cocos2d_x+lua【9】 ------tolua++使用(将2d_x自定义类导入lua)
来源:互联网 发布:直销管理平台系统源码 编辑:程序博客网 时间:2024/05/02 05:03
oDustGgg个人原创、欢迎转载、转载请注明出处、
http://blog.csdn.net/odustggg/article/details/8195137
一、首先在引擎的跟目录下找到cocos2d-x自带的工具tolua++
二、使用tolua++生成自定义类的声明
打开tool文件夹中的readme文件如下:- 1. Generating the lua<-->C bindings with tolua++
- tolua++.exe -tCocos2d -o LuaCocos2d.cpp Cocos2d.pkg
- -----------------------------------------createCpp.bat---------------------------
- @echo on
- E:\gkh_netdisk\tools\tolua++\tolua++.exe -o testCtoLua.cpp testCtoLua.pkg
- @pause
- ---------------------------------------------------------------------------------
- 2.Writing .pkg files 编写pkg文件
- 1)enum keeps the same 保持枚举类型不变
- 2)remove CC_DLL for the class defines, pay attention to multi inherites 删除CC_DLL的类定义、改为多继承
- 3)remove inline keyword for declaration and implementation 删掉声明的inline关键词
- 4)remove public protect and private 删除访问限定
- 5)remove the decalration of class member variable 删除类的成员变量
- 6)keep static keyword 保留statiic关键词
- 7)remove memeber functions that declared as private or protected 成员函数声明为私人或受保护的都删掉
- ----------- CCDirector.pkg-----------
- typedef enum {
- /// Device oriented vertically, home button on the bottom
- kCCDeviceOrientationPortrait = 0, // UIDeviceOrientationPortrait,
- /// Device oriented vertically, home button on the top
- kCCDeviceOrientationPortraitUpsideDown = 1, // UIDeviceOrientationPortraitUpsideDown,
- /// Device oriented horizontally, home button on the right
- kCCDeviceOrientationLandscapeLeft = 2, // UIDeviceOrientationLandscapeLeft,
- /// Device oriented horizontally, home button on the left
- kCCDeviceOrientationLandscapeRight = 3, // UIDeviceOrientationLandscapeRight,
- } ccDeviceOrientation;
- class CCDirector : public CCObject
- {
- CCScene* getRunningScene(void);
- double getAnimationInterval(void);
- bool isDisplayFPS(void);
- void setDisplayFPS(bool bDisplayFPS);
- bool isRetinaDisplay();
- bool isPaused(void);
- unsigned int getFrames(void);
- CCSize getWinSize(void);
- CCSize getWinSizeInPixels(void);
- CCSize getDisplaySizeInPixels(void);
- CCPoint convertToGL(CCPoint obPoint);
- CCPoint convertToUI(CCPoint obPoint);
- void runWithScene(CCScene *pScene);
- void pushScene(CCScene *pScene);
- void popScene(void);
- void replaceScene(CCScene *pScene);
- CGFloat getContentScaleFactor(void);
- int getDeviceOrientation();
- static CCDirector* sharedDirector(void);
- };
然后将编写好的*.pkg文件复制到tolua++文件目录下、双击前文的批处理文件、不出意外就能生成相对应的Cpp文件了
CCDirector.cpp中的关键代码是这些:
- tolua_beginmodule(tolua_S,"CCDirector");
- tolua_function(tolua_S,"getRunningScene",tolua_CCDirector_CCDirector_getRunningScene00);
- tolua_function(tolua_S,"getAnimationInterval",tolua_CCDirector_CCDirector_getAnimationInterval00);
- tolua_function(tolua_S,"isDisplayFPS",tolua_CCDirector_CCDirector_isDisplayFPS00);
- tolua_function(tolua_S,"setDisplayFPS",tolua_CCDirector_CCDirector_setDisplayFPS00);
- tolua_function(tolua_S,"isRetinaDisplay",tolua_CCDirector_CCDirector_isRetinaDisplay00);
- tolua_function(tolua_S,"isPaused",tolua_CCDirector_CCDirector_isPaused00);
- tolua_function(tolua_S,"getFrames",tolua_CCDirector_CCDirector_getFrames00);
- tolua_function(tolua_S,"getWinSize",tolua_CCDirector_CCDirector_getWinSize00);
- tolua_function(tolua_S,"getWinSizeInPixels",tolua_CCDirector_CCDirector_getWinSizeInPixels00);
- tolua_function(tolua_S,"getDisplaySizeInPixels",tolua_CCDirector_CCDirector_getDisplaySizeInPixels00);
- tolua_function(tolua_S,"convertToGL",tolua_CCDirector_CCDirector_convertToGL00);
- tolua_function(tolua_S,"convertToUI",tolua_CCDirector_CCDirector_convertToUI00);
- tolua_function(tolua_S,"runWithScene",tolua_CCDirector_CCDirector_runWithScene00);
- tolua_function(tolua_S,"pushScene",tolua_CCDirector_CCDirector_pushScene00);
- tolua_function(tolua_S,"popScene",tolua_CCDirector_CCDirector_popScene00);
- tolua_function(tolua_S,"replaceScene",tolua_CCDirector_CCDirector_replaceScene00);
- tolua_function(tolua_S,"getContentScaleFactor",tolua_CCDirector_CCDirector_getContentScaleFactor00);
- tolua_function(tolua_S,"getDeviceOrientation",tolua_CCDirector_CCDirector_getDeviceOrientation00);
- tolua_function(tolua_S,"sharedDirector",tolua_CCDirector_CCDirector_sharedDirector00);
- cocos2d_x+lua【9】 ------tolua++使用(将2d_x自定义类导入lua)
- cocos2d_x+lua【9】 ------tolua++使用(将2d_x自定义类导入lua)
- tolua++使用(将2d_x自定义类导入lua)
- ——tolua++使用(将2d_x自定义类_CursorTextField_导入lua)
- cocos2d-x tolua++使用(C++自定义类导入lua)
- tolua++快速将我们自定义的c2dx类嵌入,供 lua脚本使用
- cocos2dx lua中使用自定义类以及tolua++的使用
- cocos2dx lua中使用自定义类以及tolua++的使用
- 在Lua中使用自定义类——tolua++工具使用(上集)
- 在Lua中使用自定义类——tolua++工具使用(下集)
- 在Lua中使用自定义类——tolua++工具使用(上集)For Windows
- 在Lua中使用自定义类——tolua++工具使用(下集)
- COCOS2DX-LUA 脚本开发 使用tolua++编译pkg,从而创建自定义类让Lua脚本使用
- cocos2d_x+lua【2】 ——TexturePacker纹理打包器使用
- 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】
- 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】
- 【木头Cocos2d-x 007】在Lua中使用自定义类——tolua++工具使用(上集)
- 【木头Cocos2d-x 008】在Lua中使用自定义类——tolua++工具使用(下集)
- windows xp下如何安装memcached
- C#当中利用Attribute实现简易AOP
- php学习记录 ajax 状态码
- ssi 引入文件找不到时,源码中的体现
- eclipse 使用server-Runtime Environment管理server
- cocos2d_x+lua【9】 ------tolua++使用(将2d_x自定义类导入lua)
- [iis7]请求筛选模块被配置为拒绝包含双重转义序列的请求。HTTP 错误 404.11 - Not Found
- Oracle中分区表的使用
- spring中自定义属性编辑器CustomEditorConfigurer
- Linux内核编译过程详解
- android 的 AsyncTask 详解
- Shape Drawable样式
- 状态模式(State Pattern)
- delphi ocx 接口函数问题