Starting a Script Automatically

To start Lua automatically when the receiver boots, add a file named "autoexec.lua" to the root directory of the lua script package. This script will be executed when the receiver starts up. To run other scripts from the autoexec.lua script, use the dofile Lua command as shown in the example below.

Here is the content of an example hello.lua script:

Person1 = arg[1]

Person2 = arg[2]

print(string.format("%s says hello to %s",Person1,Person2))

 

Here is the content of an example autoexec.lua script:

arg[1] = "Alice"

arg[2] = "Bob"

dofile("hello.lua")

The autoexec.lua script sets up the command line arguments for the hello.lua script and then runs the script.

 

Here is the example in action:

log luastatus onchanged

<OK

[COM1]<LUASTATUS COM1 0 87.5 UNKNOWN 0 0.614 02444020 afcc 32768

<     0 "autoexec.lua" COMPLETED

[COM1]

log luaoutput onchanged

<OK

[COM1]<LUAOUTPUT 0 0.593

<     1 0 STDOUT "Alice says hello to Bob"

[COM1]saveconfig

<OK
[COM1]

reset

<OK

[COM1]

[COM1]<LUASTATUS COM1 0 13.0 UNKNOWN 0 1.234 02440000 afcc 32768

<     0 "autoexec.lua" COMPLETED

[COM1]<LUAOUTPUT 0 1.151

<     1 0 STDOUT "Alice says hello to Bob"

[COM1]

log luafilelist

<OK

[COM1]<LUAFILELIST COM1 1 84.5 UNKNOWN 0 32.000 02444020 b447 32768

<     55 20180613 105553 "/lua/autoexec.lua"

<LUAFILELIST COM1 0 87.5 UNKNOWN 0 32.000 02444020 b447 32768

<     97 20180613 105502 "/lua/hello.lua"

[COM1]