From: John L. <jr...@us...> - 2006-05-30 22:56:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/modules/wxluadebug/src Modified Files: wxldebug.cpp Log Message: move check stack to debug lib and remove duplicate code Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** wxldebug.cpp 25 May 2006 22:50:05 -0000 1.14 --- wxldebug.cpp 30 May 2006 22:56:29 -0000 1.15 *************** *** 24,27 **** --- 24,28 ---- #include "wxluadebug/include/wxldebug.h" + #include "wxlua/include/internal.h" // ---------------------------------------------------------------------------- *************** *** 297,301 **** case LUA_TUSERDATA: type = wxT("User Data"); ! value = GetUserDataInfo(wxlState, index); break; --- 298,302 ---- case LUA_TUSERDATA: type = wxT("User Data"); ! value = GetUserDataInfo(wxlState, index, true); break; *************** *** 337,343 **** --- 338,354 ---- wxCHECK_MSG(wxlState.Ok(), wxEmptyString, wxT("Invalid wxLuaState")); lua_State* L = wxlState.GetLuaState(); + + int nTag = wxLua_lua_ttag(L, index); int nItems = luaL_getn(L, index); const void *pItem = lua_topointer(L, index); + if (nTag != TLUA_NOTAG) + { + if (nItems == 0) + return wxString::Format(wxT("0x%p (tag %u)"), pItem, nTag); + + return wxString::Format(wxT("0x%p (approx %u items) (tag %u)"), pItem, nItems, nTag); + } + if (nItems == 0) return wxString::Format(wxT("0x%p"), pItem); *************** *** 355,364 **** int nTag = wxlState.ttag(index); ! const char *pTagName = NULL; if (nTag != TLUA_NOTAG) ! pTagName = wxlState.GetLuaTagName(nTag); ! if (pTagName != NULL) ! return wxString::Format(wxT("0x%p (%s)"), lua_touserdata(L, index), lua2wx(pTagName).c_str()); return wxString::Format(wxT("0x%p (%u)"), lua_touserdata(L, index), nTag); --- 366,375 ---- int nTag = wxlState.ttag(index); ! wxString pTagName; if (nTag != TLUA_NOTAG) ! pTagName = lua2wx(wxlState.GetLuaTagName(nTag)); ! if (!pTagName.IsEmpty()) ! return wxString::Format(wxT("0x%p (%s)"), lua_touserdata(L, index), pTagName.c_str()); return wxString::Format(wxT("0x%p (%u)"), lua_touserdata(L, index), nTag); *************** *** 431,432 **** --- 442,552 ---- return pSortedList; } + + // ---------------------------------------------------------------------------- + // wxLuaCheckStack - dumps the contents of the lua_State + // ---------------------------------------------------------------------------- + + wxLuaCheckStack::wxLuaCheckStack(lua_State *L, const wxString &msg) + { + m_luaState = L; + m_msg = msg; + m_top = lua_gettop(m_luaState); + } + + wxLuaCheckStack::~wxLuaCheckStack() + { + TestStack(m_msg); + } + + void wxLuaCheckStack::TestStack(const wxString &msg) + { + wxString message(!msg.IsEmpty() ? msg : m_msg); + + #if defined(__WXMSW__) + wxString buf = wxString::Format(_("Stack state in '%s': in %u out %u\r\n"), message.c_str(), m_top, lua_gettop(m_luaState)); + OutputDebugString(buf); + #else //if defined(__WXGTK__) || defined(__WXMAC__) + fprintf(stderr, "Stack state in '%s': in %u out %u\n", (const char *)wx2lua(msg), m_top, lua_gettop(m_luaState)); + #endif + } + + void wxLuaCheckStack::DumpGlobals(lua_State *L) + { + wxLuaStringToLongHashMap dumpList; + + lua_pushvalue(L, LUA_GLOBALSINDEX); + DumpTable(L, lua_gettop(L), wxT("Globals"), dumpList, 0); + lua_pop(L, 1); + } + + void wxLuaCheckStack::DumpTable(lua_State *L, const wxString &name) + { + wxLuaStringToLongHashMap dumpList; + + lua_pushstring(L, wx2lua(name)); + lua_gettable(L, LUA_GLOBALSINDEX); + DumpTable(L, lua_gettop(L), name, dumpList, 0); + lua_pop(L, 1); + } + + void wxLuaCheckStack::DumpTable(lua_State *L, int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent) + { + wxLuaState wxlState(L); + wxString indentStr; + + if (indent > 5) + return; + + for (int i = 0; i < indent; i++) + indentStr += wxT(" "); + + wxString title = wxString::Format(wxT("%sTable: %s"), indentStr.c_str(), tablename.c_str()); + wxLogMessage(title); + + if (!indentStr.IsEmpty()) + indentStr += wxT(">"); + + lua_pushnil(L); + while(lua_next(L, index) != 0) + { + wxString indexType, indexValue; + wxString valueType, value; + + wxLuaDebugData::GetTypeValue(wxlState, -2, indexType, indexValue); + wxLuaDebugData::GetTypeValue(wxlState, -1, valueType, value); + + wxString info = wxString::Format(wxT("%s%-32s\t%-15s\t%-20s\t%-10s"), + indentStr.c_str(), + indexValue.c_str(), + indexType.c_str(), + valueType.c_str(), + value.c_str()); + wxLogMessage(info); + + if (dumpList.find(value) != dumpList.end()) + { + if (valueType == wxT("Table")) + { + wxString tname = wxString::Format(wxT("%s.%s"), tablename.c_str(), indexValue.c_str()); + dumpList[value] = 1; + int tableIndex = lua_gettop(L); + // lua_pushvalue(L, lua_gettop(L)); + DumpTable(L, tableIndex, tname, dumpList, indent+1); + } + else + { + dumpList[value] = 1; + } + } + + //#if defined(__WXMSW__) + // OutputDebugString(outputIndex + outputValue); + //#elif defined(__WXGTK__) + // fprintf(stderr, wx2lua(outputIndex + outputValue)); + //#endif + lua_pop(L, 1); + } + lua_pop(L, 1); + + wxLog::FlushActive(); + } |