summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-06-28 17:19:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-06-28 17:19:41 +0800
commit4586d62c06751d99199044375393dc1595375491 (patch)
treef727477dee451756dca9227ec6bbb8fe98a40eee /server/src
parentcd115d5fb3ab4f176f5e1c82061e27ad2ab857dd (diff)
downloadlua-language-server-4586d62c06751d99199044375393dc1595375491.zip
实现special
Diffstat (limited to 'server/src')
-rw-r--r--server/src/vm/special.lua42
-rw-r--r--server/src/vm/vm.lua5
2 files changed, 47 insertions, 0 deletions
diff --git a/server/src/vm/special.lua b/server/src/vm/special.lua
new file mode 100644
index 00000000..b22ed06d
--- /dev/null
+++ b/server/src/vm/special.lua
@@ -0,0 +1,42 @@
+local mt = require 'vm.manager'
+
+---@param func emmyFunction
+---@param values table
+function mt:callEmmySpecial(func, values)
+ 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)
+ end
+ end
+end
+
+---@param func emmyFunction
+---@param values table
+---@param index integer
+---@param special string
+function mt:checkEmmyParam(func, values, index, special)
+ if special == 'dofile:1' then
+ self:callEmmyDoFile(func, values, index)
+ end
+end
+
+---@param func emmyFunction
+---@param values table
+---@param index integer
+function mt:callEmmyDoFile(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], 'dofile')
+ if not requireValue then
+ requireValue = self:createValue('any', self:getDefaultSource())
+ requireValue.isRequire = true
+ end
+ func:setReturn(1, requireValue)
+end
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index f0e30537..bafd5841 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -16,6 +16,7 @@ require 'vm.raw'
require 'vm.pcall'
require 'vm.ipairs'
require 'vm.emmy'
+require 'vm.special'
-- TODO source测试
--rawset(_G, 'CachedSource', setmetatable({}, { __mode = 'kv' }))
@@ -325,6 +326,7 @@ end
function mt:call(value, values, source)
local lib = value:getLib()
+ ---@type emmyFunction
local func = value:getFunction()
value:setType('function', 0.5)
if not func then
@@ -343,6 +345,9 @@ function mt:call(value, values, source)
else
func:mergeReturn(1, self:createValue('any', source))
end
+ if func:getEmmyParams() then
+ self:callEmmySpecial(func, values)
+ end
end
return func:getReturn()