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 | |
parent | 3ea2eca2553e34a637fbae1be3ec4413026a9a7b (diff) | |
download | lua-language-server-96647a35c6977909df5d6c5f7e77d0a4a2dbe2c0.zip |
支持rawset和rawget
-rw-r--r-- | server/libs/lua/basic.lni | 2 | ||||
-rw-r--r-- | server/main.lua | 2 | ||||
-rw-r--r-- | server/src/vm/raw.lua | 29 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 5 | ||||
-rw-r--r-- | server/test/definition/set.lua | 5 |
5 files changed, 42 insertions, 1 deletions
diff --git a/server/libs/lua/basic.lni b/server/libs/lua/basic.lni index 9f6c2d75..14c4f669 100644 --- a/server/libs/lua/basic.lni +++ b/server/libs/lua/basic.lni @@ -375,6 +375,7 @@ name = 'v2' type = 'boolean' [rawget] +special = 'rawget' [[.args]] name = 'table' type = 'table' @@ -391,6 +392,7 @@ name = 'len' type = 'integer' [rawset] +special = 'rawset' [[.args]] name = 'table' type = 'table' diff --git a/server/main.lua b/server/main.lua index dd0c53d3..1895f804 100644 --- a/server/main.lua +++ b/server/main.lua @@ -21,7 +21,7 @@ local function tryDebugger() log.info('Debugger startup, listen port: 11411') end -pcall(tryDebugger) +--pcall(tryDebugger) require 'utility' require 'global_protect' 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 diff --git a/server/test/definition/set.lua b/server/test/definition/set.lua index eb899fc9..54df1e7a 100644 --- a/server/test/definition/set.lua +++ b/server/test/definition/set.lua @@ -43,3 +43,8 @@ TEST [[ _G.<!x!> = 1 print(<?x?>) ]] + +TEST [[ +rawset<!(_G, 'x', 1)!> +print(<?x?>) +]] |