diff options
Diffstat (limited to 'server/src/vm/special.lua')
-rw-r--r-- | server/src/vm/special.lua | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/server/src/vm/special.lua b/server/src/vm/special.lua index b22ed06d..f8a03a34 100644 --- a/server/src/vm/special.lua +++ b/server/src/vm/special.lua @@ -1,13 +1,14 @@ local mt = require 'vm.manager' +local multi = require 'vm.multi' ---@param func emmyFunction ---@param values table -function mt:callEmmySpecial(func, values) +function mt:callEmmySpecial(func, values, source) local emmyParams = func:getEmmyParams() for index, param in ipairs(emmyParams) do local option = param:getOption() if option and type(option.special) == 'string' then - self:checkEmmyParam(func, values, index, option.special) + self:checkEmmyParam(func, values, index, option.special, source) end end end @@ -16,9 +17,13 @@ end ---@param values table ---@param index integer ---@param special string -function mt:checkEmmyParam(func, values, index, special) +function mt:checkEmmyParam(func, values, index, special, source) if special == 'dofile:1' then self:callEmmyDoFile(func, values, index) + elseif special == 'loadfile:1' then + self:callEmmyLoadFile(func, values, index) + elseif special == 'pcall:1' then + self:callEmmyPCall(func, values, index, source) end end @@ -40,3 +45,49 @@ function mt:callEmmyDoFile(func, values, index) end func:setReturn(1, requireValue) end + +---@param func emmyFunction +---@param values table +---@param index integer +function mt:callEmmyLoadFile(func, values, index) + if not values[index] then + values[index] = self:createValue('any', self:getDefaultSource()) + end + local str = values[index]:getLiteral() + if type(str) ~= 'string' then + return + end + local requireValue = self:tryRequireOne(values[index], 'loadfile') + if not requireValue then + requireValue = self:createValue('any', self:getDefaultSource()) + requireValue:set('cross file', true) + end + func:setReturn(1, requireValue) +end + +---@param func emmyFunction +---@param values table +---@param index integer +function mt:callEmmyPCall(func, values, index, source) + local funcValue = values[index] + if not funcValue then + return + end + local realFunc = funcValue:getFunction() + if not realFunc then + return + end + local argList = multi() + values:eachValue(function (i, v) + if i > index then + argList:push(v) + end + end) + self:call(funcValue, argList, source) + if realFunc ~= func then + func:setReturn(1, self:createValue('boolean', source)) + realFunc:getReturn():eachValue(function (i, v) + func:setReturn(i + 1, v) + end) + end +end |