binding create() functions

binding create() functions
0.0 0


cocos2dx object, CCNode, CCLayer, etc, when binding their create() functions with tolua**, codes in LuaCocos2d.cpp look like this:
CCNode* tolua_ret = CCNode::create;
int nID = ? tolua_ret~~>m_uID :~~1;
int* pLuaID = ? &tolua_ret->m_nLuaID : NULL;
i know it’s for to prevent userdata in lua to be gc, but my question is:
can tolua** generate those codes automatically or we must munually modify it ?
if it’s automatically generated, how?



In /tools/tolua*+ there are the .pkg files that you can change to expose more of the engine to lua script. So if there’s a create -method you’re missing, you can just add it to the right .pkg file.
Once you are done editing .pkg files, run build.bat or in the same directory. You probably need to unpack tolua*+.exe first from one of the .rar files, again in the same directory. Once you have successfully ran the build script, you need to rebuild your project since the LuaCocos2d.cpp file will have been changed.

I’m not sure how to do this for new classes you create in your own project, though.


it easy to do that,when export interface ,tolua*+ calls empty functions at specific points of its execution. This functions can be redefined on a separate lua file and be used to control the way tolua*+ behaves. please see the document**.html#customizing
you can modify file at “tools\tolua**.lua” at line 289 (my version is 2.12):

@ replace([[toluafix_pushusertype_ccobject(tolua_S,(void*)tolua_ret]],
[[int nID = (tolua_ret) ? (int)tolua_ret~~>m_uID :~~1;
int* pLuaID = (tolua_ret) ? &tolua_ret->m_nLuaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret]])
those line will repace the origin tolua++ output to what you want, so it it’s automatically. not need to modify every time .