Files
Original/code/lua_env.lua

30 lines
614 B
Lua
Raw Permalink Normal View History

2026-05-09 17:39:45 +02:00
local lua_env = {
extends = Node,
env = {}
}
-- optional helper to reset environment
function lua_env:reset_env()
self.env = {}
setmetatable(self.env, { __index = _G }) -- fall back to globals
end
-- the core runscript
function lua_env:run_script(code, node)
local chunk, err = load(code, "runscript", "t", self.env)
if not chunk then
print("[LuaRuntime] Syntax error: ", err)
return false
end
-- Call the chunk, optionally passing context
local ok, result = pcall(chunk, node)
if not ok then
print("[LuaRuntime] Runtime error: ", result)
return false
end
return result
end
return lua_env