From: John L. <jr...@us...> - 2010-12-03 04:39:51
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5929/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxlstate.h Log Message: Fix wxLuaObject to take a lua_State for all functions so that it works with coroutines. Send an error message in Lua is trying to install a wxEventHandler from a coroutine since a) it will only be called when the thread is suspended or dead b) we cannot track when the coroutine state is closed so we will call an invalid lua_State Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** wxlbind.h 21 Dec 2009 04:06:13 -0000 1.92 --- wxlbind.h 3 Dec 2010 04:39:43 -0000 1.93 *************** *** 35,39 **** // and is used as an end marker for the wxLuaArgType array that // represents function prototype argument types in the wxLuaBindCFunc struct ! // and it must always be 0. The Lua type LUA_TNONE starts at 1 since // Lua arrays start at 1. --- 35,39 ---- // and is used as an end marker for the wxLuaArgType array that // represents function prototype argument types in the wxLuaBindCFunc struct ! // and it must always be 0. The Lua type LUA_TNONE starts at 1 since // Lua arrays start at 1. *************** *** 105,109 **** // Note that we do not use the original since we may not be linked // to the binding library that defines them. ! // Their values are set at compile time if linked to library, // see wxbase_rules.lua and wxcore_rules.lua extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxEvent; // wxLua type for wxEvent --- 105,109 ---- // Note that we do not use the original since we may not be linked // to the binding library that defines them. ! // Their values are set at compile time if linked to library, // see wxbase_rules.lua and wxcore_rules.lua extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxEvent; // wxLua type for wxEvent *************** *** 247,251 **** wxLuaBindNumber* enums; // Class member enums or NULL if none int enums_n; // number of enums ! wxlua_delete_function delete_fn; // Function that will cast the void* pointer // to the class type and then call delete on it. --- 247,251 ---- wxLuaBindNumber* enums; // Class member enums or NULL if none int enums_n; // number of enums ! wxlua_delete_function delete_fn; // Function that will cast the void* pointer // to the class type and then call delete on it. *************** *** 288,291 **** --- 288,295 ---- // Also with a simple extension by a proxy member value it can be used // to provide pointers to the wxValidator classes. + // Note that all functions take a lua_State since we may be called from a + // coroutine with a different lua_State pointer and we want to make sure + // that we push/pull our object from the right lua_State. The registry + // where we store our object is shared by coroutine states. // ---------------------------------------------------------------------------- *************** *** 305,320 **** // in the wxlua_lreg_refs_key registy table wxLuaObject(const wxLuaState& wxlState, int stack_idx); virtual ~wxLuaObject(); // Get the value of the reference object and push it onto the stack. // (or a proxy if the object has been aliased for a wxValidator class.) // returns true if the object is valid and has a reference, returns false // on failure and nothing is pushed on the stack. ! bool GetObject(); // Remove any existing reference and allocate another. // You cannot call this after calling GetXXXPtr(), but only if this wraps a // stack item. ! void SetObject(int stack_idx); // The following methods are used by the wxValidator interface --- 309,331 ---- // in the wxlua_lreg_refs_key registy table wxLuaObject(const wxLuaState& wxlState, int stack_idx); + wxLuaObject(lua_State* L, int stack_idx); virtual ~wxLuaObject(); + // YOU MUST ALWAYS CALL THIS before deleting this object! + // This is because we do not store a pointer to the lua_State in the + // constructor since we may be used in coroutines and we need to + // make sure that we push the data into the correct lua_State. + void RemoveReference(lua_State* L); + // Get the value of the reference object and push it onto the stack. // (or a proxy if the object has been aliased for a wxValidator class.) // returns true if the object is valid and has a reference, returns false // on failure and nothing is pushed on the stack. ! bool GetObject(lua_State* L); // Remove any existing reference and allocate another. // You cannot call this after calling GetXXXPtr(), but only if this wraps a // stack item. ! void SetObject(lua_State* L, int stack_idx); // The following methods are used by the wxValidator interface *************** *** 324,337 **** // a pointer to read/write from/to. // You may only call only one of these per instance of a wxLuaObject class. ! bool *GetBoolPtr(); ! int *GetIntPtr(); ! wxString *GetStringPtr(); ! wxArrayInt *GetArrayPtr(); ! // Return a flag value that indicated whether the ! // object is being used by a wxValidator class (else wxLUAOBJECT_NONE). wxLuaObject_Type GetAllocationFlag() const { return m_alloc_flag; } ! ! wxLuaState GetwxLuaState() const; protected: --- 335,349 ---- // a pointer to read/write from/to. // You may only call only one of these per instance of a wxLuaObject class. ! bool *GetBoolPtr(lua_State* L); ! int *GetIntPtr(lua_State* L); ! wxString *GetStringPtr(lua_State* L); ! wxArrayInt *GetArrayPtr(lua_State* L); ! // Return a flag value that indicated which GetXXXPrt() function was called ! // else wxLUAOBJECT_NONE. This is for using this object with a wxValidator class wxLuaObject_Type GetAllocationFlag() const { return m_alloc_flag; } ! // Returns the reference number in the wxlua_lreg_refs_key Lua Registry table ! // or LUA_NOREF if not setup. ! int GetReference() const { return m_reference; } protected: *************** *** 611,615 **** // Call only once after subclassed version is created to sort the bindings appropriately ! void InitBinding(); // Register the classes, defines, strings, events, objects, and functions --- 623,627 ---- // Call only once after subclassed version is created to sort the bindings appropriately ! void InitBinding(); // Register the classes, defines, strings, events, objects, and functions Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.129 retrieving revision 1.130 diff -C2 -d -r1.129 -r1.130 *** wxlstate.h 30 Jan 2010 19:00:48 -0000 1.129 --- wxlstate.h 3 Dec 2010 04:39:43 -0000 1.130 *************** *** 659,663 **** //---------------------------------------------------------------------------- ! // enum wxLuaState_Type is for the function // wxLuaState::Create(lua_State* L, int state_type = wxLUASTATE_GETSTATE); enum wxLuaState_Type --- 659,664 ---- //---------------------------------------------------------------------------- ! // enum wxLuaState_Type is for the functions ! // wxLuaState(lua_State* L, int state_type = wxLUASTATE_GETSTATE) // wxLuaState::Create(lua_State* L, int state_type = wxLUASTATE_GETSTATE); enum wxLuaState_Type *************** *** 1061,1065 **** void lua_PushValue(int index); void lua_Remove(int index); ! void lua_Pop(int count); void lua_Insert(int index); void lua_Replace(int index); --- 1062,1066 ---- void lua_PushValue(int index); void lua_Remove(int index); ! void lua_Pop(int count) const; void lua_Insert(int index); void lua_Replace(int index); |