Skip to content

Commit 1a43dbb

Browse files
committed
xrScriptEngine: dump lua state only with -luadumpstate cmd key
Added LUA_TNIL case for LogVariable()
1 parent fa4fb77 commit 1a43dbb

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/xrScriptEngine/script_engine.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,26 @@ void CScriptEngine::print_stack(lua_State* L)
219219
lua_pop(L, 1); // restore lua stack
220220

221221
// Giperion: verbose log
222-
Log("\nLua state dump:\n\tLocals: ");
223-
pcstr name = nullptr;
224-
int VarID = 1;
225-
try
222+
if (strstr(Core.Params, "-luadumpstate"))
226223
{
227-
while ((name = lua_getlocal(L, &l_tDebugInfo, VarID++)) != nullptr)
224+
Log("\nLua state dump:\n\tLocals: ");
225+
pcstr name = nullptr;
226+
int VarID = 1;
227+
try
228228
{
229-
LogVariable(L, name, 1, true);
229+
while ((name = lua_getlocal(L, &l_tDebugInfo, VarID++)) != nullptr)
230+
{
231+
LogVariable(L, name, 1, true);
230232

231-
lua_pop(L, 1); /* remove variable value */
233+
lua_pop(L, 1); /* remove variable value */
234+
}
232235
}
236+
catch (...)
237+
{
238+
Log("Can't dump lua state - Engine corrupted");
239+
}
240+
Log("\tEnd\nEnd of Lua state dump.\n");
233241
}
234-
catch (...)
235-
{
236-
Log("Can't dump lua state - Engine corrupted");
237-
}
238-
Log("\tEnd\nEnd of Lua state dump.\n");
239242
// -Giperion
240243
}
241244

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

274277
switch (ntype)
275278
{
279+
case LUA_TNIL:
280+
xr_strcpy(value, "nil");
281+
break;
282+
276283
case LUA_TNUMBER:
277284
xr_sprintf(value, "%f", lua_tonumber(luaState, -1));
278285
break;
@@ -294,8 +301,8 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
294301
return;
295302
}
296303
xr_sprintf(value, "[...]");
297-
}
298304
break;
305+
}
299306

300307
case LUA_TUSERDATA:
301308
{
@@ -310,15 +317,14 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
310317
return;
311318
}*/
312319
xr_strcpy(value, "[TODO: Fix userdata retrieval]");
313-
}
314320
break;
321+
}
315322

316323
default:
317324
xr_strcpy(value, "[not available]");
318325
break;
319326
}
320327

321-
322328
Msg("%s %s %s : %s", tabBuffer, type, name, value);
323329
}
324330

0 commit comments

Comments
 (0)