summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-04 16:16:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-04 16:16:49 +0800
commitd165bf61b7f9d004cc670f6d5316096406054d2d (patch)
tree7f38daeeb8d3eb1f488738acbfaaa4d793bed59e
parent4dddd5e97906202f772642486c6e55ae89d67f81 (diff)
downloadlua-language-server-d165bf61b7f9d004cc670f6d5316096406054d2d.zip
换个方法支持object
-rw-r--r--server/src/vm/library.lua12
-rw-r--r--server/src/vm/value.lua14
-rw-r--r--server/src/vm/vm.lua7
3 files changed, 23 insertions, 10 deletions
diff --git a/server/src/vm/library.lua b/server/src/vm/library.lua
index 4545b1b5..65a70219 100644
--- a/server/src/vm/library.lua
+++ b/server/src/vm/library.lua
@@ -1,5 +1,5 @@
-local createValue = require 'vm.value'
-local createFunction = require 'vm.function'
+local createValue
+local createFunction
local CHILD_CACHE = {}
@@ -7,6 +7,10 @@ local buildLibValue
local buildLibChild
function buildLibValue(lib)
+ if not createValue then
+ createValue = require 'vm.value'
+ createFunction = require 'vm.function'
+ end
local tp = lib.type
local value
if tp == 'table' then
@@ -55,6 +59,10 @@ function buildLibValue(lib)
end
function buildLibChild(lib)
+ if not createValue then
+ createValue = require 'vm.value'
+ createFunction = require 'vm.function'
+ end
if CHILD_CACHE[lib] then
return CHILD_CACHE[lib]
end
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 18b92667..a151adc3 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -1,3 +1,6 @@
+local libraryBuilder = require 'vm.library'
+local library = require 'core.library'
+
local function getDefaultSource()
return {
start = 0,
@@ -77,6 +80,15 @@ function mt:setChild(index, value)
return value
end
+function mt:getLibChild(index)
+ local tp = self:getType()
+ local lib = library.object[tp]
+ if lib then
+ local childs = libraryBuilder.child(lib)
+ return childs[index]
+ end
+end
+
function mt:getChild(index, mark)
self:setType('table', 0.5)
local value = self:rawGet(index)
@@ -85,7 +97,7 @@ function mt:getChild(index, mark)
end
local method = self:getMetaMethod('__index')
if not method then
- return nil
+ return self:getLibChild(index)
end
if not mark then
mark = {}
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index dbd2d49a..8c8be4f7 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -335,13 +335,6 @@ end
function mt:createValue(tp, source, literal)
local value = createValue(tp, source, literal)
- local lib = library.object[tp]
- if lib then
- local child = libraryBuilder.child(lib)
- for k, v in pairs(child) do
- value:setChild(k, v)
- end
- end
return value
end