Skip to content

system.registerTask

since 1.5.0

Register a Lua Task.

system.registerTask(params)

Parameters

Name Type Required Description
params table yes see the fields below

Fields of params:

  • key (string, 7 chars max): task key
  • name (string or function): task name
  • init (function, optional): handler called on task init
  • done (function, optional): handler called on task stop
  • event (function, optional): handler called at each event
  • wakeup (function, optional): handler called at each loop
  • read (function, optional): optional read handler
  • write (function, optional): optional write handler
  • configure (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 init()
  system.registerTask({
    key = "wf2bg",
    name = "Wingflight [Background]",
    init = taskInit,
    wakeup = taskWakeup,
    event = taskEvent,
  })
end

src/wfsuite/tasks/background.lua:415

local function init()
  system.registerTask({
    key = "rf2bg",
    name = "Rotorflight [Background]",
    init = taskInit,
    wakeup = taskWakeup,
    event = taskEvent,
  })
end

src/rfsuite/tasks/background.lua:208

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

src/rfsuite/main.lua:43