Skip to content

Commit bd869e1

Browse files
committed
xrScriptEngine: improve lua state dumper
Fixed userdata retrieve Other minor changes
1 parent 9ff1917 commit bd869e1

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/xrScriptEngine/script_engine.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void CScriptEngine::print_stack(lua_State* L)
228228
{
229229
while ((name = lua_getlocal(L, &l_tDebugInfo, VarID++)) != nullptr)
230230
{
231-
LogVariable(L, name, 1, true);
231+
LogVariable(L, name, 1);
232232

233233
lua_pop(L, 1); /* remove variable value */
234234
}
@@ -258,13 +258,13 @@ void CScriptEngine::LogTable(lua_State* luaState, pcstr S, int level)
258258
char sFullName[256];
259259
xr_sprintf(sname, "%s", lua_tostring(luaState, -2));
260260
xr_sprintf(sFullName, "%s.%s", S, sname);
261-
LogVariable(luaState, sFullName, level + 1, false);
261+
LogVariable(luaState, sFullName, level + 1);
262262

263263
lua_pop(luaState, 1); /* removes `value'; keeps `key' for next iteration */
264264
}
265265
}
266266

267-
void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool bOpenTable)
267+
void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level)
268268
{
269269
const int ntype = lua_type(luaState, -1);
270270
const pcstr type = lua_typename(luaState, ntype);
@@ -280,6 +280,14 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
280280
xr_strcpy(value, "nil");
281281
break;
282282

283+
case LUA_TFUNCTION:
284+
xr_strcpy(value, "[function]");
285+
break;
286+
287+
case LUA_TTHREAD:
288+
xr_strcpy(value, "[thread]");
289+
break;
290+
283291
case LUA_TNUMBER:
284292
xr_sprintf(value, "%f", lua_tonumber(luaState, -1));
285293
break;
@@ -294,7 +302,7 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
294302

295303
case LUA_TTABLE:
296304
{
297-
if (bOpenTable)
305+
if (level <= 3)
298306
{
299307
Msg("%s Table: %s", tabBuffer, name);
300308
LogTable(luaState, name, level + 1);
@@ -304,20 +312,19 @@ void CScriptEngine::LogVariable(lua_State* luaState, pcstr name, int level, bool
304312
break;
305313
}
306314

315+
// XXX: can we process lightuserdata like userdata? In other words, is this fallthrough allowed?
316+
// case LUA_TLIGHTUSERDATA:
307317
case LUA_TUSERDATA:
308318
{
309-
/*luabind::detail::object_rep* obj = static_cast<luabind::detail::object_rep*>(lua_touserdata(luaState, -1));
310-
luabind::detail::lua_reference& r = obj->get_lua_table(); // XXX: No such method
311-
if (r.is_valid())
319+
lua_getmetatable(luaState, -1); // Maybe we can do this in another way
320+
if (lua_istable(luaState, -1))
312321
{
313-
r.get(luaState);
314322
Msg("%s Userdata: %s", tabBuffer, name);
315323
LogTable(luaState, name, level + 1);
316324
lua_pop(luaState, 1); //Remove userobject
317325
return;
318-
}*/
319-
xr_strcpy(value, "[TODO: Fix userdata retrieval]");
320-
break;
326+
}
327+
//[[fallthrough]]
321328
}
322329

323330
default:
@@ -800,7 +807,7 @@ CScriptEngine::CScriptEngine(bool is_editor)
800807
*m_last_no_file = 0;
801808
#ifdef USE_DEBUGGER
802809
#ifndef USE_LUA_STUDIO
803-
STATIC_CHECK(false, Do_Not_Define_USE_LUA_STUDIO_macro_without_USE_DEBUGGER_macro);
810+
static_assert(false, "Do not define USE_LUA_STUDIO macro without USE_DEBUGGER macro");
804811
m_scriptDebugger = nullptr;
805812
restartDebugger();
806813
#else

src/xrScriptEngine/script_engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class XRSCRIPTENGINE_API CScriptEngine
150150
void print_stack(lua_State* L = nullptr);
151151

152152
void LogTable(lua_State* l, pcstr S, int level);
153-
void LogVariable(lua_State* l, pcstr name, int level, bool bOpenTable);
153+
void LogVariable(lua_State* l, pcstr name, int level);
154154

155155
using ExporterFunc = XRay::ScriptExporter::Node::ExporterFunc;
156156
CScriptEngine(bool is_editor = false);

0 commit comments

Comments
 (0)