diff options
Diffstat (limited to 'server/src/vm/module.lua')
-rw-r--r-- | server/src/vm/module.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/server/src/vm/module.lua b/server/src/vm/module.lua new file mode 100644 index 00000000..60191bf3 --- /dev/null +++ b/server/src/vm/module.lua @@ -0,0 +1,56 @@ +local mt = require 'vm.manager' +local createMulti = require 'vm.multi' + +--[[ +function module(name, ...) + local env = {} + for _, opt in ipairs {...} do + opt(env) + end + @ENV = env +end +--]] +function mt:callModuel(func, values) + local envLoc = self:loadLocal('@ENV') + if not envLoc then + return + end + local source = self:getDefaultSource() + local newEnvValue = self:createValue('table', source) + local args = createMulti() + + args:push(newEnvValue) + + for i = 2, #values do + local value = values[i] + -- opt(env) + self:call(value, args, source) + end + + -- @ENV = env + envLoc:setValue(newEnvValue) +end + +--[[ +function package.seeall(env) + setmetatable(env, { __index = @ENV }) +end +--]] +function mt:callSeeAll(func, values) + local newEnv = values[1] + if not newEnv then + return + end + local envLoc = self:loadLocal('@ENV') + if not envLoc then + return + end + local oldEnv = envLoc:getValue() + if not oldEnv then + return + end + local source = self:getDefaultSource() + local meta = self:createValue('table', source) + meta:setChild('__index', oldEnv, source) + newEnv:setMetaTable(meta) +end |