binding Custom class to lua ,when to call register_all_xxxxxxx()

binding Custom class to lua ,when to call register_all_xxxxxxx()
0.0 0


hi guys,
I have a custom c++ class and want to bind to lua,so I write the ini file, and the binding is generate successful,I used args -n mynamespace. so in the auto-generated cpp file,has a function register_all_mynamespace。I know I should call this function to make the bind effect in lua eviroment. but what’s the time?
I tried call this befor I set the ScriptEngine.

        lua_State *state = engine->getLuaStack()->getLuaState();

but execute failed with a bad_access when called lua_rawget(L,–2); in tolua_module func

So I traced the CCLuaStack and CCLuaEngine File,found cocos2dx’s auto binding was called after luaL_register(*state, “G", global_functions); so in the tolua_module func, lua_rawget will pushG[‘namespace’] onto the stack and check if it’s exist。
but when CCLuaEngine create,it calls executeString to load deprecated lua files.and change the lua stack。and when I register my binding .the stack is empty.
so I have to write
lua_State *state = LuaEngine::getInstance()->getLuaStack()->getLuaState();
and I think the framework should offer some function for custom bindings register.
how about to add a function in LuaStack like
inline void addLuaBindings(lua_CFunction func){
int top = lua_gettop(_state);
lua_getglobal(*state, "*G”);


Yep, I got this problem too.


Please post lua binding related issues into this sub forum in future.


Sorry, my mistake. It is the correct forum.


I think encapsulate a function to support custom bindings register is a good idea.