diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-01-09 17:12:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-01-09 17:12:54 +0800 |
commit | 73244793bda51290b1028ab1f764867f33cabbc5 (patch) | |
tree | 5592fbf14f60016270dcca75190508ff89a3213f /script-beta/vm/getClass.lua | |
parent | a6148c4a1488525c9ddc60c3769479642f2b3c9d (diff) | |
download | lua-language-server-73244793bda51290b1028ab1f764867f33cabbc5.zip |
整理代码
Diffstat (limited to 'script-beta/vm/getClass.lua')
-rw-r--r-- | script-beta/vm/getClass.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua new file mode 100644 index 00000000..f1a50568 --- /dev/null +++ b/script-beta/vm/getClass.lua @@ -0,0 +1,28 @@ +local vm = require 'vm.vm' + +local function getClass(source, deep) + if deep > 3 then + return nil + end + local classes = {} + vm.eachField(source, function (src) + local key = vm.getKeyName(src) + local lkey = key:lower() + if lkey == 's|type' + or lkey == 's|__name' + or lkey == 's|name' + or lkey == 's|class' then + if src.value and src.value.type == 'string' then + classes[#classes+1] = src.value[1] + end + end + end) + if #classes == 0 then + return nil + end + return vm.mergeTypeViews(table.unpack(classes)) +end + +function vm.getClass(source) + return getClass(source, 1) +end |