diff options
Diffstat (limited to 'server-beta/src/parser')
-rw-r--r-- | server-beta/src/parser/compile.lua | 17 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 11 |
2 files changed, 21 insertions, 7 deletions
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua index 457af42c..45fd808b 100644 --- a/server-beta/src/parser/compile.lua +++ b/server-beta/src/parser/compile.lua @@ -3,7 +3,7 @@ local type = type _ENV = nil -local pushError, Root, Compile, CompileBlock, Cache, Block, GoToTag +local pushError, Root, Compile, CompileBlock, Cache, Block, GoToTag, Version, ENVMode local vmMap = { ['nil'] = function (obj) @@ -475,6 +475,15 @@ local vmMap = { Block = obj Root[#Root+1] = obj local id = #Root + if ENVMode == '_ENV' then + Compile({ + type = 'local', + start = 0, + finish = 0, + effect = 0, + [1] = '_ENV', + }, id) + end CompileBlock(obj, id) Block = nil return id @@ -584,6 +593,12 @@ return function (self, lua, mode, version) end pushError = state.pushError Root = state.root + Version = version + if version == 'Lua 5.1' or version == 'LuaJIT' then + ENVMode = 'fenv' + else + ENVMode = '_ENV' + end Cache = {} GoToTag = {} if type(state.ast) == 'table' then diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index bd7f9150..7925abe2 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -1,6 +1,4 @@ local error = error -local utf8Len = utf8.len -local utf8Offset = utf8.offset local type = type _ENV = nil @@ -199,18 +197,19 @@ end --- 遍历所有某种类型的source function m.eachSourceOf(root, types, callback) if type(types) == 'string' then - types = {[types] = true} + types = {[types] = callback} elseif type(types) == 'table' then for i = 1, #types do - types[types[i]] = true + types[types[i]] = callback end else return end for i = 1, #root do local source = root[i] - if types[source.type] then - callback(source) + local f = types[source.type] + if f then + f(source) end end end |