summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/library.lua21
-rw-r--r--script-beta/parser/guide.lua29
-rw-r--r--script-beta/vm/guideInterface.lua13
3 files changed, 53 insertions, 10 deletions
diff --git a/script-beta/library.lua b/script-beta/library.lua
index 038e19fa..a1416fb4 100644
--- a/script-beta/library.lua
+++ b/script-beta/library.lua
@@ -258,10 +258,13 @@ end
local function markLibrary(library)
for _, lib in pairs(library) do
lib.library = true
- lib.start = 0
- lib.finish = 0
+ lib.fields = {}
if lib.child then
- markLibrary(lib.child)
+ for _, child in util.sortPairs(lib.child) do
+ table.insert(lib.fields, child)
+ child.library = true
+ child.parent = library
+ end
end
end
end
@@ -269,11 +272,11 @@ end
local function init()
local lang = require 'language'
local id = lang.id
- m.global = util.container()
- m.library = util.container()
- m.object = util.container()
- m.other = util.container()
- m.custom = util.container()
+ m.global = {}
+ m.library = {}
+ m.object = {}
+ m.other = {}
+ m.custom = {}
for libPath in (ROOT / 'libs'):list_directory() do
local libName = libPath:filename():string()
@@ -281,7 +284,7 @@ local function init()
local libs
local buf = util.loadFile(path:string())
if buf then
- libs = util.container()
+ libs = {}
xpcall(lni, log.error, buf, path:string(), {libs})
fix(libs)
end
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 5fdb1e25..b16e7dcf 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -597,6 +597,9 @@ function m.getKeyName(obj)
end
function m.getSimpleName(obj)
+ if obj.library then
+ return ('s|%s'):format(obj.name)
+ end
if obj.type == 'call' then
local key = obj.args[2]
return m.getKeyName(key)
@@ -604,6 +607,8 @@ function m.getSimpleName(obj)
return ('t|%p'):format(obj)
elseif obj.type == 'select' then
return ('v|%p'):format(obj)
+ elseif obj.type == 'string' then
+ return ('z|%p'):format(obj)
end
return m.getKeyName(obj)
end
@@ -870,6 +875,9 @@ local function buildSimpleList(obj, max)
if i == limit then
return nil
end
+ while cur.type == 'paren' do
+ cur = cur.exp
+ end
if cur.type == 'setfield'
or cur.type == 'getfield'
or cur.type == 'setmethod'
@@ -898,6 +906,9 @@ local function buildSimpleList(obj, max)
elseif cur.type == 'select' then
list[i] = cur
break
+ elseif cur.type == 'string' then
+ list[i] = cur
+ break
elseif cur.type == 'function'
or cur.type == 'main' then
break
@@ -1142,6 +1153,22 @@ function m.checkSameSimpleInValueOfCallMetaTable(status, call, start, queue)
end
end
+function m.checkSameSimpleInSpecialBranch(status, obj, start, queue)
+ if not status.interface.index then
+ return
+ end
+ local results = status.interface.index(obj)
+ if not results then
+ return
+ end
+ for _, res in ipairs(results) do
+ queue[#queue+1] = {
+ obj = res,
+ start = start + 1,
+ }
+ end
+end
+
function m.checkSameSimpleInArg1OfSetMetaTable(status, obj, start, queue)
local args = obj.parent
if not args or args.type ~= 'callargs' then
@@ -1610,6 +1637,8 @@ function m.checkSameSimple(status, simple, data, mode, results, queue)
m.checkSameSimpleInArg1OfSetMetaTable(status, ref, i, queue)
-- 检查自己作为 setmetatable 调用的情况
m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, queue)
+ -- 检查自己是特殊分支的情况
+ m.checkSameSimpleInSpecialBranch(status, ref, i, queue)
if cmode ~= 'def' then
-- 检查形如 { a = f } 的情况
m.checkSameSimpleAsTableField(status, ref, i, queue)
diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua
index 3ddb86ea..b21aee79 100644
--- a/script-beta/vm/guideInterface.lua
+++ b/script-beta/vm/guideInterface.lua
@@ -3,6 +3,7 @@ local files = require 'files'
local ws = require 'workspace'
local guide = require 'parser.guide'
local await = require 'await'
+local library = require 'library'
local m = {}
@@ -65,11 +66,12 @@ vm.interface = {}
vm.interface.searchLevel = 0
function vm.interface.call(func, args, index)
- await.delay()
if func.special == 'require' and index == 1 then
+ await.delay()
return m.require(args, index)
end
if func.special == 'dofile' then
+ await.delay()
return m.dofile(args, index)
end
end
@@ -84,6 +86,15 @@ function vm.interface.link(uri)
return vm.getLinksTo(uri)
end
+function vm.interface.index(obj)
+ local tp = obj.type
+ local lib = library.object[tp]
+ if not lib then
+ return nil
+ end
+ return lib.fields
+end
+
function vm.interface.cache(source, mode)
await.delay()
local cache = vm.getCache('cache')