system.registerTask¶
since 1.5.0
Register a Lua Task.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
params |
table | yes | see the fields below |
Fields of params:
key(string, 7 chars max): task keyname(string or function): task nameinit(function, optional): handler called on task initdone(function, optional): handler called on task stopevent(function, optional): handler called at each eventwakeup(function, optional): handler called at each loopread(function, optional): optional read handlerwrite(function, optional): optional write handlerconfigure(function, optional): handler called on task configuration
Returns¶
Nothing.
Examples¶
From the official Ethos documentation
local function taskName()
return "My task name"
end
local function taskInit()
print("Task Init ...")
end
local function taskWakeup()
print("Task Wakeup ...")
end
local function taskEvent(event)
print("Task Event", event)
end
local function init()
system.registerTask({key="LuaTask", name=taskName, init=taskInit, wakeup=taskWakeup, event=taskEvent})
end
return {init=init}
Used in¶
Real-world usage¶
Called 3 times across 3 open-source Ethos Lua projects. A few short excerpts:
local function registerBackgroundTask()
if not system.registerTask then
log:warn("system.registerTask is unavailable")
return
end
system.registerTask({
name = runtime.config.bgTaskName,
key = runtime.config.bgTaskKey,
init = backgroundTask.init,
wakeup = backgroundTask.wakeup,
event = backgroundTask.event,
read = backgroundTask.read,
write = backgroundTask.write
})
end