Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
tutorial:autorun_options [2018/09/06 08:34]
payonel [Boot Scripts (/boot/)]
tutorial:autorun_options [2018/09/06 17:32]
payonel
Line 117: Line 117:
  
 There may not be a fully initialized io, there may be an incomplete init process, there may even be incomplete lua libraries. Depending on the code you execute in your boot script, you may even unintentionally circumvent the event dispatching system causing the system to miss component updates. Yes, there is a lot that the boot process is responsible for. There may not be a fully initialized io, there may be an incomplete init process, there may even be incomplete lua libraries. Depending on the code you execute in your boot script, you may even unintentionally circumvent the event dispatching system causing the system to miss component updates. Yes, there is a lot that the boot process is responsible for.
 +
 +With all of that said, here are a couple examples of `/boot` scripts that would work safely now and for the foreseable future. Prefix your script filename 99_ so that it loads at the end of the boot sequence.
 +
 +```lua
 +local event = require("​event"​)
 +-- the init signal is fired by the boot process, means the system is ready
 +event.listen("​init",​ function()
 +  local thread = require("​thread"​)
 +  thread.create(function()
 +    --[[
 +      your custom service code as a background thread
 +    ]]--
 +  end):​detach()
 +end)
 +```
 +
 +```lua
 +local event = require("​event"​)
 +event.listen("​component_added",​ function(...)
 +  --[[
 +    your custom service code as a background event responder
 +  ]]--
 +end)
 +```
  
 Contents Contents