From: John L. <jla...@gm...> - 2006-01-11 15:09:18
|
There is a problem with coroutines currently. The issue is that when lua creates a coroutine a new lua_State is created by lua and wxLua correctly associates the new lua_State with the original wxLuaState so that it can get the ref data (where the bindings and C++ variables are stored). This is all fine, however when you try to run some lua code in a coroutine, lua calls the function "int LUACALL wxLua_lua_getTableFunc(lua_State *L)" to find out about a bound function. It needs to look up the wxLuaState (for the ref data) and though the proper ref data IS found, subsequent calls to functions like wxLuaState::ttag use the lua_State of the wxLuaState and not the coroutine one and so it fails. Solutions: a) Remove all the ttag and other functions from the wxLuaState and make them standalone 'C' functions that only take a lua_State* L. This would require that the wxLuaState (and it's ref data) would have to be incessantly looked up, this is how it was previously. b) Add a parameter lua_State* L =3D NULL to the end of functions like ttag (and EVERY function that would be called by a 'C' function called by lua) that would either use the given lua_State passed in if !NULL or use the lua_State of the wxLuaState. This is easy to do, but may be a little confusing. c) Make the ref data, the C++ data for the lua_State itself ref data. wxLuaState : wxObject -> wxLuaStateRefData (the wxObjectRefData) members are lua_State* and wxLuaStateData wxLuaStateData : wxObject -> wxLuaStateDataRefData (the wxObjectRefData) members are the rest of what is currently in the wxLuaStateRefData So that if you do "wxLuaState wxlState(lua_State* L)" it finds the wxLuaStateRefData for the given lua_State, but since the wxLuaStateData is also ref counted two or more wxLuaStateRefData can share the same data, which is what coroutines require. d) Make wxLuaState NOT ref counted and keep a list of pointers to them for looking them up from the lua_State*. As a member it would have a ref counted wxLuaStateData class, similar to the one outlined above. e) ? I'd appreciate any thoughts on this. In my effort to make the wxLuaState more robust, I missed this important detail. Regards, John Labenski |