Please enable JavaScript to view this site.

MaxxECU Documentation

Navigation: Advanced > User Scripts (LUA)

MaxxECU User Scripting - Quick API Reference table

Scroll Back Prev Top Next More

Standard Lua Libraries

The following standard Lua libraries are available in the scripting environment. These behave as documented in the official Lua reference manual:

Global environment and base functions: type(), tostring(), tonumber(), pcall(), error(), ipairs(), pairs(), etc.)

Table manipulation: table.insert, table.remove, table.sort, table.concat, etc.)

String manipulation: string.format, string.sub, string.byte, string.char, string.find, etc.)

Math functions: math.abs, math.floor, math.ceil, math.min, math.max, math.huge, etc.

Coroutine management: coroutine.create, coroutine.resume, coroutine.yield, etc.)

Output function: print() Output function - text appears in the MTune Monitor window.

Note: Libraries such as io (file I/O), os, debug, and package are not available. The io namespace is used by the MaxxECU hardware API instead.

 

 

ECU-specific function available to your Lua scripts and are organized into four modules: time, ecu, io, can and print.

 

time - Timing and Delays

time.now() - Returns current timestamp in milliseconds since ECU boot.

time.since(ts) - Returns milliseconds elapsed since timestamp ts.

time.delay(ms) - Suspends script execution for ms milliseconds (cooperative yield).

yield() - Yields execution to the scheduler and resumes immediately.

 

ecu - RealTime Data Values

ecu.get(channel) - Returns raw integer RT-data value.

ecu.getf(channel) - Returns scaled floating-point RT-data value.

ecu.set(slot,value) - Writes value to script RT-data slot 1-24.

 

io - Outputs and virtual Inputs

io.set(output,state) - Sets script output 1-10 on or off.

io.pwm(output,duty[,freq]) - Sets PWM duty and optional frequency on script output 1-10.

io.din(slot,state) - Sets virtual digital input slot 1-12.

io.ain(slot,value) - Updates virtual analog input slot 1-12.

 

can - CAN Bus Communication

can.filter(id,...) - Registers CAN ID filters for received frames.

can.clear() - Removes all registered CAN filters.

can.count() - Returns number of pending received CAN frames.

can.recv() - Returns next received CAN frame or nil.

can.frame(id,bus[,data[,dlc]]) - Creates a CAN frame object.

can.send(frame) - Transmits CAN frame.

can.send(id,bus,data[,dlc]) - Transmits CAN frame directly.

 

print - Debug and log

print(...) - Outputs text to the script monitor window.

 

 

 

 

 

 

 

 

For more information about the MaxxECU user scripts, see User Scripts (LUA), or directly reference the LUA api reference and LUA examples. For more all available LUA settings and options, see Script Code, Script Input Control, Output Functions and Script RT values.