summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/meta/Lua 5.4/basic.lua2
-rw-r--r--server/src/vm/special.lua42
-rw-r--r--server/src/vm/vm.lua5
3 files changed, 48 insertions, 1 deletions
diff --git a/server/meta/Lua 5.4/basic.lua b/server/meta/Lua 5.4/basic.lua
index 25e4a43a..dcc3d580 100644
--- a/server/meta/Lua 5.4/basic.lua
+++ b/server/meta/Lua 5.4/basic.lua
@@ -27,7 +27,7 @@ function assert(v, message) end
function collectgarbage(opt, arg) end
--- 打开该名字的文件,并执行文件中的 Lua 代码块。
----@param filename string {optional = 'self'}
+---@param filename string {optional = 'self', special = 'dofile:1'}
---@return any
function dofile(filename) end
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()