summaryrefslogtreecommitdiff
path: root/script/vm/getLibrary.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
commit4ca61ec457822dd14966afa0752340ae8ce180a1 (patch)
treeae8adb1ad82c717868e551e699fd3cf3bb290089 /script/vm/getLibrary.lua
parentc63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff)
downloadlua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip
no longer beta
Diffstat (limited to 'script/vm/getLibrary.lua')
-rw-r--r--script/vm/getLibrary.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/script/vm/getLibrary.lua b/script/vm/getLibrary.lua
new file mode 100644
index 00000000..5803a73b
--- /dev/null
+++ b/script/vm/getLibrary.lua
@@ -0,0 +1,32 @@
+local vm = require 'vm.vm'
+
+function vm.getLibraryName(source, deep)
+ local defs = vm.getDefs(source, deep)
+ for _, def in ipairs(defs) do
+ if def.special then
+ return def.special
+ end
+ end
+ return nil
+end
+
+local globalLibraryNames = {
+ 'arg', 'assert', 'collectgarbage', 'dofile', '_G', 'getfenv',
+ 'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring',
+ 'module', 'next', 'pairs', 'pcall', 'print', 'rawequal',
+ 'rawget', 'rawlen', 'rawset', 'select', 'setfenv',
+ 'setmetatable', 'tonumber', 'tostring', 'type', '_VERSION',
+ 'warn', 'xpcall', 'require', 'unpack', 'bit32', 'coroutine',
+ 'debug', 'io', 'math', 'os', 'package', 'string', 'table',
+ 'utf8',
+}
+local globalLibraryNamesMap
+function vm.isGlobalLibraryName(name)
+ if not globalLibraryNamesMap then
+ globalLibraryNamesMap = {}
+ for _, v in ipairs(globalLibraryNames) do
+ globalLibraryNamesMap[v] = true
+ end
+ end
+ return globalLibraryNamesMap[name] or false
+end