diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-07-04 19:25:37 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-07-04 19:25:37 +0800 |
commit | 54453139868cdef82406b5868a9f78bc0838b6f7 (patch) | |
tree | c257fecd5a10680f628ef17e1bdc818a4de8e1f9 /server/src | |
parent | 50af0738965aeeecd974f3ba52b2d23ccf3c257a (diff) | |
download | lua-language-server-54453139868cdef82406b5868a9f78bc0838b6f7.zip |
更新 meta
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/vm/special.lua | 57 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 2 |
2 files changed, 55 insertions, 4 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 diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index bafd5841..d41d17bb 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -346,7 +346,7 @@ function mt:call(value, values, source) func:mergeReturn(1, self:createValue('any', source)) end if func:getEmmyParams() then - self:callEmmySpecial(func, values) + self:callEmmySpecial(func, values, source) end end |