From: John L. <jr...@us...> - 2007-12-13 06:23:58
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv11381/wxLua/modules/wxlua/include Modified Files: wxlstate.h Log Message: Second try at really allowing pushing the same object, but with different tags by tracking the userdata and have it fully clean up after itself. Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.105 retrieving revision 1.106 diff -C2 -d -r1.105 -r1.106 *** wxlstate.h 13 Dec 2007 00:47:51 -0000 1.105 --- wxlstate.h 13 Dec 2007 06:23:54 -0000 1.106 *************** *** 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 of obj_ptr] = { tag1 = [weak full userdata], tag2... } // Note: a single object like a wxWindow may be pushed as multiple tags when --- 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 of obj_ptr] = { tag1 = [weak full userdata], tag2... } // Note: a single object like a wxWindow may be pushed as multiple tags when *************** *** 253,269 **** //---------------------------------------------------------------------------- ! 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 }; --- 253,263 ---- //---------------------------------------------------------------------------- ! enum wxLuaGCObject_Flags { ! WXLUA_DELETE_OBJECT_LAST = 0x0000, // Delete the object if this is the last ! // userdata referece to it. ! WXLUA_DELETE_OBJECT_ALL = 0x0001, // Delete the object and clear all userdata ! // references to it. }; *************** *** 276,283 **** 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. --- 270,283 ---- 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 and delete it depending on the flags enum wxLuaGCObject_Flags. ! // If WXLUA_DELETE_OBJECT_ALL or if this is the last userdata it will also remove all ! // wxlua_lreg_weakobjects_key and wxlua_lreg_derivedmethods_key since the object is gone. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_deletegcobject(lua_State *L, void* udata, void *obj_ptr, int flags); ! ! // Remove this tracked wxObject from the wxlua_lreg_gcobjects_key table of the ! // LUA_REGISTRYINDEX. The Lua userdata for the object stays in Lua and it's ! // assumed that someone else will delete the object (took ownership of it). ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaO_undeletegcobject(lua_State *L, void *obj_ptr); ! // Check if this object is in the wxlua_lreg_gcobjects_key table of the // LUA_REGISTRYINDEX. *************** *** 289,297 **** // 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. --- 289,298 ---- // 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 removes the metatable for the Lua userdata, "udata", ! // that are associated with this obj_ptr since this function is called when the ! // object is deleted. If udata == NULL it removes ALL tracked userdata and clears ! // all of their metatables. ! WXDLLIMPEXP_WXLUA int LUACALL wxluaO_untrackweakobject(lua_State *L, void* udata, 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. *************** *** 428,433 **** // userdata and the new wxLuaObject wraps the Lua function or value // which will be deleted by this. ! // The derived methods are stored in the "wxLuaDerivedMethods" table in the ! // Lua registry table. WXDLLIMPEXP_WXLUA bool LUACALL wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj); // Is there a derived method given an object and and a method name. --- 429,434 ---- // userdata and the new wxLuaObject wraps the Lua function or value // which will be deleted by this. ! // The derived methods are stored in the wxlua_lreg_derivedmethods_key table ! // in the LUA_REGISTRYINDEX. WXDLLIMPEXP_WXLUA bool LUACALL wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj); // Is there a derived method given an object and and a method name. *************** *** 437,441 **** // When an object is being garbage collected and we call RemoveTrackedObject // object on it, we should also remove any derived functions or values it may have. ! WXDLLIMPEXP_WXLUA bool LUACALL wxlua_removederivedmethod(lua_State* L, void *pObject); //---------------------------------------------------------------------------- --- 438,442 ---- // When an object is being garbage collected and we call RemoveTrackedObject // object on it, we should also remove any derived functions or values it may have. ! WXDLLIMPEXP_WXLUA bool LUACALL wxlua_removederivedmethods(lua_State* L, void *pObject); //---------------------------------------------------------------------------- *************** *** 790,803 **** // 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(); --- 791,804 ---- // Track this object and delete it when Lua calls the gc method for it ! void AddGCObject(wxObject *wxobj); // 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 *wxobj); // Remove the object from the tracked memory and optionally delete it. // flags are ored values of enum wxLuaGCObject_flags ! bool DeleteGCObject(void* udata, void *obj_ptr, int flags); // Is this object currently tracked? ! bool IsGCObject(void *obj_ptr) const; // Get an array of strings "wxObject_classname count#" wxArrayString GetGCObjectStrings(); *************** *** 953,957 **** // When an object is being garbage collected and we call RemoveTrackedObject // object on it, we should also remove any derived functions or values it may have. ! bool RemoveDerivedMethod(void *pObject) const; // Find a derived method given an object and and a method name. // If the method can be found, return the valid wxLuaState it belongs to. --- 954,958 ---- // When an object is being garbage collected and we call RemoveTrackedObject // object on it, we should also remove any derived functions or values it may have. ! bool RemoveDerivedMethods(void *pObject) const; // Find a derived method given an object and and a method name. // If the method can be found, return the valid wxLuaState it belongs to. |