目前项目,使用了Lua脚本,至于使用Lua的好处不再赘述了。于是对Tolua做了一些小小的学习,总结一下吧。

主要说一下如何在Lua中调用C++方法。

Lua调用C++的桥梁,是tolua。tolua是什么,http://blog.csdn.net/killwd/article/details/1423923 这篇文章介绍的很详细。

我们需要手动做的,其实便是编写中间类,这个类被tolua直接使用,最终的目的是实现lua中对象方法和C++中对象方法的对应。

LuaCocos2d.cpp 完成了所有基本的cocos对象方法的转换,我们把它称之为一个桥梁。LuaCocos2d.cpp 是在CCLuaStack 中的init函数中调用的。

  1. tolua_Cocos2d_open(m_state);

1.CCLuaStack 中调用中间桥梁(比如LuaCocos2d)

2.桥梁里面(比如LuaCocos2d)实现各种方法的转换

这样,整个的重点就是桥梁的生成了。

看一下LuaCocos2d ,最重要的方法我认为是tolua_reg_types。

  1. /* function to register type */
  2. static void tolua_reg_types (lua_State* tolua_S)
  3. {
  4. tolua_usertype(tolua_S,"CCTransitionProgressOutIn");
  5. tolua_usertype(tolua_S,"CCControlSaturationBrightnessPicker");
  6. tolua_usertype(tolua_S,"CCShaky3D");
  7. tolua_usertype(tolua_S,"CCTransitionTurnOffTiles");
  8. tolua_usertype(tolua_S,"CCTransitionShrinkGrow");
  9. tolua_usertype(tolua_S,"CCFadeOutBLTiles");
  10. tolua_usertype(tolua_S,"CCProgressFromTo");
  11. tolua_usertype(tolua_S,"CCActionCamera");
  12. tolua_usertype(tolua_S,"CCFlipY3D");
  13. tolua_usertype(tolua_S,"CCLinkPosition");
  14. tolua_usertype(tolua_S,"CCEaseExponentialIn");
  15. tolua_usertype(tolua_S,"CCApplication");
  16. tolua_usertype(tolua_S,"CCControlHuePicker");
  17. tolua_usertype(tolua_S,"CCScaleTo");
  18. tolua_usertype(tolua_S,"CCTransitionFlipAngular");
  19. tolua_usertype(tolua_S,"CCEaseElasticOut");
  20. tolua_usertype(tolua_S,"CCAccelDeccelAmplitude");
  21. tolua_usertype(tolua_S,"CCDisplayData");
  22. tolua_usertype(tolua_S,"CCParticleRain");
  23. tolua_usertype(tolua_S,"CCTransitionSlideInB");
  24. tolua_usertype(tolua_S,"CCKeypadDispatcher");
  25. tolua_usertype(tolua_S,"CCDelayTime");
  26. tolua_usertype(tolua_S,"CCOrbitCamera");
  27. tolua_usertype(tolua_S,"CCLabelTTF");
  28. tolua_usertype(tolua_S,"CCScale9Sprite");
  29. tolua_usertype(tolua_S,"CCMoveTo");
  30. tolua_usertype(tolua_S,"CCTransitionSplitRows");
  31. tolua_usertype(tolua_S,"CCFollow");
  32. tolua_usertype(tolua_S,"CCMovementData");
  33. tolua_usertype(tolua_S,"CCBlink");
  34. tolua_usertype(tolua_S,"CCTexture2D");
  35. tolua_usertype(tolua_S,"CCTouch");
  36. tolua_usertype(tolua_S,"CCParticleSystemQuad");
  37. tolua_usertype(tolua_S,"CCTransitionMoveInB");
  38. tolua_usertype(tolua_S,"CCToggleVisibility");
  39. tolua_usertype(tolua_S,"cc_timeval");
  40. tolua_usertype(tolua_S,"CCTMXTilesetInfo");
  41. tolua_usertype(tolua_S,"CCParticleSun");
  42. tolua_usertype(tolua_S,"CCScene");
  43. tolua_usertype(tolua_S,"CCArmatureDataManager");
  44. tolua_usertype(tolua_S,"CCFadeIn");
  45. tolua_usertype(tolua_S,"CCTransitionFadeDown");
  46. tolua_usertype(tolua_S,"CCWavesTiles3D");
  47. tolua_usertype(tolua_S,"CCFadeOutDownTiles");
  48. tolua_usertype(tolua_S,"CCComponentContainer");
  49. tolua_usertype(tolua_S,"CCTMXTiledMap");
  50. tolua_usertype(tolua_S,"CCCardinalSplineBy");
  51. tolua_usertype(tolua_S,"CCTransitionZoomFlipAngular");
  52. tolua_usertype(tolua_S,"CCFlipY");
  53. tolua_usertype(tolua_S,"CCProgressTo");
  54. tolua_usertype(tolua_S,"CCReuseGrid");
  55. tolua_usertype(tolua_S,"CCShow");
  56. tolua_usertype(tolua_S,"CCEaseRateAction");
  57. tolua_usertype(tolua_S,"CCEaseBackIn");
  58. tolua_usertype(tolua_S,"CCTransitionScene");
  59. tolua_usertype(tolua_S,"CCGridAction");
  60. tolua_usertype(tolua_S,"CCFiniteTimeAction");
  61. tolua_usertype(tolua_S,"CCSpriteFrameCache");
  62. tolua_usertype(tolua_S,"CCMotionStreak");
  63. tolua_usertype(tolua_S,"CCAnimate");
  64. tolua_usertype(tolua_S,"CCTiledGrid3DAction");
  65. tolua_usertype(tolua_S,"CCPointArray");
  66. tolua_usertype(tolua_S,"CCTransitionProgressHorizontal");
  67. tolua_usertype(tolua_S,"CCRectShape");
  68. tolua_usertype(tolua_S,"ccColor3B");
  69. tolua_usertype(tolua_S,"CCTextureCache");
  70. tolua_usertype(tolua_S,"CCDevice");
  71. tolua_usertype(tolua_S,"CCFadeOutTRTiles");
  72. tolua_usertype(tolua_S,"CCMenuItemSprite");
  73. tolua_usertype(tolua_S,"CCEaseExponentialInOut");
  74. tolua_usertype(tolua_S,"CCFadeOutUpTiles");
  75. tolua_usertype(tolua_S,"CCWaves3D");
  76. tolua_usertype(tolua_S,"ccBlendFunc");
  77. tolua_usertype(tolua_S,"CCImage");
  78. tolua_usertype(tolua_S,"CCLens3D");
  79. tolua_usertype(tolua_S,"CCTintBy");
  80. tolua_usertype(tolua_S,"CCBool");
  81. tolua_usertype(tolua_S,"CCPoint");
  82. tolua_usertype(tolua_S,"CCParticleMeteor");
  83. tolua_usertype(tolua_S,"CCEaseElasticIn");
  84. tolua_usertype(tolua_S,"CCEaseSineIn");
  85. tolua_usertype(tolua_S,"CCCardinalSplineTo");
  86. tolua_usertype(tolua_S,"CCFloat");
  87. tolua_usertype(tolua_S,"CCWaves");
  88. tolua_usertype(tolua_S,"CCParticleFireworks");
  89. tolua_usertype(tolua_S,"CCEvent");
  90. tolua_usertype(tolua_S,"CCBaseData");
  91. tolua_usertype(tolua_S,"CCActionInterval");
  92. tolua_usertype(tolua_S,"CCRenderTexture");
  93. tolua_usertype(tolua_S,"CCObject");
  94. tolua_usertype(tolua_S,"CCEaseBackInOut");
  95. tolua_usertype(tolua_S,"CCAtlasNode");
  96. tolua_usertype(tolua_S,"CCEaseBackOut");
  97. tolua_usertype(tolua_S,"CCSize");
  98. tolua_usertype(tolua_S,"CCInteger");
  99. tolua_usertype(tolua_S,"CCParticleFlower");
  100. tolua_usertype(tolua_S,"CCLiquid");
  101. tolua_usertype(tolua_S,"CCEaseBounce");
  102. tolua_usertype(tolua_S,"CCSpeed");
  103. tolua_usertype(tolua_S,"CCFrameData");
  104. tolua_usertype(tolua_S,"CCTransitionMoveInL");
  105. tolua_usertype(tolua_S,"CCSpriteFrame");
  106. tolua_usertype(tolua_S,"CCJumpBy");
  107. tolua_usertype(tolua_S,"CCTransitionFadeTR");
  108. tolua_usertype(tolua_S,"CCControlUtils");
  109. tolua_usertype(tolua_S,"CCGridBase");
  110. tolua_usertype(tolua_S,"RGBA");
  111. tolua_usertype(tolua_S,"CCParticleDisplayData");
  112. tolua_usertype(tolua_S,"SimpleAudioEngine");
  113. tolua_usertype(tolua_S,"CCNotificationCenter");
  114. tolua_usertype(tolua_S,"CCPointShape");
  115. tolua_usertype(tolua_S,"CCSpriteBatchNode");
  116. tolua_usertype(tolua_S,"CCEaseSineInOut");
  117. tolua_usertype(tolua_S,"ccFontShadow");
  118. tolua_usertype(tolua_S,"CCTwirl");
  119. tolua_usertype(tolua_S,"CCCircleShape");
  120. tolua_usertype(tolua_S,"CCDrawNode");
  121. tolua_usertype(tolua_S,"CCControlColourPicker");
  122. tolua_usertype(tolua_S,"CCMenuItemLabel");
  123. tolua_usertype(tolua_S,"CCDouble");
  124. tolua_usertype(tolua_S,"CCTargetedAction");
  125. tolua_usertype(tolua_S,"CCGrid3DAction");
  126. tolua_usertype(tolua_S,"CCString");
  127. tolua_usertype(tolua_S,"CCRemoveSelf");
  128. tolua_usertype(tolua_S,"CCAnimationData");
  129. tolua_usertype(tolua_S,"CCTransitionMoveInR");
  130. tolua_usertype(tolua_S,"CCTransitionFade");
  131. tolua_usertype(tolua_S,"CCSkewBy");
  132. tolua_usertype(tolua_S,"CCFlipX");
  133. tolua_usertype(tolua_S,"CCActionManager");
  134. tolua_usertype(tolua_S,"CCTransitionSlideInT");
  135. tolua_usertype(tolua_S,"CCCatmullRomTo");
  136. tolua_usertype(tolua_S,"CCPolygonShape");
  137. tolua_usertype(tolua_S,"CCTransitionSceneOriented");
  138. tolua_usertype(tolua_S,"CCAnimationCache");
  139. tolua_usertype(tolua_S,"CCComponent");
  140. tolua_usertype(tolua_S,"CCTransitionSlideInR");
  141. tolua_usertype(tolua_S,"CCTransitionMoveInT");
  142. tolua_usertype(tolua_S,"CCLayerGradient");
  143. tolua_usertype(tolua_S,"CCShapeNode");
  144. tolua_usertype(tolua_S,"CCStopGrid");
  145. tolua_usertype(tolua_S,"CCTMXMapInfo");
  146. tolua_usertype(tolua_S,"CCConfiguration");
  147. tolua_usertype(tolua_S,"CCLayerColor");
  148. tolua_usertype(tolua_S,"CCMenuItemFont");
  149. tolua_usertype(tolua_S,"CCTransitionFadeUp");
  150. tolua_usertype(tolua_S,"CCTransitionProgressVertical");
  151. tolua_usertype(tolua_S,"CCAccelerometer");
  152. tolua_usertype(tolua_S,"CCProcessBase");
  153. tolua_usertype(tolua_S,"CCRect");
  154. tolua_usertype(tolua_S,"CCActionInstant");
  155. tolua_usertype(tolua_S,"CCTurnOffTiles");
  156. tolua_usertype(tolua_S,"CCParticleSnow");
  157. tolua_usertype(tolua_S,"CCMenuItemImage");
  158. tolua_usertype(tolua_S,"ccTexParams");
  159. tolua_usertype(tolua_S,"CCEaseSineOut");
  160. tolua_usertype(tolua_S,"CCCallFuncN");
  161. tolua_usertype(tolua_S,"CCTransitionPageTurn");
  162. tolua_usertype(tolua_S,"ccFontDefinition");
  163. tolua_usertype(tolua_S,"ccFontStroke");
  164. tolua_usertype(tolua_S,"CCTintTo");
  165. tolua_usertype(tolua_S,"CCTransitionCrossFade");
  166. tolua_usertype(tolua_S,"CCClippingRegionNode");
  167. tolua_usertype(tolua_S,"CCActionEase");
  168. tolua_usertype(tolua_S,"CCBone");
  169. tolua_usertype(tolua_S,"CCParallaxNode");
  170. tolua_usertype(tolua_S,"CCRotateTo");
  171. tolua_usertype(tolua_S,"CCArmature");
  172. tolua_usertype(tolua_S,"CCBatchNode");
  173. tolua_usertype(tolua_S,"CCMovementBoneData");
  174. tolua_usertype(tolua_S,"CCShakyTiles3D");
  175. tolua_usertype(tolua_S,"CCArmatureDisplayData");
  176. tolua_usertype(tolua_S,"CCNode");
  177. tolua_usertype(tolua_S,"CCArmatureData");
  178. tolua_usertype(tolua_S,"CCArmatureAnimation");
  179. tolua_usertype(tolua_S,"CCSpriteDisplayData");
  180. tolua_usertype(tolua_S,"CCBezierTo");
  181. tolua_usertype(tolua_S,"CCDeccelAmplitude");
  182. tolua_usertype(tolua_S,"CCTweenType");
  183. tolua_usertype(tolua_S,"CCBoneData");
  184. tolua_usertype(tolua_S,"CCTableView");
  185. tolua_usertype(tolua_S,"CCTableViewCell");
  186. tolua_usertype(tolua_S,"CCTransitionProgress");
  187. tolua_usertype(tolua_S,"CCEditBox");
  188. tolua_usertype(tolua_S,"HSV");
  189. tolua_usertype(tolua_S,"CCRotateBy");
  190. tolua_usertype(tolua_S,"CCControlStepper");
  191. tolua_usertype(tolua_S,"CCControlSlider");
  192. tolua_usertype(tolua_S,"CCMoveBy");
  193. tolua_usertype(tolua_S,"CCParticleGalaxy");
  194. tolua_usertype(tolua_S,"CCCamera");
  195. tolua_usertype(tolua_S,"CCSequence");
  196. tolua_usertype(tolua_S,"CCTileMapAtlas");
  197. tolua_usertype(tolua_S,"tCCParticle");
  198. tolua_usertype(tolua_S,"CCCatmullRomBy");
  199. tolua_usertype(tolua_S,"CCHide");
  200. tolua_usertype(tolua_S,"CCControlButton");
  201. tolua_usertype(tolua_S,"CCJumpTiles3D");
  202. tolua_usertype(tolua_S,"CCTransitionJumpZoom");
  203. tolua_usertype(tolua_S,"CCTMXLayer");
  204. tolua_usertype(tolua_S,"CCControl");
  205. tolua_usertype(tolua_S,"AssetsManager");
  206. tolua_usertype(tolua_S,"CCScheduler");
  207. tolua_usertype(tolua_S,"CCDirector");
  208. tolua_usertype(tolua_S,"CCMenuItemToggle");
  209. tolua_usertype(tolua_S,"CCEGLView");
  210. tolua_usertype(tolua_S,"ccBezierConfig");
  211. tolua_usertype(tolua_S,"CCFadeTo");
  212. tolua_usertype(tolua_S,"CCTouchDispatcher");
  213. tolua_usertype(tolua_S,"CCMenuItemAtlasFont");
  214. tolua_usertype(tolua_S,"SEL_MenuHandler");
  215. tolua_usertype(tolua_S,"CCEventDispatcher");
  216. tolua_usertype(tolua_S,"CCParticleSystem");
  217. tolua_usertype(tolua_S,"CCJumpTo");
  218. tolua_usertype(tolua_S,"CCMenu");
  219. tolua_usertype(tolua_S,"ccColor4F");
  220. tolua_usertype(tolua_S,"CCEaseExponentialOut");
  221. tolua_usertype(tolua_S,"CCSet");
  222. tolua_usertype(tolua_S,"CCCallFunc");
  223. tolua_usertype(tolua_S,"CCLabelAtlas");
  224. tolua_usertype(tolua_S,"CCLabelBMFont");
  225. tolua_usertype(tolua_S,"CCEaseBounceIn");
  226. tolua_usertype(tolua_S,"CCPlace");
  227. tolua_usertype(tolua_S,"CCSprite");
  228. tolua_usertype(tolua_S,"CCFileUtils");
  229. tolua_usertype(tolua_S,"CCLayer");
  230. tolua_usertype(tolua_S,"CCTransitionSplitCols");
  231. tolua_usertype(tolua_S,"CCPageTurn3D");
  232. tolua_usertype(tolua_S,"CCEaseIn");
  233. tolua_usertype(tolua_S,"CCTransitionProgressRadialCW");
  234. tolua_usertype(tolua_S,"CCEaseElastic");
  235. tolua_usertype(tolua_S,"CCTransitionProgressRadialCCW");
  236. tolua_usertype(tolua_S,"CCEaseOut");
  237. tolua_usertype(tolua_S,"CCBezierBy");
  238. tolua_usertype(tolua_S,"CCScrollView");
  239. tolua_usertype(tolua_S,"CCUserDefault");
  240. tolua_usertype(tolua_S,"CCProgressTimer");
  241. tolua_usertype(tolua_S,"CCDictionary");
  242. tolua_usertype(tolua_S,"CCParticleFire");
  243. tolua_usertype(tolua_S,"CCTransitionFlipY");
  244. tolua_usertype(tolua_S,"CCTMXLayerInfo");
  245. tolua_usertype(tolua_S,"CCTransitionFadeBL");
  246. tolua_usertype(tolua_S,"CCShuffleTiles");
  247. tolua_usertype(tolua_S,"CCTransitionSlideInL");
  248. tolua_usertype(tolua_S,"CCRipple3D");
  249. tolua_usertype(tolua_S,"CCRepeat");
  250. tolua_usertype(tolua_S,"CCClippingNode");
  251. tolua_usertype(tolua_S,"CCTransitionProgressInOut");
  252. tolua_usertype(tolua_S,"CCParticleSpiral");
  253. tolua_usertype(tolua_S,"CCTransitionZoomFlipY");
  254. tolua_usertype(tolua_S,"CCEaseBounceInOut");
  255.  
  256. tolua_usertype(tolua_S,"CCTransitionZoomFlipX");
  257. tolua_usertype(tolua_S,"CCTransitionFlipX");
  258. tolua_usertype(tolua_S,"CCSpawn");
  259. tolua_usertype(tolua_S,"CCTransitionRotoZoom");
  260. tolua_usertype(tolua_S,"CCEaseInOut");
  261. tolua_usertype(tolua_S,"CCShatteredTiles3D");
  262. tolua_usertype(tolua_S,"CCAccelAmplitude");
  263. tolua_usertype(tolua_S,"CCParticleSmoke");
  264. tolua_usertype(tolua_S,"CCTMXObjectGroup");
  265. tolua_usertype(tolua_S,"CCFadeOut");
  266. tolua_usertype(tolua_S,"CCLayerMultiplex");
  267. tolua_usertype(tolua_S,"CCControlPotentiometer");
  268. tolua_usertype(tolua_S,"CCParticleExplosion");
  269. tolua_usertype(tolua_S,"CCGLProgram");
  270. tolua_usertype(tolua_S,"CCMenuItem");
  271. tolua_usertype(tolua_S,"ccColor4B");
  272. tolua_usertype(tolua_S,"CCFlipX3D");
  273. tolua_usertype(tolua_S,"CCSplitRows");
  274. tolua_usertype(tolua_S,"CCArray");
  275. tolua_usertype(tolua_S,"CCReverseTime");
  276. tolua_usertype(tolua_S,"CCSkewTo");
  277. tolua_usertype(tolua_S,"CCParticleBatchNode");
  278. tolua_usertype(tolua_S,"CCGraySprite");
  279. tolua_usertype(tolua_S,"CCAnimation");
  280. tolua_usertype(tolua_S,"CCRepeatForever");
  281. tolua_usertype(tolua_S,"CCTime");
  282. tolua_usertype(tolua_S,"CCAction");
  283. tolua_usertype(tolua_S,"CCTextFieldTTF");
  284. tolua_usertype(tolua_S,"CCTextureAtlas");
  285. tolua_usertype(tolua_S,"CCScaleBy");
  286. tolua_usertype(tolua_S,"CCEaseElasticInOut");
  287. tolua_usertype(tolua_S,"CCSplitCols");
  288. tolua_usertype(tolua_S,"CCEaseBounceOut");
  289. tolua_usertype(tolua_S,"CCAnimationFrame");
  290. tolua_usertype(tolua_S,"CCControlSwitch");
  291. }

