summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-24 16:40:22 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-24 16:40:22 +0800
commitfb736f9479b66838da46fc4c002360a1a90761a4 (patch)
tree3acc2bcf2f0e4d8e84c27a040826759e37667f0c /server
parentcdb3b46b433a52f1533ce432b2337527df1b443e (diff)
downloadlua-language-server-fb736f9479b66838da46fc4c002360a1a90761a4.zip
value单独拆成一个类
Diffstat (limited to 'server')
-rw-r--r--server/src/core/value.lua22
-rw-r--r--server/src/core/vm.lua15
2 files changed, 24 insertions, 13 deletions
diff --git a/server/src/core/value.lua b/server/src/core/value.lua
new file mode 100644
index 00000000..2285738b
--- /dev/null
+++ b/server/src/core/value.lua
@@ -0,0 +1,22 @@
+local DefaultSource = { start = 0, finish = 0 }
+
+local mt = {}
+mt.__index = mt
+mt.type = 'value'
+
+return function (tp, uri, source, value)
+ if tp == '...' then
+ error('Value type cant be ...')
+ end
+ -- TODO lib里的多类型
+ if type(tp) == 'table' then
+ tp = tp[1]
+ end
+ local self = setmetatable({
+ type = tp,
+ source = source or DefaultSource,
+ value = value,
+ uri = uri,
+ }, mt)
+ return self
+end
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 8c27c13a..965a0bec 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -1,5 +1,6 @@
local env = require 'core.env'
local library = require 'core.library'
+local createValue = require 'core.value'
local DefaultSource = { start = 0, finish = 0 }
local GlobalChild
@@ -781,19 +782,7 @@ function mt:inference(value, type)
end
function mt:createValue(tp, source, v)
- if tp == '...' then
- error('Value type cant be ...')
- end
- -- TODO lib里的多类型
- if type(tp) == 'table' then
- tp = tp[1]
- end
- local value = {
- type = tp,
- source = source or DefaultSource,
- value = v,
- uri = self.uri,
- }
+ local value = createValue(tp, self.uri, source, v)
local lib = library.object[tp]
if lib then
self:getLibChild(value, lib, 'object')