cocos2d-x从c++文件生成lua绑定文件及lua脚本文件

需要参考自己的工程目录\frameworks\cocos2d-x\tools\tolua\目录下的README.mdown文件下载安装相关的工具;

(其中python需要安装32位的 --- 即使你是64位的系统; 其他几个工具也要装32位的)

本次测试使用的NDK是r10d;


1、准备文件:

a.h a.cpp

a.h => 

#ifndef __A_H__
#define __A_H__

#include "cocos2d.h"

class A : public cocos2d::Node
{
public:
CREATE_FUNC(A);

virtual bool init();
void testFunc();
};

#endif

a.cpp =>

#include "a.h"
using namespace cocos2d;

bool A::init()
{
if (!Node::init())
{
return false;
}

return true;
}

void A::testFunc()
{

}


2、修改配置文件:

进入=》 自己的工程目录\frameworks\cocos2d-x\tools\tolua\

复制cocos2dx.ini、genbindings.py,改名为my.ini,genbindings_my.py,然后修改这两个文件如下:

(1)修改genbindings_my.py:

    try:

        tolua_root = '%s/tools/tolua' % project_root
        output_dir = '%s/../runtime-src/Classes/test/luabinding' % project_root

        cmd_args = {'my.ini' : ('my', 'lua_my_auto'), \

}

* output_dir 是生成的绑定文件和lua脚本的存放路径

* cmd_args 是(待研究),总之,cmd_args中my.ini 和 my,这两个地方名字必须一致,lua_my_auto名字随便,这个是生成的绑定文件的名字;

(2)修改my.ini:

[my]  ==》 这个中括号中的内容和你文件名相同
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates

prefix = my  ==》函数名的前缀,prefix同样可以和文件名相同

# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace

target_namespace = me  ==》模块名


android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include
android_flags = -D_SIZE_T_DEFINED_


clang_headers = -I%(clangllvmdir)s/lib/clang/%(clang_version)s/include
clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__


cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/external
cocos_flags = -DANDROID


cxxgenerator_headers =


# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s


# what headers to parse
headers = %(cocosdir)s/../runtime-src/Classes/test/a.h  ==》要转换的头文件路径,转换成绑定文件只需要类的头文件,不需要cpp文件,因为只需要类的声明


# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".

classes = A ==》需要转换的类,支持正则表达式

你可能感兴趣的:(C++,cocos2dx,lua,lua绑定)