summaryrefslogtreecommitdiff
path: root/server-beta/src/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-25 16:53:16 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-25 16:53:16 +0800
commitc08ce9af7a35be058aafabcb5dd88748aae75282 (patch)
treed00ab5a5bdbb97ade99fb85e78f35db240fd94f5 /server-beta/src/parser
parent9c79e11ff4c7778e7f35d25c62390be13f9d1959 (diff)
downloadlua-language-server-c08ce9af7a35be058aafabcb5dd88748aae75282.zip
rawset
Diffstat (limited to 'server-beta/src/parser')
-rw-r--r--server-beta/src/parser/compile.lua17
-rw-r--r--server-beta/src/parser/guide.lua11
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