Bururu Modding docs

Lua API reference

The Lua API of mod API 0.12. It may still change before 1.0. Every mod's Lua sees these tables; bururu mod types writes the same API as types/bururu.d.lua for an editor. How to use them: When to use Lua, A mod in Lua.

Tables

Table What it holds
bururu Registration of handlers, this mod's state, exports between mods.
hook Hook points between a game mod and its add-ons.
feel Feels: one-shots, layers and motor levels.
rules The data rules of the instance.
Frame The frame in on_frame: f:light(...), f:trigger(...) and the rest change it after the tables and overlays.
out Timed overlays of lights.json.
sensor Asks and queries to the declared sensors.
channels Vocabulary channels.
data The mod's data tables.
status Live facts and toasts.
setup Setup items on the Controller page.
log The log, under the log budget.
kit General helpers.
gomath Math functions: rounding, min and max, trigonometry.
bit Bit operations on integers up to 2^53.
sensors The visible snapshots of the declared sensors, by id; read-only.
Table shapes the tables the API hands out or takes: the tick context, the pad, options

The bururu table

Registration of handlers, this mod's state, exports between mods.

bururu.state

A value of type table. This mod's own table for the session.

bururu.on

bururu.on(selector, fn)

Run fn for every input the selector matches (as a rule's "on").

Parameter Type What it is
selector string "<sensor>:<name>", "<sensor>:*", "<sensor>:change" or "binds:action=<name>"
fn fun(ev: Event) the handler

bururu.facts

bururu.facts(fn)

Tell Bururu at the end of each read phase whether the player is in control.

Parameter Type What it is
fn fun(t: Tick): Facts returns active, menu and context

bururu.before_screen

bururu.before_screen(fn)

Set the screen asks before Bururu takes the screen's state.

Parameter Type What it is
fn fun(t: Tick, active: boolean) the handler

bururu.after_screen

bururu.after_screen(fn)

Run after the screen's inputs of the tick (the fast ask).

Parameter Type What it is
fn fun(t: Tick) the handler

bururu.on_pad

bururu.on_pad(fn)

Run at the start of the drive phase, before the actions of the tick.

Parameter Type What it is
fn fun(t: Tick) the handler

bururu.on_tick

bururu.on_tick(fn)

Run on every active tick with haptics on; layers are set here.

Parameter Type What it is
fn fun(t: Tick) the handler

bururu.on_idle

bururu.on_idle(fn)

Run on ticks without driving; t.reason is "idle" or "haptics_off", and "restart" once when a session restart keeps the game.

Parameter Type What it is
fn fun(t: Tick) the handler

bururu.before_frame

bururu.before_frame(fn)

Compute state the light tables read, before the tables run.

Parameter Type What it is
fn fun(t: Tick) the handler

bururu.on_frame

bururu.on_frame(fn)

Change the frame after the tables and overlays.

Parameter Type What it is
fn fun(t: Tick, f: Frame) the handler

bururu.on_reload

bururu.on_reload(fn)

Take over the state of the version a hot reload replaced.

Parameter Type What it is
fn fun(old_state: table) gets a data-only copy of the old bururu.state

bururu.export

bururu.export(name, fn)

Offer a function to the other mods of the instance.

Parameter Type What it is
name string the export's name
fn function the function

bururu.import

bururu.import(mod_id, name) -> fn

A function another mod of the instance exported; it is looked up at each call.

Parameter Type What it is
mod_id string the exporting mod
name string the export's name
Result Type What it is
fn function calls the export

The hook table

Hook points between a game mod and its add-ons.

hook.add

hook.add(point, handler_id, fn)

Attach a handler to a hook point another mod runs.

Parameter Type What it is
point string "<mod>/<name>@<n>"
handler_id string "<your mod>/<name>", unique per point
fn fun(payload: table) changes the copy of the payload it gets

hook.remove

hook.remove(point, handler_id)

Detach a handler from a hook point.

Parameter Type What it is
point string "<mod>/<name>@<n>"
handler_id string the id hook.add gave

hook.run

hook.run(point, payload) -> payload

Run one of this mod's declared hook points; returns the payload after its handlers.

Parameter Type What it is
point string "<name>@<n>" as the manifest declares it
payload table plain data, at most 4 deep and 256 entries
Result Type What it is
payload table the payload after the handlers, or the same table when none ran

The feel table

Feels: one-shots, layers and motor levels.

feel.play

feel.play(name, opts)

Play a one-shot feel, on the controller in your hands or the one opts names.

Parameter Type What it is
name string a feel name, plain or "<mod>/<name>"
opts FeelPlayOpts? how it plays

feel.layer

feel.layer(key, name, level, opts)

Hold a continuous feel this tick at a level; a key missing next tick glides out.

Parameter Type What it is
key string the layer key: its identity and mix order
name string? the feel; nil with opts.rumble plays on the motors only
level number 0..1
opts FeelLayerOpts? how it plays

feel.rumble

feel.rumble(key, rumble_key, level, opts)

Hold a motors-only level this tick.

Parameter Type What it is
key string the layer key
rumble_key string the rumble table entry
level number 0..1
opts FeelRumbleOpts? side and gain

feel.exists

feel.exists(name) -> exists

Whether a feel of that name resolves for this mod.

Parameter Type What it is
name string a feel name
Result Type What it is
exists boolean

The rules table

The data rules of the instance.

rules.stage

rules.stage(name)

Evaluate a layer stage of the data rules now.

Parameter Type What it is
name string the stage

The frame (on_frame's f)

The frame in on_frame: f:light(...), f:trigger(...) and the rest change it after the tables and overlays.

Frame:light

f:light(key, bright)

Set the lightbar to a colour of the colour table.

Parameter Type What it is
key string the colour table key
bright number? 0..1 of the player's brightness; nil: 1

Frame:light_rgb

f:light_rgb(rgb, key, bright)

Set the lightbar to an explicit colour.

Parameter Type What it is
rgb integer[] {r, g, b}, 0..255 each
key string? the key the window shows
bright number? 0..1 of the player's brightness; nil: 1

Frame:trigger

f:trigger(side, key)

Set a trigger to an effect of the trigger table.

Parameter Type What it is
side string "l2", "r2" or "both"
key string? the trigger table key; nil: none

Frame:trigger_raw

f:trigger_raw(side, mode, values)

Set a trigger to a raw effect.

Parameter Type What it is
side string "l2", "r2" or "both"
mode string a trigger mode: OFF, FEEDBACK, WEAPON, VIBRATION, ...
values integer[] the mode's values

Frame:leds

f:leds(count)

Light the player LEDs.

Parameter Type What it is
count integer 0 (off) to 5

Frame:mic

f:mic(mode)

Set the mic LED.

Parameter Type What it is
mode string "on", "pulse" or "off"

Frame:final

f:final()

No overlays this frame.

Frame:slot

f:slot(n) -> frame

The frame of controller n (t.slots[n]), with the same methods. The tables and overlays set only the frame of the controller in your hands; another controller that gets no frame rests.

Parameter Type What it is
n integer the slot, from 1
Result Type What it is
frame Frame

Frame:player

f:player(n) -> frame

The frame of player n's controller: Controller n while the facts say two or more people play and two or more controllers are connected (a player with no controller connected gets none), else the controller in your hands.

Parameter Type What it is
n integer the player, from 1
Result Type What it is
frame Frame

The out table

Timed overlays of lights.json.

out.overlay

out.overlay(id, opts)

Start a timed overlay of lights.json.

Parameter Type What it is
id string the overlay id
opts table? options, plain data

out.overlay_stop

out.overlay_stop(id)

Stop a running overlay.

Parameter Type What it is
id string the overlay id

The sensor table

Asks and queries to the declared sensors.

sensor.set

sensor.set(id, params)

Ask a sensor to change its parameters (screen on, fast mode, or any setting the sensor takes).

Parameter Type What it is
id string the sensor id
params table parameters, plain data

sensor.call

sensor.call(id, method, ...) -> result

A one-off ask of a sensor, or a query that answers at once, such as the newest line of a log.

Parameter Type What it is
id string the sensor id
method string the method
... any its arguments, plain data
Result Type What it is
result any a query's answer; nothing for an ask

The channels table

Vocabulary channels.

channels.set

channels.set(name, value)

Publish a vocabulary channel.

Parameter Type What it is
name string the channel: "racing.rpm"
value any a number, boolean, string or per-wheel array

The data table

The mod's data tables.

data.get

data.get(name) -> table

A data table, data/<name>.json after patches; a fresh copy each call.

Parameter Type What it is
name string the table's name
Result Type What it is
table table

The status table

Live facts and toasts.

status.fact

status.fact(id, value)

Set a live fact the settings schema declares (on the mod's first page).

Parameter Type What it is
id string the fact id
value any a number, boolean or string

status.notice

status.notice(text)

Show a toast (rate-limited).

Parameter Type What it is
text string the words

The setup table

Setup items on the Controller page.

setup.item

setup.item(id, state, text)

Set a setup item on the Controller page.

Parameter Type What it is
id string the item id
state string "ok", "warn" or "fail"
text string? the words

The log table

The log, under the log budget.

log.info

log.info(fmt, ...)

Write a log line, formatted as string.format does, under the log budget.

Parameter Type What it is
fmt string the line or a format
... any the format's values

log.warn

log.warn(fmt, ...)

Write a warning line, formatted as string.format does.

Parameter Type What it is
fmt string the line or a format
... any the format's values

log.once

log.once(key, fmt, ...)

Write a line once per session for key.

Parameter Type What it is
key string the line's key
fmt string the line or a format
... any the format's values

The kit table

General helpers.

kit.null

A value of type userdata. The JSON null in inputs, so presence tests see a JSON null.

kit.fresh

kit.fresh(tracked, now, ms) -> fresh

tracked.ok and now - tracked.at < ms milliseconds (hud.Tracked.Fresh).

Parameter Type What it is
tracked table? {value, ok, at}
now number ns since session start
ms number the age limit
Result Type What it is
fresh boolean

kit.has

kit.has(x) -> has

x is present: neither nil nor kit.null.

Parameter Type What it is
x any
Result Type What it is
has boolean

kit.blink(unix_ms, hz) -> on

On for the first half of each period at hz (always on at 0).

Parameter Type What it is
unix_ms number t.unix_ms
hz number blinks per second
Result Type What it is
on boolean

kit.breathe

kit.breathe(unix_ms, hz, low) -> level

A brightness between low and 1 that swells at hz.

Parameter Type What it is
unix_ms number t.unix_ms
hz number swells per second
low number the lowest value
Result Type What it is
level number

kit.seconds

kit.seconds(unix_ms) -> s

unix_ms in seconds.

Parameter Type What it is
unix_ms number t.unix_ms
Result Type What it is
s number

kit.mix

kit.mix(a, b, f) -> rgb

From colour a to colour b as f goes from 0 to 1, rounded to whole numbers.

Parameter Type What it is
a integer[] {r, g, b}
b integer[] {r, g, b}
f number 0..1
Result Type What it is
rgb integer[] {r, g, b}

kit.clamp

kit.clamp(x, lo, hi) -> x

x within lo and hi.

Parameter Type What it is
x number
lo number
hi number
Result Type What it is
x number

kit.same

kit.same(a, b) -> same

Deep equality of plain values.

Parameter Type What it is
a any
b any
Result Type What it is
same boolean

kit.has_prefix

kit.has_prefix(s, p) -> has

s starts with p (plain text, no patterns).

Parameter Type What it is
s string
p string
Result Type What it is
has boolean

kit.has_suffix

kit.has_suffix(s, p) -> has

s ends with p (plain text).

Parameter Type What it is
s string
p string
Result Type What it is
has boolean

kit.contains

kit.contains(s, sub) -> has

s holds sub (plain text).

Parameter Type What it is
s string
sub string
Result Type What it is
has boolean

kit.lower

kit.lower(s) -> lower

s in lower case.

Parameter Type What it is
s string
Result Type What it is
lower string

The gomath table

Math functions: rounding, min and max, trigonometry.

gomath.inf

A value of type number. Positive infinity.

gomath.nan

A value of type number. Not a number.

gomath.pi

A value of type number. Pi.

gomath.abs

gomath.abs(x) -> y

x without its sign.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.floor

gomath.floor(x) -> y

x rounded down.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.ceil

gomath.ceil(x) -> y

x rounded up.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.trunc

gomath.trunc(x) -> y

x without its fraction, toward zero.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.sqrt

gomath.sqrt(x) -> y

The square root of x.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.sin

gomath.sin(x) -> y

The sine of x, in radians.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.cos

gomath.cos(x) -> y

The cosine of x, in radians.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.tan

gomath.tan(x) -> y

The tangent of x, in radians.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.exp

gomath.exp(x) -> y

e to the power x.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.log

gomath.log(x) -> y

The natural logarithm of x.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.tanh

gomath.tanh(x) -> y

The hyperbolic tangent of x.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.round

gomath.round(x) -> y

x rounded to the nearest whole number, halves away from zero.

Parameter Type What it is
x number
Result Type What it is
y number

gomath.min

gomath.min(x, y) -> z

The smaller of x and y.

Parameter Type What it is
x number
y number
Result Type What it is
z number

gomath.max

gomath.max(x, y) -> z

The larger of x and y.

Parameter Type What it is
x number
y number
Result Type What it is
z number

gomath.hypot

gomath.hypot(x, y) -> z

The square root of xx + yy.

Parameter Type What it is
x number
y number
Result Type What it is
z number

gomath.copysign

gomath.copysign(x, y) -> z

x with the sign of y.

Parameter Type What it is
x number
y number
Result Type What it is
z number

gomath.mod

gomath.mod(x, y) -> z

The remainder of x / y, with the sign of x (Lua's % takes the sign of y).

Parameter Type What it is
x number
y number
Result Type What it is
z number

gomath.pow

gomath.pow(x, y) -> z

x to the power y.

Parameter Type What it is
x number
y number
Result Type What it is
z number

gomath.atan2

gomath.atan2(x, y) -> z

The angle of the point (y, x), in radians.

Parameter Type What it is
x number
y number
Result Type What it is
z number

The bit table

Bit operations on integers up to 2^53.

bit.band

bit.band(x, y) -> z

Bitwise x & y.

Parameter Type What it is
x integer
y integer
Result Type What it is
z integer

bit.bor

bit.bor(x, y) -> z

Bitwise x | y.

Parameter Type What it is
x integer
y integer
Result Type What it is
z integer

bit.bxor

bit.bxor(x, y) -> z

Bitwise x ^ y.

Parameter Type What it is
x integer
y integer
Result Type What it is
z integer

bit.bnot

bit.bnot(x) -> y

Bitwise not (two's complement).

Parameter Type What it is
x integer
Result Type What it is
y integer

bit.lshift

bit.lshift(x, n) -> y

x shifted left by n bits.

Parameter Type What it is
x integer
n integer 0..63
Result Type What it is
y integer

bit.rshift

bit.rshift(x, n) -> y

x shifted right by n bits (the sign kept).

Parameter Type What it is
x integer
n integer 0..63
Result Type What it is
y integer

bit.btest

bit.btest(x, y) -> set

x & y is not 0.

Parameter Type What it is
x integer
y integer
Result Type What it is
set boolean

The sensors table

The visible snapshots of the declared sensors, by id; read-only.

sensors.<id>

A value of type table. The visible snapshot of a declared sensor (sensors.game, sensors.status); read-only.

Table shapes

The tables the API hands out or takes. A handler's t is a Tick; on_frame's second argument is a Frame.

Tick

The tick context every handler gets; one per VM, updated in place, read-only.

Field Type What it is
now number ns since session start (an exact integer)
unix_ms number wall clock ms (blinks, wobbles)
dt number drive phase: s since the last on_tick, 0.005..0.2, first 0.025
native boolean voices render on the actuators
ducked table<string, boolean> ducked[bus] is true while a ducking shot holds that bus
active boolean true this tick when the game runs, the mod says active, and effects are not paused
reason string on_idle: "idle", "haptics_off" or "restart"
gyro Gyro Bururu's gyro aim
caps Caps what the controller in use can do
slot integer the slot of the controller in use (the one in your hands); 0 while none is connected
slots Slot[] the connected controllers: Controller n on the Controller page is t.slots[n] (walk them with for n = 1, #t.slots)
pad Pad drive phase: the pad of this tick
settings table this mod's setting values
core table Bururu's own settings, read-only: gyro_aim, haptics_strength, lightbar_brightness, poll_ms, ...
words table<string, string> backend words a mod may log (no_motion_hint, ...)

Gyro

Bururu's gyro aim as a mod may read it.

Field Type What it is
held boolean something holds the gyro aim
aiming boolean gyro aim is on and moving the mouse

Slot

One connected controller.

Field Type What it is
name string "DualSense Edge, USB", "Xbox controller"
caps Caps what it can do

Caps

What a controller can do.

Field Type What it is
voices boolean wave haptics on two actuators; false for a DualSense on its cable on macOS
voice_rate integer 48000 (USB) or 3000 (Bluetooth); 0 without voices
motors integer body rumble motors
impulse boolean trigger motors
adaptive boolean adaptive trigger effects
lightbar boolean a lightbar
leds boolean player LEDs
mic boolean a mic LED
motion boolean motion input
touch boolean a touchpad

Pad

The pad of one active tick.

Field Type What it is
ok boolean a controller is open and sends input
l2 integer left trigger, 0..255
r2 integer right trigger, 0..255
held table<string, boolean> held buttons: south east west north l1 r1 l2 r2 l3 r3 start select home touchpad mic up down left right, and their Sony and Xbox names
pressed table<string, boolean> pressed since the last tick, same names
sticks table<string, number> lx ly rx ry, -1..1
aim_dps number how fast the pad pitches and yaws, deg/s
gyro_dps number[] deg/s: pitch, yaw, roll
gyro_raw integer[] raw angular velocity
accel_raw integer[] raw acceleration
clock integer the motion sensor clock
touch boolean a finger rests on the touchpad
has_gyro boolean the connection passes motion
l2_held boolean button pressed or analog past the threshold
r2_held boolean button pressed or analog past the threshold

Event

One input: its fields as the sensor gives them, plus these.

Field Type What it is
at number ns since session start
live boolean false while a file source catches up
sensor string the sensor id
input string "<sensor>:<name>"
old table? a snapshot change: the previous value
new table? a snapshot change: the new value

Facts

What a game mod's facts handler returns.

Field Type What it is
active boolean the player is in control
menu boolean a menu is open: hold the gyro if the player wants that
context string the sentence for "State: ..." and the window
players integer? how many people play now; nil is 1. With 2 or more, and two or more controllers connected, player n's feels play on Controller n; a player with no controller connected gets none

FeelPlayOpts

How a one-shot plays.

Field Type What it is
delay_ms number? start this much later
at number? start at this time, ns since session start
side string? "both", "left" or "right"
scale number? strength; nil is 1, 0 or less plays nothing
pan number? -1 left .. 1 right
amount number? what the feel's amount-scaled voices scale by
gain string? the gain table key; default the feel's mix.gain, else its name
rumble string? the rumble table key; default the feel's name
params table<string, number>? the feel's params
slot integer? play on controller n (t.slots[n]) only; nil: the controller in your hands
player integer? player n's feel: Controller n while the facts say two or more people play and two or more controllers are connected (a player with no controller connected gets none), else the controller in your hands

FeelLayerOpts

How a layer plays this tick.

Field Type What it is
side string? "both", "left" or "right"
gain string? the gain table key; default the layer key
rumble string|false|nil the rumble table key, false for nothing on the motors
params table<string, number>? the feel's params
add table<string, number>? added to voice fields (f0_hz, f1_hz, level, trem_hz, trem_depth, gate_hz, gate_duty, band_hz)
slot integer? as for feel.play
player integer? as for feel.play

FeelRumbleOpts

How a motors-only level plays.

Field Type What it is
side string? "both", "left" or "right"
gain string? the gain table key; default the layer key
slot integer? as for feel.play
player integer? as for feel.play

Frame

on_frame's f: changes the frame of the controller in your hands after the tables and overlays (methods: light, light_rgb, trigger, trigger_raw, leds, mic, final, slot, player).