x.onrun - Execution Hook

x.onrun is called when Lua starts/reboots. This function has no timeout limit, and can house long-running Lua functions.

If the function returns, the function is called again after a one second delay.

Caution

Within the loop, use the expression while tools.run() do, rather than while true do - this will provide a graceful closure when Lua is rebooted.

Example

-- Simple SNMP Trap rx that doesn't use a channel
function myservercode()
 local u=socket.new("udp")
 u:open(162)
 while tools.run() do
  local n,rx=socket.select(500,{u})
  if rx[u] then
   local b,ip = u:recv()
   b=snmp.decode(b,ip)
   if b~="" then mem.write(4,"TRAP:"..b.."\r\n") end
  end
 end
 u:close()
end

x.onrun=myservercode