您的位置:首页 > 移动开发 > Cocos引擎

quick-cocos2d-x 创建自定义lua绑定c++类

2014-08-26 11:54 411 查看
内容主要参考 “在quick-cocos2d-x中添加自定义的类给lua使用” ( http://www.codeo4.cn/archives/746)
1. quick-coco2d-x 使用 tolua++ 来简化lua绑定c++类操作,mac下用到了 /usr/local/bin/tolua++ ,可以把bin/mac下的可执行程序复制过去,省得编译安装了。

2. 在 lib/cocos2dx_extra/extra 下创建目录并实现c++类,例如 mylib/foo.h mylib/foo.cpp

3. 修改 /lib/cocos2dx_extra/extra/luabinding/cocos2dx_extra_luabinding.tolua ,在开头加入

$#include "mylib/foo.h"

在文件尾部加入类定义,遵循以下原则:

1) enum keeps the same

2) remove CC_DLL for the class defines, pay attention to multi inherites

3) remove inline keyword for declaration and implementation

4) remove public protect and private

5) remove the decalration of class member variable

6) keep static keyword

7) remove memeber functions that declared as private or protected

4. 执行 lib/cocos2dx_extra/extra/luabinding/build.sh 生成类的lua绑定类,就是 /lib/cocos2dx_extra/extra/luabinding/cocos2dx_extra_luabinding.cpp,正常应该在文件里看到foo类

5. 如果是Android项目,修改 lib/cocos2dx_extra/proj.android/Android.mk

在 LOCAL_SRC_FILES 里加入源文件 ( ../extra/mylib/foo.cpp \)

如果用到第三方库,加入到 LOCAL_WHOLE_STATIC_LIBRARIES 和 $(call import-module,libxxx)

6. 编译项目
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: