fix crash on dump because of assumtion that every ref as is_valid

This commit is contained in:
whosit 2024-12-11 23:51:27 +03:00
parent 44d24e549d
commit 86b59e4d08
2 changed files with 15 additions and 17 deletions

View File

@ -55,24 +55,22 @@ local function basic_dump(o)
--elseif tp == "function" then
-- return string.format("loadstring(%q)", string.dump(o))
elseif tp == "userdata" then
if o:is_valid() then
if o.is_player then
if o:is_player() then
return string.format('#<player: "%s">', o:get_player_name())
else
local e = o:get_luaentity()
if e then
return string.format('#<luaentity: "%s">', e.name)
else
return string.format('#<ObjectRef: %s>', o)
end
end
else
return tostring(o)
end
else
if o.is_valid and not o:is_valid() then
return string.format('#<invalid_ref: %s>', o)
end
if o.is_player then
if o:is_player() then
return string.format('#<player: "%s">', o:get_player_name())
else
local e = o:get_luaentity()
if e then
return string.format('#<luaentity: "%s">', e.name)
else
return string.format('#<ObjectRef: %s>', o)
end
end
end
return string.format("#<%s>", o)
else
return string.format("#<%s>", tp)
end

View File

@ -75,7 +75,7 @@ local function create_shared_environment(player_name)
return magic()
elseif not g[key] then
core.chat_send_player(player_name, string.format("* Accessing undeclared variable: '%s'", key))
g[key] = true
g[key] = true -- warn only once
end
end
return res