From: John L. <jr...@us...> - 2005-12-02 06:38:39
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1520/modules/wxluadebug/src Modified Files: staktree.cpp wxldebug.cpp Log Message: restore the stacktree for the wxLua app more code unification for wxLuaDebug classes revert to EnumerateStack, EnumerateStackEntry, EnumerateTable instead of BuildStack, BuildStackList, BuildTableList Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** wxldebug.cpp 1 Dec 2005 06:43:53 -0000 1.7 --- wxldebug.cpp 2 Dec 2005 06:38:31 -0000 1.8 *************** *** 177,189 **** } ! int wxLuaDebugData::BuildStack(const wxLuaState& wxlState_) { ! wxLuaState wxlState(wxlState_); // unconst the state int nIndex = 0; bool fFirst = true; int count = 0; - lua_Debug luaDebug; - lua_State* L = wxlState.GetLuaState(); while (lua_getstack(L, nIndex, &luaDebug) != 0) --- 177,190 ---- } ! int wxLuaDebugData::EnumerateStack(const wxLuaState& wxlState_) { ! wxCHECK_MSG(wxlState_.Ok(), 0, wxT("Invalid wxLuaState")); + wxLuaState wxlState(wxlState_); // unconst the state + lua_State* L = wxlState.GetLuaState(); + lua_Debug luaDebug; int nIndex = 0; bool fFirst = true; int count = 0; while (lua_getstack(L, nIndex, &luaDebug) != 0) *************** *** 225,235 **** } ! int wxLuaDebugData::BuildStackList(const wxLuaState& wxlState_, int stackRef, wxArrayInt& references) { ! wxLuaState wxlState(wxlState_); // unconst the state ! int count = 0; ! lua_Debug luaDebug; lua_State* L = wxlState.GetLuaState(); if (lua_getstack(L, stackRef, &luaDebug) != 0) --- 226,237 ---- } ! int wxLuaDebugData::EnumerateStackEntry(const wxLuaState& wxlState_, int stackRef, wxArrayInt& references) { ! wxCHECK_MSG(wxlState_.Ok(), 0, wxT("Invalid wxLuaState")); ! wxLuaState wxlState(wxlState_); // unconst the state lua_State* L = wxlState.GetLuaState(); + lua_Debug luaDebug; + int count = 0; if (lua_getstack(L, stackRef, &luaDebug) != 0) *************** *** 239,307 **** while (!name.IsEmpty()) { - bool fIsTable = false; wxString type; wxString value; wxString source = lua2wx(luaDebug.source); ! switch (lua_type(L, -1)) ! { ! case LUA_TNIL: ! type = wxT("Nil"); ! value = wxT("nil"); ! break; ! ! case LUA_TBOOLEAN: ! type = wxT("Boolean"); ! value = MakeBoolean(lua_toboolean(L, -1)); ! break; ! ! case LUA_TNUMBER: ! type = wxT("Number"); ! value = MakeNumber(lua_tonumber(L, -1)); ! break; ! ! case LUA_TSTRING: ! type = wxT("String"); ! value = lua2wx(lua_tostring(L, -1)); ! break; ! ! case LUA_TTABLE: ! type = wxT("Table"); ! value = GetTableInfo(wxlState, -1); ! fIsTable = true; ! break; ! ! case LUA_TFUNCTION: ! if (lua_iscfunction(L, -1)) ! { ! type = wxT("C Function"); ! value.Printf(wxT("%p"), lua_tocfunction(L, -1)); ! } ! else ! { ! type = wxT("Lua Function"); ! value.Printf(wxT("%p"), lua_topointer(L, -1)); ! } ! break; ! ! case LUA_TUSERDATA: ! type = wxT("User Data"); ! value = GetUserDataInfo(wxlState, -1); ! break; ! ! case LUA_TLIGHTUSERDATA: ! type = wxT("Light User Data"); ! value = GetUserDataInfo(wxlState, -1, false); ! break; ! ! case LUA_TTHREAD: ! type = wxT("Thread"); ! value.Printf(wxT("%p"), lua_topointer(L, -1)); ! break; ! } int nRef = LUA_NOREF; ! if (lua_istable(L, -1)) // FIXME or fIsTable { lua_pushvalue(L, -1); --- 241,253 ---- while (!name.IsEmpty()) { wxString type; wxString value; wxString source = lua2wx(luaDebug.source); ! GetTypeValue(wxlState, -1, type, value); int nRef = LUA_NOREF; ! if (lua_istable(L, -1)) { lua_pushvalue(L, -1); *************** *** 324,329 **** } ! int wxLuaDebugData::BuildTableList(const wxLuaState& wxlState_, int tableRef, int nIndex, wxArrayInt& references) { wxLuaState wxlState(wxlState_); // unconst the state lua_State* L = wxlState.GetLuaState(); --- 270,276 ---- } ! int wxLuaDebugData::EnumerateTable(const wxLuaState& wxlState_, int tableRef, int nIndex, wxArrayInt& references) { + wxCHECK_MSG(wxlState_.Ok(), 0, wxT("Invalid wxLuaState")); wxLuaState wxlState(wxlState_); // unconst the state lua_State* L = wxlState.GetLuaState(); *************** *** 334,343 **** lua_pushvalue(L, LUA_GLOBALSINDEX); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugDataItem(wxT("Globals"), ! wxT(""), ! wxT(""), ! wxT(""), ! nRef, ! 0)); references.Add(nRef); } --- 281,285 ---- lua_pushvalue(L, LUA_GLOBALSINDEX); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugDataItem(wxT("Globals"), wxT(""), wxT(""), wxT(""), nRef, 0)); references.Add(nRef); } *************** *** 352,356 **** while (lua_next(L, nTop) != 0) { - bool fIsTable = false; wxString type; wxString value; --- 294,297 ---- *************** *** 401,464 **** } ! // get the value ! switch (lua_type(L, -1)) ! { ! case LUA_TNIL: ! type = wxT("Nil"); ! value = wxT("nil"); ! break; ! ! case LUA_TBOOLEAN: ! value = MakeBoolean(lua_toboolean(L, -1)); ! type = wxT("Boolean"); ! break; ! ! case LUA_TNUMBER: ! value = MakeNumber(lua_tonumber(L, -1)); ! type = wxT("Number"); ! break; ! ! case LUA_TSTRING: ! type = wxT("String"); ! value = lua2wx(lua_tostring(L, -1)); ! break; ! ! case LUA_TTABLE: ! type = wxT("Table"); ! value = GetTableInfo(wxlState, -1); ! fIsTable = true; ! break; ! ! case LUA_TFUNCTION: ! if (lua_iscfunction(L, -1)) ! { ! type = wxT("C Function"); ! value.Printf(wxT("%p"), lua_tocfunction(L, -1)); ! } ! else ! { ! type = wxT("Lua Function"); ! value.Printf(wxT("%p"), lua_topointer(L, -1)); ! } ! break; ! ! case LUA_TUSERDATA: ! type = wxT("User Data"); ! value = GetUserDataInfo(wxlState, -1); ! break; ! ! case LUA_TLIGHTUSERDATA: ! type = wxT("Light User Data"); ! value = GetUserDataInfo(wxlState, -1, false); ! break; ! ! case LUA_TTHREAD: ! type = wxT("Thread"); ! value.Printf(wxT("%p"), lua_topointer(L, -1)); ! break; ! } int nRef = LUA_NOREF; ! if (fIsTable) { nRef = wxlState.tinsert(-1); --- 342,350 ---- } ! // get the type and value ! GetTypeValue(wxlState, -1, type, value); int nRef = LUA_NOREF; ! if (lua_istable(L, -1)) { nRef = wxlState.tinsert(-1); *************** *** 484,487 **** --- 370,438 ---- } + int wxLuaDebugData::GetTypeValue(const wxLuaState& wxlState, int index, wxString& type, wxString& value) + { + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + lua_State* L = wxlState.GetLuaState(); + int l_type = lua_type(L, -1); + + switch (l_type) + { + case LUA_TNIL: + type = wxT("Nil"); + value = wxT("nil"); + break; + + case LUA_TBOOLEAN: + type = wxT("Boolean"); + value = MakeBoolean(lua_toboolean(L, -1)); + break; + + case LUA_TNUMBER: + type = wxT("Number"); + value = MakeNumber(lua_tonumber(L, -1)); + break; + + case LUA_TSTRING: + type = wxT("String"); + value = lua2wx(lua_tostring(L, -1)); + break; + + case LUA_TTABLE: + type = wxT("Table"); + value = GetTableInfo(wxlState, -1); + break; + + case LUA_TFUNCTION: + if (lua_iscfunction(L, -1)) + { + type = wxT("C Function"); + value.Printf(wxT("%p"), lua_tocfunction(L, -1)); + } + else + { + type = wxT("Lua Function"); + value.Printf(wxT("%p"), lua_topointer(L, -1)); + } + break; + + case LUA_TUSERDATA: + type = wxT("User Data"); + value = GetUserDataInfo(wxlState, -1); + break; + + case LUA_TLIGHTUSERDATA: + type = wxT("Light User Data"); + value = GetUserDataInfo(wxlState, -1, false); + break; + + case LUA_TTHREAD: + type = wxT("Thread"); + value.Printf(wxT("%p"), lua_topointer(L, -1)); + break; + } + + return l_type; + } + wxString wxLuaDebugData::MakeNumber(double dnum) { *************** *** 505,508 **** --- 456,460 ---- wxString wxLuaDebugData::GetTableInfo(const wxLuaState& wxlState, int index) { + wxCHECK_MSG(wxlState.Ok(), wxEmptyString, wxT("Invalid wxLuaState")); lua_State* L = wxlState.GetLuaState(); int nItems = luaL_getn(L, index); *************** *** 517,525 **** wxString wxLuaDebugData::GetUserDataInfo(const wxLuaState& wxlState_, int index, bool full) { wxLuaState wxlState(wxlState_); // unconst wxLuaState lua_State* L = wxlState.GetLuaState(); if (full) { - int nTag = wxlState.ttag(index); --- 469,477 ---- wxString wxLuaDebugData::GetUserDataInfo(const wxLuaState& wxlState_, int index, bool full) { + wxCHECK_MSG(wxlState_.Ok(), wxEmptyString, wxT("Invalid wxLuaState")); wxLuaState wxlState(wxlState_); // unconst wxLuaState lua_State* L = wxlState.GetLuaState(); if (full) { int nTag = wxlState.ttag(index); *************** *** 537,541 **** } - // ---------------------------------------------------------------------------- // wxLuaInterface (local) --- 489,492 ---- *************** *** 563,567 **** } ! wxLuaDebugData *wxLuaInterface::BuildStack() { wxLuaDebugData *pSortedList = new wxLuaDebugData(); --- 514,518 ---- } ! wxLuaDebugData *wxLuaInterface::EnumerateStack() { wxLuaDebugData *pSortedList = new wxLuaDebugData(); *************** *** 569,577 **** return NULL; ! pSortedList->BuildStack(m_wxlState); return pSortedList; } ! wxLuaDebugData *wxLuaInterface::BuildStackList(int nEntry) { wxLuaDebugData *pSortedList = new wxLuaDebugData(); --- 520,528 ---- return NULL; ! pSortedList->EnumerateStack(m_wxlState); return pSortedList; } ! wxLuaDebugData *wxLuaInterface::EnumerateStackEntry(int nEntry) { wxLuaDebugData *pSortedList = new wxLuaDebugData(); *************** *** 579,587 **** return NULL; ! pSortedList->BuildStackList(m_wxlState, nEntry, m_references); return pSortedList; } ! wxLuaDebugData *wxLuaInterface::BuildTableList(int nRef, int nIndex) { wxLuaDebugData *pSortedList = new wxLuaDebugData(); --- 530,538 ---- return NULL; ! pSortedList->EnumerateStackEntry(m_wxlState, nEntry, m_references); return pSortedList; } ! wxLuaDebugData *wxLuaInterface::EnumerateTable(int nRef, int nIndex) { wxLuaDebugData *pSortedList = new wxLuaDebugData(); *************** *** 589,593 **** return NULL; ! pSortedList->BuildTableList(m_wxlState, nRef, nIndex, m_references); return pSortedList; } --- 540,544 ---- return NULL; ! pSortedList->EnumerateTable(m_wxlState, nRef, nIndex, m_references); return pSortedList; } Index: staktree.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/staktree.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** staktree.cpp 1 Dec 2005 04:17:29 -0000 1.9 --- staktree.cpp 2 Dec 2005 06:38:31 -0000 1.10 *************** *** 141,147 **** if (m_pServer != NULL) m_pServer->CleanupDebugReferences(); - - // if (m_pServer != NULL) - // wxLuaHandler::GetHandler().SetStackFrame(NULL); } --- 141,144 ---- *************** *** 155,161 **** m_secondValueWindow = NULL; - // if (m_pServer != NULL) - // wxLuaHandler::GetHandler().SetStackFrame(this); - m_stackComboBox = new wxComboBox( this, ID_WXLUA_STACKFRAME_COMBO, --- 152,155 ---- *************** *** 258,262 **** else { ! wxLuaDebugData *pSortedList = m_luaInterface->BuildStack(); if (pSortedList != NULL) { --- 252,256 ---- else { ! wxLuaDebugData *pSortedList = m_luaInterface->EnumerateStack(); if (pSortedList != NULL) { *************** *** 330,334 **** else { ! wxLuaDebugData *pSortedList = m_luaInterface->BuildStackList(nEntry); if (pSortedList != NULL) { --- 324,328 ---- else { ! wxLuaDebugData *pSortedList = m_luaInterface->EnumerateStackEntry(nEntry); if (pSortedList != NULL) { *************** *** 444,448 **** { // insert items ! wxLuaDebugData *pSortedList = m_luaInterface->BuildTableList(nRef, nIndex); if (pSortedList != NULL) { --- 438,442 ---- { // insert items ! wxLuaDebugData *pSortedList = m_luaInterface->EnumerateTable(nRef, nIndex); if (pSortedList != NULL) { |