commit 4363fcf9907fdb9a14d0842b35f227176368251c
parent 2818a7ed6561fcf8ba0a81f3c5411ef083a16a3e
Author: tms <nemi@skaut.cz>
Date: Thu, 10 Jun 2021 13:49:38 +0200
Add userdata table which is passed between hooks
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/trun.lua b/trun.lua
@@ -10,6 +10,7 @@ local name = arg[2] or 'trun'
local handlerPath = os.getenv('CONFIG') .. '/trun/?.lua'
package.path = package.path .. ';' .. handlerPath
local handler = require(handlerName)
+local userdata = {}
-- status dir
local status_dir = os.getenv('HOME') .. '/.cache/trun'
@@ -33,7 +34,7 @@ local signal = require 'posix.signal'
local function cleanup()
os.execute('rm ' .. status_file)
if handler.onEnd then
- handler.onEnd()
+ handler.onEnd(userdata)
end
end
@@ -59,13 +60,10 @@ local function updateFile(output)
file:write(output)
end
file:close()
- if handler.onUpdate then
- handler.onUpdate()
- end
end
if handler.onStart then
- handler.onStart()
+ handler.onStart(userdata)
end
local lastStatus
@@ -73,9 +71,12 @@ for line in io.lines() do
io.stdout:write(line, '\n')
lastStatus = status
- status = handler.handle(line)
+ status = handler.handle(line, userdata)
if status and status ~= lastStatus then
updateFile(status)
+ if handler.onUpdate then
+ handler.onUpdate(line, status, userdata)
+ end
end
end