util.startup: Handle missing nparams field from debug info (not present in 5.1)

This commit is contained in:
Matthew Wild 2020-10-11 20:25:32 +01:00
parent bb3948c857
commit c07d15cf71

View file

@ -198,11 +198,12 @@ function startup.set_function_metatable()
end
function mt.__tostring(f)
local info = debug.getinfo(f, "Su");
for i = 1, info.nparams do
local n_params = info.nparams or 0;
for i = 1, n_params do
info[i] = debug.getlocal(f, i);
end
if info.isvararg then
info[info.nparams+1] = "...";
info[n_params+1] = "...";
end
return ("function<%s:%d>(%s)"):format(info.short_src:match("[^\\/]*$"), info.linedefined, table.concat(info, ", "));
end