summaryrefslogtreecommitdiff
path: root/script/vm/getDef.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/getDef.lua')
-rw-r--r--script/vm/getDef.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua
new file mode 100644
index 00000000..11a64421
--- /dev/null
+++ b/script/vm/getDef.lua
@@ -0,0 +1,29 @@
+local util = require 'utility'
+
+---@class vm
+local vm = require 'vm.vm'
+
+local simpleMap = util.switch()
+ : case 'local'
+ : call(function (source, results)
+ results[#results+1] = source
+ end)
+ : case 'getlocal'
+ : case 'setlocal'
+ : call(function (source, results)
+ results[#results+1] = source.node
+ end)
+ : getMap()
+
+function vm.getDefs(source, field)
+ local results = {}
+ local simple = simpleMap[source.type]
+ if simple then
+ simple(source, results)
+ end
+ return results
+end
+
+function vm.getAllDefs(source, field)
+ return vm.getDefs(source, field)
+end