拿CCLabelTTF举例,你在里面搜便可以明白了。第一个参数先不用管,第二个是CCLabelTTF在调用的方法名,第三个参数便是这个文件中定义的方法,你找到一看便会明白了。

  1. #ifdef __cplusplus
  2. tolua_cclass(tolua_S,"CCLabelTTF","CCLabelTTF","CCSprite",tolua_collect_CCLabelTTF);
  3. #else
  4. tolua_cclass(tolua_S,"CCLabelTTF","CCLabelTTF","CCSprite",NULL);
  5. #endif
  6. tolua_beginmodule(tolua_S,"CCLabelTTF");
  7. tolua_function(tolua_S,"new",tolua_Cocos2d_CCLabelTTF_new00);
  8. tolua_function(tolua_S,"new_local",tolua_Cocos2d_CCLabelTTF_new00_local);
  9. tolua_function(tolua_S,".call",tolua_Cocos2d_CCLabelTTF_new00_local);
  10. tolua_function(tolua_S,"delete",tolua_Cocos2d_CCLabelTTF_delete00);
  11. tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create00);
  12. tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create01);
  13. tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create02);
  14. tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create03);
  15. tolua_function(tolua_S,"initWithString",tolua_Cocos2d_CCLabelTTF_initWithString00);
  16. tolua_function(tolua_S,"initWithString",tolua_Cocos2d_CCLabelTTF_initWithString01);
  17. tolua_function(tolua_S,"initWithString",tolua_Cocos2d_CCLabelTTF_initWithString02);
  18. tolua_function(tolua_S,"initWithStringAndTextDefinition",tolua_Cocos2d_CCLabelTTF_initWithStringAndTextDefinition00);
  19. tolua_function(tolua_S,"init",tolua_Cocos2d_CCLabelTTF_init00);
  20. tolua_function(tolua_S,"setTextDefinition",tolua_Cocos2d_CCLabelTTF_setTextDefinition00);
  21. tolua_function(tolua_S,"getTextDefinition",tolua_Cocos2d_CCLabelTTF_getTextDefinition00);
  22. tolua_function(tolua_S,"enableShadow",tolua_Cocos2d_CCLabelTTF_enableShadow00);
  23. tolua_function(tolua_S,"disableShadow",tolua_Cocos2d_CCLabelTTF_disableShadow00);
  24. tolua_function(tolua_S,"enableStroke",tolua_Cocos2d_CCLabelTTF_enableStroke00);
  25. tolua_function(tolua_S,"disableStroke",tolua_Cocos2d_CCLabelTTF_disableStroke00);
  26. tolua_function(tolua_S,"setFontFillColor",tolua_Cocos2d_CCLabelTTF_setFontFillColor00);
  27. tolua_function(tolua_S,"setString",tolua_Cocos2d_CCLabelTTF_setString00);
  28. tolua_function(tolua_S,"getString",tolua_Cocos2d_CCLabelTTF_getString00);
  29. tolua_function(tolua_S,"getHorizontalAlignment",tolua_Cocos2d_CCLabelTTF_getHorizontalAlignment00);
  30. tolua_function(tolua_S,"setHorizontalAlignment",tolua_Cocos2d_CCLabelTTF_setHorizontalAlignment00);
  31. tolua_function(tolua_S,"getVerticalAlignment",tolua_Cocos2d_CCLabelTTF_getVerticalAlignment00);
  32. tolua_function(tolua_S,"setVerticalAlignment",tolua_Cocos2d_CCLabelTTF_setVerticalAlignment00);
  33. tolua_function(tolua_S,"getDimensions",tolua_Cocos2d_CCLabelTTF_getDimensions00);
  34. tolua_function(tolua_S,"setDimensions",tolua_Cocos2d_CCLabelTTF_setDimensions00);
  35. tolua_function(tolua_S,"getFontSize",tolua_Cocos2d_CCLabelTTF_getFontSize00);
  36. tolua_function(tolua_S,"setFontSize",tolua_Cocos2d_CCLabelTTF_setFontSize00);
  37. tolua_function(tolua_S,"getFontName",tolua_Cocos2d_CCLabelTTF_getFontName00);
  38. tolua_function(tolua_S,"setFontName",tolua_Cocos2d_CCLabelTTF_setFontName00);
  39. tolua_endmodule(tolua_S);

