diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-09 13:29:57 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-09 13:29:57 +0800 |
commit | 96647a35c6977909df5d6c5f7e77d0a4a2dbe2c0 (patch) | |
tree | 535909151e4f4efc950df6506728e7660f96acb3 /server/src/vm | |
parent | 3ea2eca2553e34a637fbae1be3ec4413026a9a7b (diff) | |
download | lua-language-server-96647a35c6977909df5d6c5f7e77d0a4a2dbe2c0.zip |
支持rawset和rawget
Diffstat (limited to 'server/src/vm')
-rw-r--r-- | server/src/vm/raw.lua | 29 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 5 |
2 files changed, 34 insertions, 0 deletions
diff --git a/server/src/vm/raw.lua b/server/src/vm/raw.lua new file mode 100644 index 00000000..31a8e8d1 --- /dev/null +++ b/server/src/vm/raw.lua @@ -0,0 +1,29 @@ +local mt = require 'vm.manager' + +function mt:callRawSet(func, values, source) + local tbl = values[1] + local index = values[2] + local value = values[3] + if not tbl or not index or not value then + return + end + if index:getLiteral() then + index = index:getLiteral() + end + tbl:addInfo('set child', source, index) + tbl:rawSet(index, value, source) +end + +function mt:callRawGet(func, values, source) + local tbl = values[1] + local index = values[2] + if not tbl or not index then + return + end + if index:getLiteral() then + index = index:getLiteral() + end + tbl:addInfo('get child', source, index) + local value = tbl:rawGet(index) + func:setReturn(1, value) +end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index dfdac390..1f9f4e83 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -11,6 +11,7 @@ local config = require 'config' local mt = require 'vm.manager' require 'vm.module' +require 'vm.raw' -- TODO source测试 --rawset(_G, 'CachedSource', setmetatable({}, { __mode = 'kv' })) @@ -277,6 +278,10 @@ function mt:callLibrary(func, values, source, lib) self:callModuel(func, values) elseif lib.special == 'seeall' then self:callSeeAll(func, values) + elseif lib.special == 'rawset' then + self:callRawSet(func, values, source) + elseif lib.special == 'rawget' then + self:callRawGet(func, values, source) end else -- 如果lib的参数中有function,则立即执行function |