Quick-Cocos2d-x 创建自定义Lua绑定C++类

来源:互联网 发布:网络用语nl是什么意思 编辑:程序博客网 时间:2024/05/16 20:30

内容主要参考 “在Quick-Cocos2d-x中添加自定义的类给lua使用” :

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)

来源网址:http://blog.csdn.net/aryang/article/details/9611883

0 0