diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-18 21:04:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-18 21:04:39 +0800 |
commit | 1827e053fa17863a7a3632a731540176648242ae (patch) | |
tree | 5302f6e15bfb68f6a1fbc25153883f6d90185bd8 /script-beta/library.lua | |
parent | 34bda3431ecef5fe318d3f9761134db24f9813d2 (diff) | |
download | lua-language-server-1827e053fa17863a7a3632a731540176648242ae.zip |
函数版本预处理
Diffstat (limited to 'script-beta/library.lua')
-rw-r--r-- | script-beta/library.lua | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/script-beta/library.lua b/script-beta/library.lua index ffe016ec..a8c45738 100644 --- a/script-beta/library.lua +++ b/script-beta/library.lua @@ -345,12 +345,22 @@ local function compileSingleMetaDoc(script, metaLang) end middleBuf[#middleBuf+1] = ('PUSH [===[%s]===]'):format(script:sub(last)) local middleScript = table.concat(middleBuf, '\n') + local version, jit + if config.config.runtime.version == 'LuaJIT' then + version = 5.1 + jit = true + else + version = tonumber(config.config.runtime.version:sub(-3)) + jit = false + end local env = setmetatable({ - PUSH = function (text) + VERSION = version, + JIT = jit, + PUSH = function (text) compileBuf[#compileBuf+1] = text end, - DES = function (name) + DES = function (name) local des = metaLang[name] if not des then des = ('Miss locale <%s>'):format(name) @@ -377,16 +387,35 @@ local function compileSingleMetaDoc(script, metaLang) compileBuf[#compileBuf+1] = convertLink(des) compileBuf[#compileBuf+1] = '\n' end, + ALIVE = function (str) + local isAlive + for piece in str:gmatch '[^%,]+' do + if piece:sub(1, 1) == '>' then + local alive = tonumber(piece:sub(2)) + if not alive or version >= alive then + isAlive = true + break + end + elseif piece:sub(1, 1) == '<' then + local alive = tonumber(piece:sub(2)) + if not alive or version <= alive then + isAlive = true + break + end + else + local alive = tonumber(piece) + if not alive or version == alive then + isAlive = true + break + end + end + end + if not isAlive then + compileBuf[#compileBuf+1] = '---@deprecated\n' + end + end, }, { __index = _ENV }) - if config.config.runtime.version == 'LuaJIT' then - env.VERSION = 5.1 - env.JIT = true - else - env.VERSION = tonumber(config.config.runtime.version:sub(-3)) - env.JIT = false - end - util.saveFile((ROOT / 'log' / 'middleScript.lua'):string(), middleScript) assert(load(middleScript, middleScript, 't', env))() |