diff options
Diffstat (limited to 'server/src/vm/function.lua')
-rw-r--r-- | server/src/vm/function.lua | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index a6835f5b..145e5eda 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -125,6 +125,10 @@ function mt:setObject(value, source) self._objectSource = source end +function mt:getObject() + return self._objectValue, self._objectSource +end + function mt:hasRuned() return self._runed > 0 end @@ -135,6 +139,10 @@ function mt:run() return end + if self._runed > 1 then + --return + end + -- 第一次运行函数时,创建函数的参数 if self._runed ~= 1 then return @@ -157,22 +165,33 @@ function mt:setArgs(values) for i = 1, #values do self.argValues[i] = values[i] end - if self.dots then - local dotsIndex = #self.args - for i = dotsIndex, #values do - self.dots:set(i - dotsIndex + 1, values[i]) - end - end end function mt:createArg(arg) if arg.type == 'name' then local loc = createLocal(arg[1], arg, createValue('any', arg)) self:saveLocal(arg[1], loc) + self.args[#self.args+1] = loc elseif arg.type == '...' then + self._dots = createDots() end end +function mt:createLibArg(arg) + if arg.type == '...' then + self._dots = createDots() + else + local name = arg.name or '_' + local loc = createLocal(name, nil, createValue('any')) + self:saveLocal(name, loc) + self.args[#self.args+1] = loc + end +end + +function mt:hasDots() + return self._dots ~= nil +end + function mt:createArgs() if not self.source then return @@ -194,6 +213,7 @@ return function (source) local self = setmetatable({ source = source, locals = {}, + args = {}, }, mt) self:push() return self |