summaryrefslogtreecommitdiff
path: root/script/vm/value.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-08 20:02:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-08 20:02:49 +0800
commit6ef8cb96f7834c99e998b49a4b8632a784b67e89 (patch)
treed4fdddfe3f098599e1c6ea4766d7544d3a85fee9 /script/vm/value.lua
parent256b37771a9203ab0c27d5690e35d9a1f9185465 (diff)
downloadlua-language-server-6ef8cb96f7834c99e998b49a4b8632a784b67e89.zip
update
Diffstat (limited to 'script/vm/value.lua')
-rw-r--r--script/vm/value.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/script/vm/value.lua b/script/vm/value.lua
new file mode 100644
index 00000000..f2708de1
--- /dev/null
+++ b/script/vm/value.lua
@@ -0,0 +1,42 @@
+local nodeMgr = require 'vm.node'
+
+---@class vm.value-manager
+local m = {}
+
+---@param source parser.object
+---@return boolean|nil
+function m.test(source)
+ local compiler = require 'vm.compiler'
+ local node = compiler.compileNode(source)
+ local hasTrue, hasFalse
+ for n in nodeMgr.eachNode(node) do
+ if n.type == 'boolean' then
+ if n[1] == true then
+ hasTrue = true
+ end
+ if n[1] == false then
+ hasTrue = false
+ end
+ end
+ if n.type == 'nil' then
+ hasFalse = true
+ end
+ if n.type == 'string'
+ or n.type == 'number'
+ or n.type == 'integer'
+ or n.type == 'table'
+ or n.type == 'function' then
+ hasTrue = true
+ end
+ end
+ if hasTrue == hasFalse then
+ return nil
+ end
+ if hasTrue then
+ return true
+ else
+ return false
+ end
+end
+
+return m