From: John L. <jr...@us...> - 2007-11-30 23:00:42
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22316/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxlstate.h Log Message: - wxLuaStackDialog has better search for all columns, collapse and expand tables, and show metatables. It also now uses a virtual wxListCtrl so it's much faster. - Separated the "tags" for C++ classes from "refs" for objects we want a handle on in the Lua registry by putting them in separate tables. - Removed wxlua_pushkey_XXX #defines since we now have a few tables in the registry that we use and those methods were not useful anymore. The lightuserdata keys are now const char* strings with a descriptive name, however only the mem address is used as the table key. - wxluaT_newtag() now leaves the created table on the stack. - Removed wxluaT_newweaktag() and wxluaT_settagmethod() since they were not needed anymore. Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** wxlbind.h 30 Nov 2007 06:23:39 -0000 1.64 --- wxlbind.h 30 Nov 2007 23:00:06 -0000 1.65 *************** *** 505,509 **** int m_start_tag; // The first wxLua allocated Lua tag int m_last_tag; // The last wxLua Lua tag of registered classes ! int m_luaTable_tag; // The Lua tag for the wxLua private tables static wxLuaBindingList sm_bindingList; --- 505,509 ---- int m_start_tag; // The first wxLua allocated Lua tag int m_last_tag; // The last wxLua Lua tag of registered classes ! int m_luaTable_ref; // The Lua ref for the wxLua private tables static wxLuaBindingList sm_bindingList; Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** wxlstate.h 17 Nov 2007 00:15:00 -0000 1.95 --- wxlstate.h 30 Nov 2007 23:00:07 -0000 1.96 *************** *** 76,129 **** // ---------------------------------------------------------------------------- - #define WXLUA_LREG_REFERENCES 1 - #define WXLUA_LREG_CLASSES 2 - #define WXLUA_LREG_DERIVED_METHODS 3 - #define WXLUA_LREG_WXLUASTATE 4 - #define WXLUA_LREG_OBJECTS 5 - #define WXLUA_LREG_CALLBASECLASSFUNC 6 - #define WXLUA_METATABLE_TAG 7 - #define WXLUA_METATABLE_CLASS 8 - // Light user data used as keys in the Lua LUA_REGISTRYINDEX table for wxLua items. // Note that even though these have values, they're not used, just the memory address. - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_references_key; // WXLUA_LREG_REFERENCES - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_classes_key; // WXLUA_LREG_CLASSES - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_derivedmethods_key; // WXLUA_LREG_DERIVED_METHODS - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_wxluastate_key; // WXLUA_LREG_WXLUASTATE - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_objects_key; // WXLUA_LREG_OBJECTS - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_callbaseclassfunc_key; // WXLUA_LREG_CALLBASECLASSFUNC - - // Light user data used as keys in the metatables created for the class userdata objects. - // Note that even though these have values, they're not used, just the memory address. - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_metatable_tag_key; // WXLUA_METATABLE_TAG - extern WXDLLIMPEXP_DATA_WXLUA(int) wxlua_lreg_metatable_class_key; // WXLUA_METATABLE_CLASS ! // Push a key that is index in the LUA_REGISTRYINDEX table that is a table indexed ! // on the "tags" and each item is a metatable for classes ! // or a reference to an object we want to keep a handle to. ! #define wxlua_pushkey_wxLuaReferences(L) lua_pushlightuserdata(L, &wxlua_lreg_references_key) ! // Push a key that is an index in the LUA_REGISTRYINDEX table that is a table ! // t[wxLuaBindClass.name] = wxLuaBindClass, where the wxLuaBindClass struct is a lightuserdata. ! #define wxlua_pushkey_wxLuaClasses(L) lua_pushlightuserdata(L, &wxlua_lreg_classes_key) ! // Push a key that is an index in the LUA_REGISTRYINDEX table that is a table // of Lua functions assigned to wxLua userdata programatically in Lua. // t[lightuserdata object] = {["derived func/value name"] = wxLuaObject(Lua function/value), ...} ! #define wxlua_pushkey_wxLuaDerivedMethods(L) lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key) ! // Push a key that is an index of the LUA_REGISTRYINDEX table who's value is a // lightuserdata of the wxLuaState for this lua_State. ! #define wxlua_pushkey_wxLuaState(L) lua_pushlightuserdata(L, &wxlua_lreg_wxluastate_key) ! // Push a key that is an index of the LUA_REGISTRYINDEX table that is table of all // objects that we've pushed into Lua using t[lightuserdata] = [weak valued full userdata] ! #define wxlua_pushkey_wxLuaObjects(L) lua_pushlightuserdata(L, &wxlua_lreg_objects_key) ! // Push a key that is an index of the LUA_REGISTRYINDEX table that is boolean value // of whether the Lua code has prepended a '_' to function name to indicate // that they want the base class function called. ! #define wxlua_pushkey_CallBaseClassFunc(L) lua_pushlightuserdata(L, &wxlua_lreg_callbaseclassfunc_key) // Push a key of an index into the metatable of a wxLua userdata for the "tag" number. ! #define wxlua_pushkey_metatableTag(L) lua_pushlightuserdata(L, &wxlua_lreg_metatable_tag_key) // Push a key of an index into the metatable of a wxLua userdata for the // lightuserdata of the wxLuaBindClass struct. ! #define wxlua_pushkey_metatableClass(L) lua_pushlightuserdata(L, &wxlua_lreg_metatable_class_key) // ---------------------------------------------------------------------------- --- 76,118 ---- // ---------------------------------------------------------------------------- // Light user data used as keys in the Lua LUA_REGISTRYINDEX table for wxLua items. // Note that even though these have values, they're not used, just the memory address. ! // The key in the LUA_REGISTRYINDEX table that is a table indexed ! // on the "tags" and each item is a metatable for a C++ class. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_tags_key; ! // The key in the LUA_REGISTRYINDEX table that is a numerically keyed table ! // with references to objects we want to keep a handle to. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_refs_key; ! // The key in the LUA_REGISTRYINDEX table that is a numerically keyed table ! // with references to objects we want to keep a handle to. It also ! // stores their value for faster lookup. It is used only for the wxLuaDebugData. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_debug_refs_key; ! // The key that in the LUA_REGISTRYINDEX table that is a table ! // t[wxLuaBindClass.name] = lightuserdata(wxLuaBindClass stuct) ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_classes_key; ! // The key in the LUA_REGISTRYINDEX table that is a table // of Lua functions assigned to wxLua userdata programatically in Lua. // t[lightuserdata object] = {["derived func/value name"] = wxLuaObject(Lua function/value), ...} ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_derivedmethods_key; ! // The key in the LUA_REGISTRYINDEX table who's value is a // lightuserdata of the wxLuaState for this lua_State. ! 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 using t[lightuserdata] = [weak valued full userdata] ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_objects_key; ! // The key in the LUA_REGISTRYINDEX table that is a boolean value // of whether the Lua code has prepended a '_' to function name to indicate // that they want the base class function called. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_lreg_callbaseclassfunc_key; ! ! // Light user data used as keys in the metatables created for the class userdata objects. ! // Note that even though these have values, they're not used, just the memory address. // Push a key of an index into the metatable of a wxLua userdata for the "tag" number. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_metatable_tag_key; // Push a key of an index into the metatable of a wxLua userdata for the // lightuserdata of the wxLuaBindClass struct. ! extern WXDLLIMPEXP_DATA_WXLUA(const char*) wxlua_metatable_wxluabindclass_key; // ---------------------------------------------------------------------------- *************** *** 144,199 **** //---------------------------------------------------------------------------- ! // Create a reference to the object at stack index in the ! // wxLuaReferences registry table, returns the table index or LUA_REFNIL ! // if the item on the stack is none or nil (an error). ! WXDLLIMPEXP_WXLUA int LUACALL wxluaT_insert(lua_State* L, int stack_idx); ! // Remove a reference to the object at the index in the ! // wxLuaReferences registry table, returns success. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_remove(lua_State* L, int wxlref_index); ! // Push onto the top of the stack the object at the index in the ! // wxLuaReferences registry table, if the index is LUA_REFNIL or the // value is nil return false and don't leave anything on the stack. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_get(lua_State* L, int wxlref_index); // Push the object u onto the top of the stack wrapped in a newuserdata ! // with it's metatable set to the table from wxluaT_get(tag). Returns true if the ! // tag is known and the metatable was set. If track=true then push the ! // object as a lightuser data key into the wxlua_pushkey_wxLuaObjects table of ! // the Lua registry so that if we need to push it again we just push the full ! // userdata value. WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_pushusertag(lua_State* L, const void* u, int tag, bool track); // If an object was pushed into Lua using wxluaT_pushusertag with track=true // then this function will remove the object from being tracked in the ! // wxlua_pushkey_wxLuaObjects Lua registry table. WXDLLIMPEXP_WXLUA void LUACALL wxluaT_untrackuserdata(lua_State* L, const void* u); // 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_pushkey_wxLuaObjects Lua registry table. WXDLLIMPEXP_WXLUA void LUACALL wxluaT_cleartrackedmetatable(lua_State* L, const void* u); ! // Get the numeric tag of the object at the stack index using the metatable's "tag" key. ! // returns WXLUA_NOTAG if the metatable of the object doesn't have a "tag" ! // key or it isn't a number. The tag is presumedly the index into the wxLuaReferences ! // registry table and denotes what type of object this is. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_tag(lua_State* L, int stack_idx); // Get the userdata at the stack index, if null_ptr then set the pointer wrapped // by Lua's userdata to NULL to clear it. WXDLLIMPEXP_WXLUA void* LUACALL wxlua_touserdata(lua_State* L, int stack_idx, bool null_ptr = false); ! // Allocate a new table (metatable) with a "tag" key equal to the number from wxluaT_insert ! // and store it in the wxLuaReferences registry table. ! // Returns the index into the ref table, the "tag" from wxluaT_insert. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_newtag(lua_State* L); - // Create a new table and its metatable with weak keys and/or values by setting the - // metatable's __weak index to [k/v]. The table is wxluaT_insert into the wxLuaReferences - // registry table. Returns the created index into the ref table. - WXDLLIMPEXP_WXLUA int LUACALL wxluaT_newweaktag(lua_State* L, bool weak_keys, bool weak_values); // Set the metatable of the object at top of stack to the table stored in the ! // wxLuaReferences registry table using wxluaT_get(tag). WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_settag(lua_State* L, int tag); - // Set a metamethod for the metatable referenced by tag with the supplied name and function. - // If pClass is non-null set the upvalue of the function to the supplied wxLuaBindClass. - WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_settagmethod(lua_State* L, int tag, const char* method, - lua_CFunction func, void* pClass = NULL); // Is the item at the stack_idx in the wxLuaReferences table already? // returns the tag or LUA_NOREF if it's not. ! WXDLLIMPEXP_WXLUA int LUACALL wxluaT_isrefed(lua_State* L, int stack_idx); // ---------------------------------------------------------------------------- --- 133,181 ---- //---------------------------------------------------------------------------- ! // Create a reference to the object at stack index in a table with the key ! // lightuserdata_reg_key in the LUA_REGISTRYINDEX table. Does not pop the object. ! // Returns the table index or LUA_REFNIL if the item on the stack is none or nil (an error). ! WXDLLIMPEXP_WXLUA int LUACALL wxluaT_insert(lua_State* L, int stack_idx, const void* lightuserdata_reg_key); ! // Remove a reference to the object at the index in a table with the key ! // lightuserdata_reg_key in the LUA_REGISTRYINDEX table, returns success. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_remove(lua_State* L, int wxlref_index, const void* lightuserdata_reg_key); ! // Push onto the top of the stack the object at the index in a table with the key ! // lightuserdata_reg_key in the LUA_REGISTRYINDEX table, if the index is LUA_REFNIL or the // value is nil return false and don't leave anything on the stack. ! WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_get(lua_State* L, int wxlref_index, const void* lightuserdata_reg_key); // Push the object u onto the top of the stack wrapped in a newuserdata ! // with it's metatable set to the table from wxluaT_get(tag). ! // Returns true if the tag is known and the metatable was set. ! // If track=true then push the object as a lightuser data key into the ! // wxlua_lreg_objects_key table of the Lua LUA_REGISTRYINDEX table so that if we need to ! // push it again we just push the full userdata value. WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_pushusertag(lua_State* L, const void* u, int tag, bool track); // If an object was pushed into Lua using wxluaT_pushusertag with track=true // then this function will remove the object from being tracked in the ! // wxlua_lreg_objects_key Lua LUA_REGISTRYINDEX table. WXDLLIMPEXP_WXLUA void LUACALL wxluaT_untrackuserdata(lua_State* L, const void* u); // 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_objects_key Lua LUA_REGISTRYINDEX table. WXDLLIMPEXP_WXLUA void LUACALL wxluaT_cleartrackedmetatable(lua_State* L, const void* u); ! // Get the numeric tag of the object at the stack index using the metatable's wxlua_metatable_tag_key key. ! // Returns WXLUA_NOTAG if the metatable of the object doesn't have a wxlua_metatable_tag_key ! // key or it isn't a number. The tag is presumedly the index into the wxlua_lreg_tags_key ! // LUA_REGISTRYINDEX table and denotes what type of C++ object this is. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_tag(lua_State* L, int stack_idx); // Get the userdata at the stack index, if null_ptr then set the pointer wrapped // by Lua's userdata to NULL to clear it. WXDLLIMPEXP_WXLUA void* LUACALL wxlua_touserdata(lua_State* L, int stack_idx, bool null_ptr = false); ! // Allocate a new table (metatable) with a wxlua_metatable_tag_key key equal ! // to the number from wxluaT_insert and store it in the wxlua_lreg_tags_key LUA_REGISTRYINDEX table. ! // Returns the index into the tags table, the return value from wxluaT_insert. ! // Leaves the new table on the top of the stack. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_newtag(lua_State* L); // Set the metatable of the object at top of stack to the table stored in the ! // wxlua_lreg_tags_key LUA_REGISTRYINDEX table using wxluaT_get(tag). WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_settag(lua_State* L, int tag); // Is the item at the stack_idx in the wxLuaReferences table already? // returns the tag or LUA_NOREF if it's not. ! WXDLLIMPEXP_WXLUA int LUACALL wxluaT_isrefed(lua_State* L, int stack_idx, const void* lightuserdata_reg_key); // ---------------------------------------------------------------------------- *************** *** 695,732 **** // wxLua Lua Registry Table Functions ! // Create a reference to the object at stack index in the ! // wxLuaReferences registry table, returns the table index. ! int wxluaT_Insert(int stack_idx); ! // Remove a reference to the object at the index in the ! // wxLuaReferences registry table, returns success. ! bool wxluaT_Remove(int wxlref_index); ! // Push onto the top of the stack the object at the index in the ! // wxLuaReferences registry table, if the index is LUA_REFNIL or the ! // value is nil return false and don't leave anything on the stack. ! bool wxluaT_Get(int wxlref_index); ! // Push the object u onto the top of the stack wrapped in a newuserdata ! // with it's metatable set to the table from wxluaT_Get(tag). Returns true if the ! // tag is known and the metatable was set. ! bool wxluaT_PushUserTag(const void *u, int tag, bool track); ! // Get the numeric tag of the object at the stack index using the metatable's "tag" key. ! // returns WXLUA_NOTAG if the metatable of the object doesn't have a "tag" ! // key or it isn't a number. The tag is presumedly the index into the wxLuaReferences ! // registry table and denotes what type of object this is. ! int wxluaT_Tag(int stack_idx) const; ! // Get the userdata at the stack index, if null_ptr then set the userdata pointer ! // in Lua to NULL so that Lua won't gc it. void* wxlua_ToUserdata(int stack_idx, bool null_ptr = false) const; ! // Create a new table (metatable) wxluaT_Insert it into the wxLuaReferences registry table ! // and return its index into the ref table. ! int wxluaT_NewTag(); ! // Create a new table and its metatable with weak keys and/or values by setting the ! // metatable's __weak index to [k/v]. The table is wxluaT_Insert into the wxLuaReferences ! // registry table and return its index into the ref table. ! int wxluaT_NewWeakTag(bool weak_keys, bool weak_values); ! // Set the metatable of the object at top of stack to wxluaT_Get(tag) ! bool wxluaT_SetTag(int tag); ! // Set a metamethod for the metatable referenced by tag with the supplied name and function. ! // if pClass is non-null set the upvalue of the function to the supplied class ! bool wxluaT_SetTagMethod(int tag, const char *method, lua_CFunction func, void *pClass = NULL); // ----------------------------------------------------------------------- --- 677,688 ---- // wxLua Lua Registry Table Functions ! int wxluaT_Insert(int stack_idx, const void* lightuserdata_reg_key); ! bool wxluaT_Remove(int wxlref_index, const void* lightuserdata_reg_key); ! bool wxluaT_Get(int wxlref_index, const void* lightuserdata_reg_key); ! bool wxluaT_PushUserTag(const void *u, int tag, bool track); ! int wxluaT_Tag(int stack_idx) const; void* wxlua_ToUserdata(int stack_idx, bool null_ptr = false) const; ! int wxluaT_NewTag(); ! bool wxluaT_SetTag(int tag); // ----------------------------------------------------------------------- |