2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-04-20 20:43:23 +00:00

feat: add processors api

This commit is contained in:
sammyette 2025-04-02 14:47:21 -04:00
parent e4a9e06d2a
commit 155bb69a7f
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD

32
nature/processors.lua Normal file
View File

@ -0,0 +1,32 @@
-- @module hilbish.processors
hilbish.processors = {
list = {}
sorted = {}
}
function hilbish.processors.add(processor)
if not processor.func then
error 'processor is missing function'
end
table.insert(hilbish.processors.list, processor)
table.sort(hilbish.processors.list, function(a, b) return a.priority < b.priority end)
end
--- Run all command processors, in order by priority.
--- It returns the processed command (which may be the same as the passed command)
--- and a boolean which states whether to proceed with command execution.
function hilbish.processors.execute(command)
local continue = true
for _, processor in ipairs(hilbish.processors.list) do
local processed = hilbish.processors.func(command)
if processed.command then command = processed.command end
if not processed.continue then
continue = false
break
end
end
return command, continue
end