假如我们有自己的C++方法需要在Lua中调用,也按照这两个大步骤完成即可。中间桥梁类参考LuaCocos2d.cpp即可。

Lua中调用C++方法的更多相关文章

  1. Lua中“.”调用方法与“:”调用方法的区别

    Lua中“.”调用方法与“:”调用方法的区别:                                                                             ...

  2. 【问题】Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数

    [问题]Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数. [解决]直接对变量加引号,如: <button onclick="deleteProduct('@ ...

  3. C# 构造函数中调用虚方法的问题

    请看下面代码: using System; public class A{ public A(){ M1(); } public virtual void M1(){} } public class ...

  4. 【09】绝不在构造和析构过程中调用virtual方法

    1.绝不在构造和析构过程中调用virtual方法,为啥? 原因很简单,对于前者,这种情况下,子类专有成分还没有构造,对于后者,子类专有成分已经销毁,因此调用的并不是子类重写的方法,这不是程序员所期望的 ...

  5. angularjs 动态表单, 原生事件中调用angular方法

    1. 原生事件中调用angular方法, 比如 input的onChange事件想调用angular里面定义的方法 - onChange="angular.element(this).sco ...

  6. 避免在构造函数中调用虚方法(Do not call overridable methods in constructors)

    CLR中说道,不要在构造函数中调用虚方法,原因是假如被实例化的类型重写了虚方法,就会执行派生类型对虚方法的实现.但在这个时候,尚未完成对继承层次结构中所有字段的初始化.所以,调用虚方法会导致不可预测的 ...

  7. Python 在子类中调用父类方法详解(单继承、多层继承、多重继承)

    Python 在子类中调用父类方法详解(单继承.多层继承.多重继承)   by:授客 QQ:1033553122   测试环境: win7 64位 Python版本:Python 3.3.5 代码实践 ...

  8. JS与OC交互,JS中调用OC方法(获取JSContext的方式)

    最近用到JS和OC原生方法调用的问题,查了许多资料都语焉不详,自己记录一下吧,如果有误欢迎联系我指出. JS中调用OC方法有三种方式: 1.通过获取JSContext的方式直接调用OC方法 2.通过继 ...

  9. python基础----继承与派生、组合、接口与归一化设计、抽象类、子类中调用父类方法

    一.什么是继承                                                                          继承是一种创建新的类的方式,在pyth ...

