first commit
This commit is contained in:
29
code/lua_env.lua
Normal file
29
code/lua_env.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
Reference in New Issue
Block a user