From: John L. <jr...@us...> - 2007-12-13 00:48:25
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15370/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxlstate.h Log Message: * Allowed using wxObject:DynamicCast() on an object and be able to use the object as both types. The problem was that wxEvent:GetEventObject() returned a wxObject which overwrote the wxWindow (perhaps) that you had as a userdata in Lua already. Additionally, if you delete an object all of the userdata that wrap it have their metatables cleared for safety. Functions renamed since they didn't do the same thing or behave the same. wxluaO_istrackedobject -> wxluaO_isgcobject wxluaO_addtrackedobject -> wxluaO_addgcobject wxluaO_removetrackedobject -> wxluaO_deletegcobject - Created a central luauserdata:delete() function for the bindings to reduce code. wxLua_wxluabind_delete(L) wxLuaStackDialog: You can expand both key and values of a table and more information is provided about items wxLua knows about. Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** wxlbind.h 10 Dec 2007 05:39:09 -0000 1.70 --- wxlbind.h 13 Dec 2007 00:47:51 -0000 1.71 *************** *** 23,26 **** --- 23,29 ---- // ---------------------------------------------------------------------------- + // Generic delete function for binding objects + WXDLLIMPEXP_WXLUA int LUACALL wxLua_wxluabind_delete(lua_State *L); + // memory deallocation function for created wxLuaBindClass defined objects, Lua's __gc metatable index WXDLLIMPEXP_WXLUA int LUACALL wxluabind__gc_wxLuaBindClass(lua_State *L); Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.104 retrieving revision 1.105 diff -C2 -d -r1.104 -r1.105 *** wxlstate.h 10 Dec 2007 05:39:09 -0000 1.104 --- wxlstate.h 13 Dec 2007 00:47:51 -0000 1.105 *************** *** 101,105 **** extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_wxluastate_key; // The key in the LUA_REGISTRYINDEX table that is table of all ! // objects that we've pushed into Lua. t[lightuserdata] = [weak valued full userdata] extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_weakobjects_key; // The key in the LUA_REGISTRYINDEX table that is table of all --- 101,108 ---- extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_wxluastate_key; // The key in the LUA_REGISTRYINDEX table that is table of all ! // objects that we've pushed into Lua. ! // t[lightuserdata of obj_ptr] = { tag1 = [weak full userdata], tag2... } ! // Note: a single object like a wxWindow may be pushed as multiple tags when ! // they create it wxWindow* = wx.wxWindow... later from wxObject* wxEvent.GetEventObject() extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_weakobjects_key; // The key in the LUA_REGISTRYINDEX table that is table of all *************** *** 108,112 **** // Note that non wxObject classes use wxLUA_DECLARE_ENCAPSULATION so // the key is the object pointer and the value is the wxObject encapsulation. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_delobjects_key; // The key in the LUA_REGISTRYINDEX table that is table of all // wxLuaCallbacks that we've created. --- 111,116 ---- // Note that non wxObject classes use wxLUA_DECLARE_ENCAPSULATION so // the key is the object pointer and the value is the wxObject encapsulation. ! // If not encapsulated both the key and the value are the same ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_gcobjects_key; // The key in the LUA_REGISTRYINDEX table that is table of all // wxLuaCallbacks that we've created. *************** *** 246,283 **** // wxluaO_XXX - functions operate on the "Objects" which are userdata wrapping // C++ class objects and are stored in the wxlua_lreg_weakobjects_key table ! // and the wxlua_lreg_delobjects_key in Lua's LUA_REGISTRYINDEX. //---------------------------------------------------------------------------- ! enum wxLuaRemoveTrackedObject_flags { ! wxLUA_UNDELETE_OBJECT = 0, // stop tracking for deletion (someone else owns this) ! wxLUA_DELETE_OBJECT = 0x0001, // delete the object ! wxLUA_CLEAR_TRACKED_OBJECT = 0x0002, // clear tracking the object in Lua reg table ! wxLUA_CLEAR_DERIVED_METHODS = 0x0004, // clear any derived methods in Lua reg table ! wxLUA_DELETE_CLEAR_OBJECT = wxLUA_DELETE_OBJECT|wxLUA_CLEAR_TRACKED_OBJECT|wxLUA_CLEAR_DERIVED_METHODS }; // Track this wxObject and delete it when Lua calls the __gc method for it. ! // The object is stored in the wxlua_lreg_delobjects_key of the LUA_REGISTRYINDEX // as t[lightuserdata(obj_ptr)] = lightuserdata(wxobj). // The second version is used when the non-wxObject class is encapsulated and so // the obj_ptr points to the actual object that the wxObject encapsulates. ! WXDLLIMPEXP_WXLUA void LUACALL wxluaO_addtrackedobject(lua_State* L, wxObject* wxobj); ! WXDLLIMPEXP_WXLUA void LUACALL wxluaO_addtrackedobject(lua_State* L, const void* obj_ptr, wxObject* wxobj); ! // Remove this tracked wxObject from the wxlua_lreg_delobjects_key table of the // LUA_REGISTRYINDEX. ! // The object can be deleted and other items assicated may be cleared ! // by setting the "flags" from ored values of enum wxLuaRemoveTrackedObject_flags ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_removetrackedobject(lua_State *L, void *obj_ptr, int flags); ! // Check if this object is in the wxlua_lreg_delobjects_key table of the // LUA_REGISTRYINDEX. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_istrackedobject(lua_State *L, void *obj_ptr); ! // Get a wxArrayString of the info in the wxlua_lreg_delobjects_key LUA_REGISTRYINDEX table. ! WXDLLIMPEXP_WXLUA wxArrayString LUACALL wxluaO_gettrackedobjectstrings(lua_State *L); ! // If an object was pushed into Lua using wxluaT_pushusertag with track=true ! // then this function will remove the metable of the object being tracked in the ! // wxlua_lreg_weakobjects_key Lua LUA_REGISTRYINDEX table. ! WXDLLIMPEXP_WXLUA void LUACALL wxluaO_cleartrackedmetatable(lua_State* L, const void* u); //---------------------------------------------------------------------------- --- 250,300 ---- // wxluaO_XXX - functions operate on the "Objects" which are userdata wrapping // C++ class objects and are stored in the wxlua_lreg_weakobjects_key table ! // and the wxlua_lreg_gcobjects_key in Lua's LUA_REGISTRYINDEX. //---------------------------------------------------------------------------- ! enum wxLuaGCObject_flags { ! wxLUA_UNDELETE_OBJECT = 0x0001, // Remove from the wxlua_lreg_gcobjects_key table ! // so we won't delete it (someone else should), ! // but keep the userdata in the wxlua_lreg_weakobjects_key ! // table, it's still in Lua and is usable. ! wxLUA_DELETE_OBJECT = 0x0002, // Literally delete the object and remove it from the ! // wxlua_lreg_gcobjects_key table. See remove... ! wxLUA_REMOVE_OBJECT = 0x0004, // Clear tracking the object in the wxlua_lreg_weakobjects_key ! // and wxlua_lreg_derivedmethods_key since ! // it's gone from Lua. ! ! wxLUA_DELETE_REMOVE_OBJECT = wxLUA_DELETE_OBJECT|wxLUA_REMOVE_OBJECT }; // Track this wxObject and delete it when Lua calls the __gc method for it. ! // The object is stored in the wxlua_lreg_gcobjects_key of the LUA_REGISTRYINDEX // as t[lightuserdata(obj_ptr)] = lightuserdata(wxobj). // The second version is used when the non-wxObject class is encapsulated and so // the obj_ptr points to the actual object that the wxObject encapsulates. ! WXDLLIMPEXP_WXLUA void LUACALL wxluaO_addgcobject(lua_State* L, wxObject* wxobj); ! WXDLLIMPEXP_WXLUA void LUACALL wxluaO_addgcobject(lua_State* L, const void* obj_ptr, wxObject* wxobj); ! // Remove this tracked wxObject from the wxlua_lreg_gcobjects_key table of the // LUA_REGISTRYINDEX. ! // The object can be deleted and other items associated with it may be removed ! // by setting the "flags" from ored values of enum wxLuaGCObject_flags ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_deletegcobject(lua_State *L, void *obj_ptr, int flags); ! // Check if this object is in the wxlua_lreg_gcobjects_key table of the // LUA_REGISTRYINDEX. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_isgcobject(lua_State *L, void *obj_ptr); ! // Get a wxArrayString of the info in the wxlua_lreg_gcobjects_key LUA_REGISTRYINDEX table. ! WXDLLIMPEXP_WXLUA wxArrayString LUACALL wxluaO_getgcobjectstrings(lua_State *L); ! // Track the obj_ptr and it's Lua userdata in the wxlua_lreg_weakobjects_key ! // table of the LUA_REGISTRYINDEX so we can push it again if needed. ! WXDLLIMPEXP_WXLUA void LUACALL wxluaO_trackweakobject(lua_State *L, int udata_stack_idx, void *obj_ptr, int tag); ! // Remove the obj_ptr key from the wxlua_lreg_weakobjects_key table of ! // the LUA_REGISTRYINDEX. It also removes the metatable for ALL Lua userdata ! // that are associated with this obj_ptr since this function is called when the ! // object is deleted. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_untrackweakobject(lua_State *L, void *obj_ptr); ! // Check if this object with the given tag is in the wxlua_lreg_weakobjects_key ! // table of the LUA_REGISTRYINDEX. If push_on_stack then push on top of the stack. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_istrackedweakobject(lua_State *L, void *obj_ptr, int tag, bool push_on_stack); //---------------------------------------------------------------------------- *************** *** 773,788 **** // Track this object and delete it when Lua calls the gc method for it ! void AddTrackedObject(wxObject *pObject); // Track this object, but hash it on the obj_ptr which may differ from the // pObject and delete it when Lua calls the gc method for it. // This is used for encapsulated classes that are wrapped in a wxObject. ! void AddTrackedObject(const void* obj_ptr, wxObject *pObject); // Remove the object from the tracked memory and optionally delete it. ! // flags are ored values of enum wxLuaRemoveTrackedObject_flags ! bool RemoveTrackedObject(void *pObject, int flags); // Is this object currently tracked? ! bool IsTrackedObject(void *pObject) const; // Get an array of strings "wxObject_classname count#" ! wxArrayString GetTrackedObjectStrings(); // Add a wxWindow to track and delete when we're closed, only track --- 790,805 ---- // Track this object and delete it when Lua calls the gc method for it ! void AddGCObject(wxObject *pObject); // Track this object, but hash it on the obj_ptr which may differ from the // pObject and delete it when Lua calls the gc method for it. // This is used for encapsulated classes that are wrapped in a wxObject. ! void AddGCObject(const void* obj_ptr, wxObject *pObject); // Remove the object from the tracked memory and optionally delete it. ! // flags are ored values of enum wxLuaGCObject_flags ! bool DeleteGCObject(void *pObject, int flags); // Is this object currently tracked? ! bool IsGCObject(void *pObject) const; // Get an array of strings "wxObject_classname count#" ! wxArrayString GetGCObjectStrings(); // Add a wxWindow to track and delete when we're closed, only track |