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

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.
used:

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

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
<pre>
lua_State *state = LuaEngine::getInstance()->getLuaStack()->getLuaState();
lua_getglobal(state,”*G“);
register_all_lever(state);
</pre>
and I think the framework should offer some function for custom bindings register.
how about to add a function in LuaStack like
<pre>
inline void addLuaBindings(lua_CFunction func){
int top = lua_gettop(_state);
lua_getglobal(*state, "*G”);
func(_state);
lua_settop(L,top);
}

Yep, I got this problem too.

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

Sorry, my mistake. It is the correct forum.

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