随机推荐

  1. javabean的内省技术和BeanUtils的使用

    一.关于javabean javabean是固定写法的java类 书写格式为: 1)必须有无参构造函数 2)属性必须私有, 我们称为字段 3)提供标准的getter和setter 例: name 字段 ...

  2. ajax的一些实用技巧

    1.尽量优先采用ajax获取html文件,然后再操作dom把数据填充到里面 在实际项目中,如果前端开发人员没有把页面给切分开,那么有如下两种办法可供选择:其一是,在各种点击事件中,用js去拼接并在拼接 ...

  3. iOS开发多线程编程2 - NSOperation

    1.简介 NSOperation实例封装了需要执行的操作和执行操作所需的数据,并且能够以并发或非并发的方式执行这个操作. NSOperation本身是抽象基类,因此必须使用它的子类,使用NSOpera ...

  4. git初始化之git config

    git初始化之git config     1. 下面的命令将修改/home/[username]/.gitconfig文件,也就是说下面的配置只对每一个ssh的用户可见,所以每个人都需要做.   提 ...

  5. Delphi DBGrid双击事件、单元格操作

    1.得到当前格子中的内容:DBGrid1.Fields[DBGrid1.SelectedIndex].DisplayText;把DBGrid1.SelectedIndex改为你所希望引用的字段就可以了 ...

  6. 【EF】Entity Framework Core 2.0 特性介绍和使用指南

    阅读目录 前言 获取和使用 新特性 项目升级和核心API变化 下一步计划 遗憾的地方 回到目录 前言 这是.Net Core 2.0生态生态介绍的最后一篇,EF一直是我喜欢的一个ORM框架,随着版本升 ...

  7. 【bzoj5049】[Lydsy九月月赛]导航系统 并查集+双向BFS最短路

    题目描述 给你一张 $n$ 个点 $m$ 条边的随机图,边权为1.$k$ 次询问两点间最短路,不连通则输出-1. 输入 第一行包含3个正整数n,m,k(2<=n<=100000,1< ...

  8. 【hdu3555】Bomb 数位dp

    题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...

  9. poj 1422 Air Raid (二分匹配)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6520   Accepted: 3877 Descript ...

  10. hadoop 将HDFS上多个小文件合并到SequenceFile里

    背景:hdfs上的文件最好和hdfs的块大小的N倍.如果文件太小,浪费namnode的元数据存储空间以及内存,如果文件分块不合理也会影响mapreduce中map的效率. 本例中将小文件的文件名作为k ...