Skip to content

Commit

Permalink
dump more recursive output for console
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 14, 2023
1 parent 62b67af commit 6893138
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
29 changes: 28 additions & 1 deletion src/game_api/lua_libs/lua_libs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)##");
}
6 changes: 4 additions & 2 deletions src/game_api/script/lua_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6893138

Please sign in to comment.