startup API

For understanding the structure of these APIs, please consult startup concepts.

Standard APIs

Todo

Should we put into place a complete cross-version environment, or instead setup the appropriate environment for the current Lua version?

The following utilities are available as described in the Lua 5.3 manual:

_G
_VERSION

assert
error
getmetatable
ipairs
load
next
pairs
pcall
rawequal
rawget
rawlen
rawset
select
setmetatable
tonumber
tostring
type
xpcall

coroutine.create
coroutine.resume
coroutine.running
coroutine.status
coroutine.wrap
coroutine.yield

math.abs
math.acos
math.asin
math.atan
math.ceil
math.cos
math.deg
math.exp
math.floor
math.fmod
math.huge
math.log
math.max
math.min
math.modf
math.pi
math.rad
math.random
math.randomseed
math.sin
math.sqrt
math.tan

os.clock
os.date
os.difftime
os.time

string.byte
string.char
string.dump
string.find
string.format
string.gmatch
string.gsub
string.len
string.lower
string.match
string.rep
string.reverse
string.sub
string.upper

table.concat
table.insert
table.pack
table.remove
table.sort
table.unpack

On certain conditions, the debug utilities might be available:

debug.gethook
debug.getinfo
debug.getlocal
debug.getmetatable
debug.getupvalue
debug.getuservalue
debug.sethook
debug.setlocal
debug.setmetatable
debug.setupvalue
debug.setuservalue
debug.traceback
debug.upvalueid
debug.upvaluejoin

On Lua 5.3 if available, the following utilities are also available:

coroutine.isyieldable

string.pack
string.unpack
string.packsize

table.move

math.maxinteger
math.mininteger
math.tointeger
math.type
math.ult

utf8.char
utf8.charpattern
utf8.codes
utf8.codepoint
utf8.len
utf8.offset

Todo

Check if we have access to debug, in what circumstances, and so on.

Event-based component abstraction API

startup.pull(timeout_sec)

Pull the next event out of the queue, while waiting for timeout_sec seconds at a maximum (fractional seconds are allowed and will be fulfilled within the underlying platform’s capabilities).

If timeout_sec is lesser or equal to 0, the function will return immediately with an event if available, or with nil otherwise.

If a timeout has occurred, the returned event will be nil.

Parameters

timeout_sec (number) – Timeout in seconds.

Returns

The next event in the queue or nil.

Return type

Event

startup.call(id, name, ...)

Call the method identified by its name name on the component which the identifier is id with the given arguments.

Returns the raw return value of the method, or nil if the method doesn’t exist on the given peripheral.

Parameters
  • id (number) – Identifier of the component of which to call the method.

  • name (string) – The name of the method to call.

class startup.Event

An event on the component abstraction, as returned by pull(). Note that attributes include, but are not limited to the list given below.

type: string

The event type:

  • "attach" if a new component is attached to a given bus.

  • "detach" if a component is detached from a given bus.

  • "other" if the component has emitted an event.

id: number

The numeric identifier of the component that has been attached, detached, or which has emitted the event.

parent: number

Only for attach and detach events.

The numeric identifier of the bus on which the component has been attached, or from which the component has been detached.

methods: sequence

Only for attach events.

The sequence containing the method names as declared by the bus or the component itself.