-- @runtimes lua54 luajit --- 演示:load 注入白名单环境。 local M = {} --- @return table { result = integer, blocked = boolean } function M.run(log) log = log or print local env = { math = math } local fn = assert(load("return math.max(1, 2)", "=sandbox", "t", env)) local result = fn() local blocked = not pcall(load("return os.time()", "=sandbox", "t", env)) log(("result=%d blocked=%s"):format(result, tostring(blocked))) return { result = result, blocked = blocked } end if not ... then M.run() end return M