From 3771e70b48e9a088cbdc11a8b952d525eea1e7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 8 Apr 2022 13:12:31 +0800 Subject: cleanup --- script/vm/library.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 script/vm/library.lua (limited to 'script/vm/library.lua') diff --git a/script/vm/library.lua b/script/vm/library.lua new file mode 100644 index 00000000..1a8d8ffd --- /dev/null +++ b/script/vm/library.lua @@ -0,0 +1,36 @@ +---@class vm +local vm = require 'vm.vm' + +function vm.getLibraryName(source) + if source.special then + return source.special + end + local defs = vm.getDefs(source) + for _, def in ipairs(defs) do + if def.special then + return def.special + end + end + return nil +end + +local globalLibraryNames = { + 'arg', 'assert', 'error', '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 -- cgit v1.2.3