@@ -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 (" \n Lua state dump:\n\t Locals: " );
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 (" \n Lua state dump:\n\t Locals: " );
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 (" \t End\n End of Lua state dump.\n " );
233241 }
234- catch (...)
235- {
236- Log (" Can't dump lua state - Engine corrupted" );
237- }
238- Log (" \t End\n End 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