以下实现方式基于Quick-cocos2d-x 2.1.4,使用cocos2d-x版本的同学请自行修正。
C++数据类定义
class SHAccountData : public CCObject { CC_SYNTHESIZE(long long, _gameId, GameId); CC_SYNTHESIZE(int, _sessionId, SessionId); CC_SYNTHESIZE(int, _serverId, ServerId); public: SHAccountData() : _gameId(0L), _sessionId(0), _serverId(0) {} ~SHAccountData() {} };
以往,不知道 tolua_property 之前,我采用的笨办法来编写tolua描述文件
class SHAccountData : public CCObject { public: long long getGameId(); int getSessionId(); int getServerId(); void setGameId(long long var); void setSessionId(int var); void setServerId(int var); SHAccountData(); ~SHAccountData(); };
这才3个属性,从3行代码编程6行,工作量还OK。20个,100个属性呢?
认认真真地抽时间阅读了一遍《tolua++ reference manual》后,终于找到一条捷径。
新的tolua描述文件
class SHAccountData : public CCObject { public: tolua_property__java long long gameId; tolua_property__java int sessionId; tolua_property__java int serverId; SHAccountData(); ~SHAccountData(); };
这里用到了自定义的 Property types。
另外,注意 tolua_property__java,"property"和"java"之间是两个下划线,不是一个。
这时候,想要顺利编译的时候,需要修改 ${projectName}/luabinding/basic.lua (PS:每个人的目录结构不一样,请自行修正)。
-- usage: (use instead of ant) -- tolua++ "-L" "basic.lua" "-o" "../../scripting/lua/cocos2dx_support/LuaCocos2d.cpp" "Cocos2d.pkg" _is_functions = _is_functions or {} _to_functions = _to_functions or {} _push_functions = _push_functions or {} function get_property_methods_hook(ptype, name) name = name:gsub("^%l", string.upper) if ptype == "java" then return "get"..name, "set"..name end if ptype == "java_bool" then return "is"..name, "set"..name end -- etc end local CCObjectTypes = { "UnitManager", "GoObject", "GoObjectList", "GoMap", } -- register CCObject types for i = 1, #CCObjectTypes do _push_functions[CCObjectTypes[i]] = "toluafix_pushusertype_ccobject" end …………
get_property_methods_hook部分,是需要大家补充的。
由于我是从Java语言转到C++上的,所以习惯了JavaBean的格式。如果需要转为别的属性命名规范,请自行修改。
相关推荐
Code to synthesize Arithmetic Logic Unit
相信每个初学者对@property和@synthesize都感到非常的陌生,在此给大家分享下我的自己的理解,有不当之处,还望多多指教。详细说明文章在下面连接http://blog.csdn.net/comeontom/article/details/7455459
针对iOS开发中属性 property 和 synthesize 进行了详细介绍
在MyOjbect.h ,单行添加为: # import " RWSingletonMacro.h "@interface MyObject : NSObjectRW_DECLARE_SINGLETON_FOR_CLASS_WITH_ACCESSOR (MyObject, sharedObject)@end 在MyObject.m : # import " MyObject....
资源分类:Python库 所属语言:Python 资源全名:synthesize-0.0.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
一种蟾蜍内酰胺衍生物简便合成方法及其抑制前列腺癌细胞活性,袁小风,田海妍,将蟾蜍灵与乙酸铵在DMF溶液中反应,得到bufadienolactam(1)和secobufalinamide(2)。这两个化合物的结构通过波谱学方法进行鉴定,...
3D-Synthesize3DviaDepthOrSil.zip,[CVPR 2017]通过建模多视图深度图或轮廓生成和重建三维形状,3D建模使用专门的软件来创建物理对象的数字模型。它是3D计算机图形的一个方面,用于视频游戏,3D打印和VR,以及其他...
Synthesize & Power Analyze
@property (nonatomic, retain) NSMutableString *currentResult; @property (nonatomic, retain) NSMutableDictionary *map; @property (nonatomic, retain) NSMutableArray *list; -(NSMutableDictionary *)...
Synthesize Synthesize is an android library which can create layout images in background threads, services, etc without inflating them in activity or fragments. Synthesize Documentation
that can be used to synthesize sandy terrain with vegetation covers. For realizing a real-time simulation process, we implemented the method on the programming graphics processing unit (GPU). We tried...
This program will also synthesize FIR filters with the Parks McClellan algorithm. If you are familiar with this algorithm, you know that it requires the filter to be described in bands. This program's...
以下是如何使用synthesize_texture函数的示例(来自synthesize_texture_test.m ): input_image = im2double(imread( ' 161.png ' )); output_image = synthesize_texture(input_image, 256 , 256 , 9 ); imwrite...
Synthesize3DviaDepthOrSil:[CVPR 2017]通过对多视图深度图或轮廓建模来生成和重建3D形状
Field test 5, released 16-dec-2001 ?1997-2001 Angus Johnson & Anders Melander http://www.melander.dk/delphi/dragdrop/ ------------------------------------------- Table of Contents: ------------------...
Hands-on labs throughout the book challenge you to practice and synthesize your skills as you dissect real malware samples, and pages of detailed dissections offer an over-the-shoulder look at how the...
The Xilinx® Vivado® High-Level Synthesis (HLS) tool transforms a C specification into a register transfer level (RTL) implementation that you can synthesize into a Xilinx field programmable gate ...
DT系列伺服马达产品手册pdf,DT系列伺服马达产品手册
quickly produces high-quality textures with little user intervention has remained elusive. The algorithm presented in this paper brings us closer to that goal by generating high-quality textures on ...