mesecons
mesecons copied to clipboard
Add safe version of pcall and error function to luacontroller environment
Currently propagates all errors generated by the luacontroller code itself (e.g. string length overflow), which might not be the desired behavior, but can be fixed if necessary.
I'm not sure if anyone actually wants this feature, but it could be useful for certain forms of non-local control flow, and judging by the comment I saw by the safe_globals definition, it seems like there was some interest in it.
I suggest you write safe_pcall something like this (I haven't tested the code):
local function finish_safe_pcall(...)
local ok, err = ...
if not ok and not debug.gethook() then
error(err, 0)
end
return ...
end
local function safe_pcall(f, ...)
return finish_safe_pcall(pcall(f, ...))
end
This handles nil return values correctly.
Calling error with 0 as its second argument throws the given message without modifying it.
I support this! I would not like to manually check inputs for errors.