Added basalt.onEvent(event, callback)

Added basalt.removeEvent(eventcallback)
basalt.triggerEvent(event, ...)

Fixed a event is nil error in Container.lua
This commit is contained in:
Robert Jelic
2025-09-02 12:24:30 +02:00
parent d2d5f8c3ae
commit f10413dddb
5 changed files with 132 additions and 14 deletions

View File

@@ -1,24 +1,49 @@
local markdown = require("tools/markdown")
local function ensureDirectory(path)
local dir = path:match("(.*)/[^/]*$")
if dir then
os.execute('mkdir -p "' .. dir .. '"')
local oldPath = package.path
local scriptSource = debug.getinfo(1, "S").source
local scriptDir = nil
if scriptSource and scriptSource:sub(1,1) == "@" then
local scriptPath = scriptSource:sub(2)
scriptDir = scriptPath:match("^(.*)[/\\]") or "."
else
scriptDir = "."
end
local parserSrc = scriptDir .. "/BasaltDoc/ldoc-markdown-parser/src/"
package.path = package.path .. ";" .. parserSrc .. "?.lua;" .. parserSrc .. "?/init.lua"
local ok, parser = pcall(require, "parser.init")
local ioAdaptor = require("tools.io")
package.path = oldPath
if not ok or not parser then
-- try dofile fallback
local initPath = parserSrc .. "/parser/init.lua"
local ok2, module = pcall(dofile, initPath)
if ok2 and module then
parser = module
else
error("Failed to load parser.init via require and dofile (tried: "..tostring(initPath)..")")
end
end
local function processFile(inputFile)
local parsed = markdown.parseFile(inputFile)
local md = markdown.makeMarkdown(parsed)
local content = ioAdaptor.readFile(inputFile)
if not content then
io.stderr:write("Failed to read: " .. tostring(inputFile) .. "\n")
return
end
local commentBlocks = parser.extractComments(content)
local md = parser.generateMarkdown(commentBlocks)
local outputFile = "build_docs/docs/references/" .. inputFile:match("^src/(.+)"):gsub("%.lua$", "")
ensureDirectory(outputFile)
markdown.saveToFile(outputFile, md)
ioAdaptor.ensureDirectory(outputFile)
ioAdaptor.writeFile(outputFile .. ".md", md)
end
for file in io.popen('find "src" -type f -name "*.lua"'):lines() do
local files = ioAdaptor.listFiles("src", "*.lua")
for _, file in ipairs(files) do
if not file:match("LuaLS.lua$") then
processFile(file)
end