summaryrefslogtreecommitdiff
path: root/script/vm/value.lua
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2022-03-12 03:58:08 +0800
committersumneko <sumneko@hotmail.com>2022-03-12 03:58:08 +0800
commita4baf8a43b0b25414d8fe08cb898e150d420e705 (patch)
tree58d562463229b5a42659027e6d47bafab3005e8b /script/vm/value.lua
parent7baee6a3d54dc7cb94fb9db95d01244a17f126f6 (diff)
downloadlua-language-server-a4baf8a43b0b25414d8fe08cb898e150d420e705.zip
update
Diffstat (limited to 'script/vm/value.lua')
-rw-r--r--script/vm/value.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/script/vm/value.lua b/script/vm/value.lua
index 43c5d4bd..549cee02 100644
--- a/script/vm/value.lua
+++ b/script/vm/value.lua
@@ -191,4 +191,37 @@ function m.getBoolean(v)
return result
end
+---@param v vm.node
+---@return table<any, boolean>?
+function m.getLiterals(v)
+ local map
+ local node = compiler.compileNode(v)
+ for n in nodeMgr.eachNode(node) do
+ local literal
+ if n.type == 'boolean'
+ or n.type == 'string'
+ or n.type == 'number'
+ or n.type == 'integer' then
+ literal = n[1]
+ end
+ if n.type == 'global' and n.cate == 'type' then
+ if n.name == 'true' then
+ literal = true
+ elseif n.name == 'false' then
+ literal = false
+ end
+ end
+ if n.type == 'doc.type.integer' then
+ literal = n[1]
+ end
+ if literal ~= nil then
+ if not map then
+ map = {}
+ end
+ map[literal] = true
+ end
+ end
+ return map
+end
+
return m