From: John L. <jr...@us...> - 2007-12-10 23:20:51
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15373/wxLua/modules/wxluadebug/src Modified Files: wxldebug.cpp wxlstack.cpp Log Message: Allow browsing userdata's metatables in wxLuaStackDialog and give more info about wxLua's structs Index: wxlstack.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxlstack.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** wxlstack.cpp 10 Dec 2007 05:39:10 -0000 1.26 --- wxlstack.cpp 10 Dec 2007 23:20:19 -0000 1.27 *************** *** 624,628 **** int img = GetItemImage(debugItem); ! if ((img == IMG_TABLE) || (img == IMG_TABLE_OPEN)) { wxTreeItemId id = m_treeCtrl->AppendItem(treeId, debugItem->GetKey(), -1, -1, new wxLuaStackTreeData(stkListData)); --- 624,628 ---- int img = GetItemImage(debugItem); ! if (debugItem->GetReference() != LUA_NOREF) { wxTreeItemId id = m_treeCtrl->AppendItem(treeId, debugItem->GetKey(), -1, -1, new wxLuaStackTreeData(stkListData)); Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** wxldebug.cpp 10 Dec 2007 05:39:10 -0000 1.57 --- wxldebug.cpp 10 Dec 2007 23:20:19 -0000 1.58 *************** *** 243,246 **** --- 243,256 ---- } + wxString wxLuaBindClassString(wxLuaBindClass* wxlClass) + { + wxCHECK_MSG(wxlClass, wxEmptyString, wxT("Invalid wxLuaBindClass")); + return wxString::Format(wxT(" (%s, tag=%d, classinfo=%s, baseclass=%s, methods=%d, enums=%d)"), + lua2wx(wxlClass->name).c_str(), *wxlClass->class_tag, + wxString(wxlClass->classInfo ? wxlClass->classInfo->GetClassName() : wxEmptyString).c_str(), + lua2wx(wxlClass->baseclassName).c_str(), + wxlClass->methods_n, wxlClass->enums_n); + } + int wxLuaDebugData::EnumerateTable(const wxLuaState& wxlState_, int tableRef, int nIndex, wxArrayInt& references) { *************** *** 259,263 **** if ((tableRef == -1) || (tableRef == LUA_GLOBALSINDEX)) { ! wxlState.GetGlobals(); GetTypeValue(wxlState, -1, &wxl_valuetype, value); --- 269,273 ---- if ((tableRef == -1) || (tableRef == LUA_GLOBALSINDEX)) { ! lua_pushvalue(L, LUA_GLOBALSINDEX); GetTypeValue(wxlState, -1, &wxl_valuetype, value); *************** *** 270,274 **** else if (tableRef == LUA_REGISTRYINDEX) { ! wxlState.lua_PushValue(LUA_REGISTRYINDEX); GetTypeValue(wxlState, -1, &wxl_valuetype, value); --- 280,284 ---- else if (tableRef == LUA_REGISTRYINDEX) { ! lua_pushvalue(L, LUA_REGISTRYINDEX); GetTypeValue(wxlState, -1, &wxl_valuetype, value); *************** *** 282,287 **** { // push the table onto the stack to iterate through ! if (wxlState.wxluaR_GetRef(tableRef, &wxlua_lreg_debug_refs_key)) { // Check to see if this is a wxLua LUA_REGISTRYINDEX table void *lightuserdata_reg_key = NULL; --- 292,305 ---- { // push the table onto the stack to iterate through ! if (wxluaR_getref(L, tableRef, &wxlua_lreg_debug_refs_key)) { + if (lua_isnil(L, -1)) + { + // assert so we don't crash mysteriously inside Lua on nil + lua_pop(L, 1); // pop nil + wxFAIL_MSG(wxT("Invalid wxLua debug reference")); + return count; + } + // Check to see if this is a wxLua LUA_REGISTRYINDEX table void *lightuserdata_reg_key = NULL; *************** *** 293,297 **** lua_pop(L, 2); // pop wxlua_lreg_regtable_key table and (nil or lightuserdata) ! // Check if it has a metatable if (lua_getmetatable(L, -1)) // if no metatable then nothing is pushed { --- 311,315 ---- lua_pop(L, 2); // pop wxlua_lreg_regtable_key table and (nil or lightuserdata) ! // Check if the table/userdata has a metatable if (lua_getmetatable(L, -1)) // if no metatable then nothing is pushed { *************** *** 310,313 **** --- 328,333 ---- // start iterating + if (lua_istable(L, -1)) + { lua_pushnil(L); while (lua_next(L, -2) != 0) *************** *** 315,322 **** // value at -1, key at -2, table at -3 ! // get the index, just want the name=value, type is dummy here ! GetTypeValue(wxlState, -2, &wxl_keytype, name); ! // get the type and value ! GetTypeValue(wxlState, -1, &wxl_valuetype, value); // Handle wxLua LUA_REGISTRYINDEX tables to give more information --- 335,342 ---- // value at -1, key at -2, table at -3 ! // get the key type and value ! int lua_key_type = GetTypeValue(wxlState, -2, &wxl_keytype, name); ! // get the value type and value ! int lua_value_type = GetTypeValue(wxlState, -1, &wxl_valuetype, value); // Handle wxLua LUA_REGISTRYINDEX tables to give more information *************** *** 327,330 **** --- 347,355 ---- value += wxT(" (") + wxluaT_gettagname(L, (int)lua_tonumber(L, -2)) + wxT(")"); } + else if (lightuserdata_reg_key == &wxlua_lreg_classes_key) + { + wxLuaBindClass* wxlClass = (wxLuaBindClass*)lua_touserdata(L, -1); + value += wxLuaBindClassString(wxlClass); + } else if (lightuserdata_reg_key == &wxlua_lreg_evtcallbacks_key) { *************** *** 359,367 **** } int flag_type = 0; int nRef = LUA_NOREF; // don't ref anything in this table since it's already refed ! if (lightuserdata_reg_key != &wxlua_lreg_debug_refs_key) nRef = RefTable(L, -1, &flag_type, references); Add(new wxLuaDebugItem(name, wxl_keytype, value, wxl_valuetype, wxT(""), nRef, nIndex, flag_type)); --- 384,416 ---- } + // For these keys we know what is in the value to give more information + if (lua_key_type == LUA_TLIGHTUSERDATA) + { + void* key = lua_touserdata(L, -2); + + if (key == &wxlua_metatable_tag_key) + { + value += wxT(" (") + wxluaT_gettagname(L, (int)lua_tonumber(L, -1)) + wxT(")"); + } + else if (key == &wxlua_metatable_wxluabindclass_key) + { + wxLuaBindClass* wxlClass = (wxLuaBindClass*)lua_touserdata(L, -1); + value += wxLuaBindClassString(wxlClass); + } + } + int flag_type = 0; int nRef = LUA_NOREF; // don't ref anything in this table since it's already refed ! if ((lua_value_type == LUA_TTABLE) && (lightuserdata_reg_key != &wxlua_lreg_debug_refs_key)) nRef = RefTable(L, -1, &flag_type, references); + else if (lua_value_type == LUA_TUSERDATA) + { + if (lua_getmetatable(L, -1)) // doesn't push anything if nil + { + nRef = RefTable(L, -1, &flag_type, references); + lua_pop(L, 1); + } + } Add(new wxLuaDebugItem(name, wxl_keytype, value, wxl_valuetype, wxT(""), nRef, nIndex, flag_type)); *************** *** 370,373 **** --- 419,423 ---- lua_pop(L, 1); // pop value, leave key } + } lua_pop(L, 1); // remove reference *************** *** 383,387 **** int nRef = LUA_NOREF; ! if (lua_istable(L, stack_idx)) { //nRef = wxluaR_isrefed(L, stack_idx, &wxlua_lreg_debug_refs_key); // don't duplicate refs --- 433,437 ---- int nRef = LUA_NOREF; ! //if (lua_istable(L, stack_idx)) { //nRef = wxluaR_isrefed(L, stack_idx, &wxlua_lreg_debug_refs_key); // don't duplicate refs *************** *** 532,536 **** { const char* ss = *(const char**)udata; ! s += wxString::Format(wxT(" : %s"), lua2wx(ss).c_str()); } } --- 582,586 ---- { const char* ss = *(const char**)udata; ! s += wxT(" (") + lua2wx(ss) + wxT(")"); } } |