Skip to content

Commit

Permalink
xrScriptEngine: dump lua state only with -luadumpstate cmd key
Browse files Browse the repository at this point in the history
Added LUA_TNIL case for LogVariable()
  • Loading branch information
Xottab-DUTY committed Mar 7, 2018
1 parent fa4fb77 commit 1a43dbb
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,26 @@ void CScriptEngine::print_stack(lua_State* L)
lua_pop(L, 1); // restore lua stack

// Giperion: verbose log
Log("\nLua state dump:\n\tLocals: ");
pcstr name = nullptr;
int VarID = 1;
try
if (strstr(Core.Params, "-luadumpstate"))
{
while ((name = lua_getlocal(L, &l_tDebugInfo, VarID++)) != nullptr)
Log("\nLua state dump:\n\tLocals: ");
pcstr name = nullptr;
int VarID = 1;
try
{
LogVariable(L, name, 1, true);
while ((name = lua_getlocal(L, &l_tDebugInfo, VarID++)) != nullptr)
{
LogVariable(L, name, 1, true);

lua_pop(L, 1); /* remove variable value */
lua_pop(L, 1); /* remove variable value */
}
}
catch (...)
{
Log("Can't dump lua state - Engine corrupted");
}
Log("\tEnd\nEnd of Lua state dump.\n");
}
catch (...)
{
Log("Can't dump lua state - Engine corrupted");
}
Log("\tEnd\nEnd of Lua state dump.\n");
// -Giperion
}

Expand Down Expand Up @@ -273,6 +276,10 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool

switch (ntype)
{
case LUA_TNIL:
xr_strcpy(value, "nil");
break;

case LUA_TNUMBER:
xr_sprintf(value, "%f", lua_tonumber(luaState, -1));
break;
Expand All @@ -294,8 +301,8 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
return;
}
xr_sprintf(value, "[...]");
}
break;
}

case LUA_TUSERDATA:
{
Expand All @@ -310,15 +317,14 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
return;
}*/
xr_strcpy(value, "[TODO: Fix userdata retrieval]");
}
break;
}

default:
xr_strcpy(value, "[not available]");
break;
}


Msg("%s %s %s : %s", tabBuffer, type, name, value);
}

Expand Down

0 comments on commit 1a43dbb

Please sign in to comment.