From 68931381d9ebfdfbd480f0a2f4cf7adc1fb7bc76 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 14 Oct 2023 23:55:07 +0300 Subject: [PATCH] dump more recursive output for console --- src/game_api/lua_libs/lua_libs.cpp | 29 ++++++++++++++++++++++++++++- src/game_api/script/lua_console.cpp | 6 ++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/game_api/lua_libs/lua_libs.cpp b/src/game_api/lua_libs/lua_libs.cpp index ceb681af2..37fd74d86 100644 --- a/src/game_api/lua_libs/lua_libs.cpp +++ b/src/game_api/lua_libs/lua_libs.cpp @@ -796,7 +796,7 @@ local function format(_, str) return fmt and string.format(fmt, fn()) or tostring(fn()) else error(err, 0) - end + end end)) end @@ -955,4 +955,31 @@ return { _NAME = n, _COPYRIGHT = c, _DESCRIPTION = d, _VERSION = v, serialize = block = function(a, opts) return s(a, merge({indent = ' ', sortkeys = true, comment = true}, opts)) end } )serp"; lua["serpent"] = lua.require_script("serpent", serpent_code); + + lua.script(R"##( + function dump(o, d, n) + local n = n or 0 + local t = nil + if getmetatable(o) and (not d or n < d) then + t = {} + if o.pairs then + for k,v in pairs(o) do + t[k] = dump(v, d, n+1) + end + else + for k,v in pairs(getmetatable(o)) do + if k:sub(0, 2) ~= "__" and k ~= "class_cast" and k ~= "class_check" and k ~= "new" then + t[k] = dump(o[k], d, n+1) + end + end + end + else + t = o + end + return t + end + function dump_string(o, d) + return serpent.line(dump(o, d), {comment=false, indent=" "}) + end + )##"); } diff --git a/src/game_api/script/lua_console.cpp b/src/game_api/script/lua_console.cpp index cde609f58..e30ff43c3 100644 --- a/src/game_api/script/lua_console.cpp +++ b/src/game_api/script/lua_console.cpp @@ -1046,8 +1046,10 @@ std::string LuaConsole::execute_raw(std::string code) } else { - sol::function serpent = lua["serpent"]["block"]; - return serpent(ret); + // sol::function serpent = lua["serpent"]["block"]; + // return serpent(ret); + sol::function dump_string = lua["dump_string"]; + return dump_string(ret, 2); } } catch (const sol::error& e)