关于tolua的使用
一、首先在引擎的跟目录下找到cocos2d-x自带的工具tolua++
二、使用tolua++生成自定义类的声明
打开tool文件夹中的readme文件如下:
- 1. Generating the lua<-->C bindings with tolua++
- tolua++.exe -tCocos2d -o LuaCocos2d.cpp Cocos2d.pkg
我们为了方便可以制作一个批处理文件、放在tolua.exe同目录下、每次点击就可产生自定义类的声明、如下
- -----------------------------------------createCpp.bat---------------------------
- @echo on
- E:\gkh_netdisk\tools\tolua++\tolua++.exe -o testCtoLua.cpp testCtoLua.pkg
- @pause
- ---------------------------------------------------------------------------------
然后开始编写testCtoLua.pkg 要遵循以下的规则
- 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类做个测试
- ----------- 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);
只要把cpp中的对应的代码复制到引擎目录下cocos2d_support文件夹中Luacocos2d.cpp中就搞定了 然后重新编译项目、就可以在lua中使用这个接口了、
关于tolua的使用的更多相关文章
- Unity3d:UI面板管理整合进ToLua
本文基于 https://github.com/chiuan/TTUIFramework https://github.com/jarjin/LuaFramework_UGUI 进行的二次开发,Tha ...
- cocos2dx 3.x tolua 分析
cocos2dx 3.x 版本已经出到3.10了,终于决定要进行引擎版本升级,c++配合lua进行游戏开发,从3.x版本开始cocos使用了新的tolua方式,由于不懂python,折腾tolua搞的 ...
- tolua++实现分析
项目正在使用cocos2dx的lua绑定,绑定的方式是tolua++.对大规模使用lua代码信心不是很足,花了一些时间阅读tolua++的代码,希望对绑定实现的了解,有助于项目对lua代码的把控.从阅 ...
- U3D 扩展方法 & Dotween & tolua
using UnityEngine; using System.Collections; using LuaInterface;//tolua 空间引用 using DG.Tweening;//DOT ...
- tolua.cast的实用方法
local name = (tolua.cast(sender, "ccui.Button")):getTitleText()
- cocos2dx 2.x版本:简化提炼tolua++绑定自定义类到lua中使用
cocos2dx的3.x版本已经提供了更好地绑定方式,网上有很多相关的教程,这里给一个链接:http://www.cocoachina.com/bbs/read.php?tid=196416. 由于目 ...
- 学习tolua#·20多个例子
初始项目搭建 clone官方库 新建unity工程 依次把官方库里的Assets和Unity5.x/Assets拷贝到项目Assets里 打开unity工程, 开始逐个学习例子,例子目录: 1. he ...
- 使用tolua++编译pkg,从而创建自定义类让Lua脚本使用
步骤一:首先自定义类(这里Himi自定义类名 “MySprite”) MySprite.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // // ...
- tolua 有些功能可以用(经过测试)
tolua 提供几个 C++ 与 Lua 进行数据交换的工具函数. ~~ tolua.type 返回一个 C++ 对象的类型描写叙述字符串. local node = display.newNode( ...
- cocos2dx使用tolua关于字符串处理的一个问题
正在使用cocos2dx的tolua binding在此过程中发现的一个问题.假设一回或输入是std::string当我们不同意包括二进制数据,和std::string我同意,这样一来就导致了不正确的 ...
随机推荐
- Why does eclipse automatically add appcompat v7 library support whenever I create a new project?
Best ways to solve these: Firstly in project,Right click->properties->Android.There you can se ...
- 机器学习算法实践:Platt SMO 和遗传算法优化 SVM
机器学习算法实践:Platt SMO 和遗传算法优化 SVM 之前实现了简单的SMO算法来优化SVM的对偶问题,其中在选取α的时候使用的是两重循环通过完全随机的方式选取,具体的实现参考<机器学习 ...
- fedora 19 gnome 3.8 关闭笔记本盖子的动作
gnome-tweak-tool里没有了相关选项,但是又想让关闭盖子不挂起,后来看看才知道gnome3.8不再提供这功能,而是交给systemd来处理,所以估计用dconf-edit在gnome的po ...
- LINUX 笔记-crontab命令
用户所建立的crontab文件中,每一行都代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,格式如下: minute hour da ...
- [Java Web 第一个项目]客户关系处理系统(CRM)项目总结
一.table的应用: 1.表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔).cellpadd ...
- ALV添加文字输入框
一.业务场景 在合同打印中,需要临时添加其他约定事项,在打印程序的ALV中添加其他事项字段,点击之后弹出文字输入窗口,点击确定,文字内容存表,并在ALV中展示,点击打印后,文字内容加载到smartfo ...
- 记一次mysql千万订单汇总查询优化
公司订单系统每日订单量庞大,有很多表数据超千万.公司SQL优化这块做的很不好,可以说是没有做,所以导致查询很慢. 正题 节选某个功能中的一句SQL EXPLAIN 查看执行计划 EXPLAIN + S ...
- Python多进程应用
在我之前的一篇博文中详细介绍了Python多线程的应用: 进程,线程,GIL,Python多线程,生产者消费者模型都是什么鬼 但是由于GIL的存在,使得python多线程没有充分利用CPU的多核,为 ...
- pandas.DataFrame学习系列1——定义及属性
定义: DataFrame是二维的.大小可变的.成分混合的.具有标签化坐标轴(行和列)的表数据结构.基于行和列标签进行计算.可以被看作是为序列对象(Series)提供的类似字典的一个容器,是panda ...
- iOS之创建一个常驻线程
// 当创建一个线程,并且希望它一直存在时,但往往我们创建的线程都是执行完成之后也就停止了,不能再次利用,那么如何创建一个线程可以让他可以再次工作呢,这个时候就需要使用到RunLoop了.下面的是我写 ...