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

内容主要参考 “在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. 编译项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值