Modify Lua warn() function to support @on and @off

This commit is contained in:
Gnome Ann
2022-01-21 01:28:26 -05:00
parent 44d49ed0b2
commit 82455e310b

View File

@ -1669,12 +1669,33 @@ return function(_python, _bridged)
bridged.print(table.concat(args, "\t")) bridged.print(table.concat(args, "\t"))
end end
local function redirected_warn(...) local function _redirected_warn()
local args = table.pack(...) local do_warning = true
for i = 1, args.n do local control_table = {
args[i] = tostring(args[i]) ["@on"] = function()
do_warning = true
end,
["@off"] = function()
do_warning = false
end,
}
return function(...)
local args = table.pack(...)
if args.n == 1 and type(args[1]) == "string" and args[1]:sub(1, 1) == "@" then
local f = control_table[args[1]]
if f ~= nil then
f()
end
return
end
if not do_warning then
return
end
for i = 1, args.n do
args[i] = tostring(args[i])
end
bridged.warn(table.concat(args, "\t"))
end end
bridged.warn(table.concat(args, "\t"))
end end
local sandbox_template_env = { local sandbox_template_env = {
@ -1834,7 +1855,7 @@ return function(_python, _bridged)
envs[universe].load = _safe_load(env) envs[universe].load = _safe_load(env)
envs[universe].require = _safe_require(env) envs[universe].require = _safe_require(env)
envs[universe].print = redirected_print envs[universe].print = redirected_print
envs[universe].warn = redirected_warn envs[universe].warn = _redirected_warn()
env._G = env env._G = env
end end
return env return env