From: John L. <jr...@us...> - 2006-05-30 22:56:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/modules/wxlua/src Modified Files: internal.cpp wxlstate.cpp Log Message: move check stack to debug lib and remove duplicate code Index: internal.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/internal.cpp,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** internal.cpp 4 May 2006 05:07:04 -0000 1.41 --- internal.cpp 30 May 2006 22:56:29 -0000 1.42 *************** *** 390,625 **** } - // ---------------------------------------------------------------------------- - // 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; - - if (message.IsEmpty()) - message = 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\r\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); - } - - int wxLuaCheckStack::GetTableInfo(lua_State *L, int index, wxString& address, wxString& info) - { - int nTag = wxLua_lua_ttag(L, index); - int nItems = luaL_getn(L, index); - const void *pItem = lua_topointer(L, index); - - address = wxString::Format(wxT("%p"), pItem); - - if (nTag != TLUA_NOTAG) - { - if (nItems == 0) - info = wxString::Format(_("(tag %u)"), nTag); - else - info = wxString::Format(_("(tag %u, approx. %u items)"), nTag, nItems); - } - else - { - if (nItems == 0) - info = _("(no tag)"); - else - info = wxString::Format(_("(no tag, approx %u items)"), nItems); - } - - return nItems; - } - - // FIXME - this function copied from wxLuaDebugData to remove dependency - wxString wxLuaDebugData_MakeNumber(double dnum) - { - long num = (long) dnum; - if ((double) num == dnum) - { - if (num >= 0) - return wxString::Format(wxT("%lu (0x%lx)"), num, num); - - return wxString::Format(wxT("%ld (0x%lx)"), num, num); - } - - return wxString::Format(wxT("%g"), dnum); - } - - void wxLuaCheckStack::DumpType(lua_State *L, int index, wxString& type, wxString& value, wxString& info) - { - type = wxEmptyString; - value = wxEmptyString; - info = wxEmptyString; - - switch (lua_type(L, index)) - { - default: - type = wxString::Format(wxT("%u"), lua_type(L, index)); - value = wxT("?"); - break; - - case LUA_TNIL: - type = wxT("Nil"); - value = wxT("nil"); - break; - - case LUA_TNUMBER: - type = wxT("Number"); - value = wxLuaDebugData_MakeNumber(lua_tonumber(L, index)); - break; - - case LUA_TSTRING: - type = wxT("String"); - value = lua2wx(lua_tostring(L, index)); - break; - - case LUA_TTABLE: - type = wxT("Table"); - GetTableInfo(L, index, value, info); - break; - - case LUA_TFUNCTION: - if (lua_iscfunction(L, index)) - { - type = wxT("C Function"); - value = wxString::Format(wxT("%p"), lua_tocfunction(L, index)); - } - else - { - type = wxT("Lua Function"); - value = wxString::Format(wxT("%p"), lua_topointer(L, index)); - } - - break; - - case LUA_TUSERDATA: - type = wxT("User Data"); - value = GetUserDataInfo(L, index); - break; - } - - //return wxString::Format(_("%s - type: %s, value: %s\n"), name.c_str(), type.c_str(), value.c_str()); - } - - wxString wxLuaCheckStack::GetUserDataInfo(lua_State *L, int index) - { - wxString userdataInfo; - wxString tagName; - wxLuaState wxlState(L); - - int nTag = wxLua_lua_ttag(L, index); - - if (nTag != TLUA_NOTAG) - tagName = lua2wx(wxlState.GetLuaTagName(nTag)); - - if (!tagName.IsEmpty()) - userdataInfo = wxString::Format(wxT("%p (%s)"), lua_touserdata(L, index), tagName.c_str()); - else - userdataInfo = wxString::Format(wxT("%p (%u)"), lua_touserdata(L, index), nTag); - - return userdataInfo; - } - - void wxLuaCheckStack::DumpTable(lua_State *L, int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent) - { - 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, indexInfo; - wxString valueType, value, valueInfo; - - DumpType(L, -2, indexType, indexValue, indexInfo); - DumpType(L, -1, valueType, value, valueInfo); - - wxString info = wxString::Format(wxT("%s%-32s\t%-15s\t%-20s\t%-10s\t%s"), - indentStr.c_str(), - indexValue.c_str(), - indexType.c_str(), - valueType.c_str(), - value.c_str(), - valueInfo.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(); - } // Validate that the object at the stack index specified is a string object --- 390,393 ---- Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** wxlstate.cpp 25 May 2006 03:55:23 -0000 1.70 --- wxlstate.cpp 30 May 2006 22:56:29 -0000 1.71 *************** *** 63,70 **** extern "C" { - #include "lua/include/lua.h" - #include "lua/include/lauxlib.h" - #include "lua/include/lualib.h" - #ifdef WXLUA_LUA_NEWTHREAD // See lua/src/lstate.c for added hook into luaE_newthread() --- 63,66 ---- |