diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | .vscode/settings.json | 1 | ||||
-rw-r--r-- | meta/template/builtin.lua | 2 | ||||
-rw-r--r-- | script-beta/config.lua | 1 | ||||
-rw-r--r-- | script-beta/library.lua | 52 |
5 files changed, 56 insertions, 3 deletions
@@ -3,4 +3,5 @@ /bin !*.exe /test/temp.lua - +/meta/* +!/meta/template diff --git a/.vscode/settings.json b/.vscode/settings.json index ecf65735..d8f6e8f5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,7 @@ "3rd", ".vscode", "script", + "meta", ], "Lua.workspace.library": { "E:/Github/test" : true, diff --git a/meta/template/builtin.lua b/meta/template/builtin.lua index 94bdd53f..4f45b1ec 100644 --- a/meta/template/builtin.lua +++ b/meta/template/builtin.lua @@ -6,7 +6,7 @@ ---@class integer: number ---#else ---@alias integer number ----#endif +---#end ---@class thread: any ---@class table: any ---@class file: any diff --git a/script-beta/config.lua b/script-beta/config.lua index 8927f9b1..0544c317 100644 --- a/script-beta/config.lua +++ b/script-beta/config.lua @@ -103,6 +103,7 @@ local ConfigTemplate = { "?/?.lua" }, Array(String)}, special = {{}, Hash(String, String)}, + meta = {'${version} ${language}', String}, }, diagnostics = { enable = {true, Boolean}, diff --git a/script-beta/library.lua b/script-beta/library.lua index 961b6b4c..bbd540cd 100644 --- a/script-beta/library.lua +++ b/script-beta/library.lua @@ -2,6 +2,7 @@ local lni = require 'lni' local fs = require 'bee.filesystem' local config = require 'config' local util = require 'utility' +local lang = require 'language' local m = {} @@ -277,8 +278,55 @@ local function markLibrary(library) end end +local function compileSingleMetaDoc(script) + local middleBuf = {} + middleBuf[#middleBuf+1] = [[ +local COMPILE_BUF = {} +function PUSH(text) + COMPILE_BUF[#COMPILE_BUF+1] = text +end +]] + local last = 1 + for start, lua, finish in script:gmatch '()%-%-%-%#([^\n\r]*)()' do + middleBuf[#middleBuf+1] = ('PUSH [===[%s]===]'):format(script:sub(last, start - 1)) + middleBuf[#middleBuf+1] = lua + last = finish + end + middleBuf[#middleBuf+1] = ('PUSH [===[%s]===]'):format(script:sub(last)) + middleBuf[#middleBuf+1] = 'return table.concat(COMPILE_BUF)' + local middleScript = table.concat(middleBuf, '\n') + local env = setmetatable({}, { __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) + return assert(load(middleScript, middleScript, 't', env))() +end + +local function compileMetaDoc() + local langID = lang.id + local version = config.config.runtime.version + local metaDir = ROOT / 'meta' / config.config.runtime.meta:gsub('%$%{(.-)%}', { + version = version, + language = langID, + }) + if fs.exists(metaDir) then + return + end + fs.create_directory(metaDir) + local templateDir = ROOT / 'meta' / 'template' + for fullpath in templateDir:list_directory() do + local filename = fullpath:filename() + local metaDoc = compileSingleMetaDoc(util.loadFile(fullpath:string())) + util.saveFile((metaDir / filename):string(), metaDoc) + end +end + local function init() - local lang = require 'language' local id = lang.id m.global = util.container() m.library = util.container() @@ -313,6 +361,8 @@ local function init() markLibrary(m.object) markLibrary(m.other) markLibrary(m.custom) + + compileMetaDoc() end function m.reload() |