Actions Lua Functions

Action Subgroups

One of the basic XLua operations is to invoke a Lua function that has been loaded from a string or a file.  One of the data structures XLua uses for communication with Lua functions is an implicit parameter queue.  Before calling a Lua function, any number of supported parameter types can be pushed onto the parameter queue, and will be passed in the same order as the arguments of the Lua function.

Once a Lua function is invoked, MMF execution is suspended, and the Lua code executes.  Once the function returns, MMF execution will resume where it left off.  A Lua function may itself call back into MMF via an MMF Function, and thus control may pass back and forth between Lua and MMF several times, creating a call stack.  Only the top frame of the call stack is currently executing; every other frame is suspended, waiting for the frame above it to return.

Supported parameter types to pass to a Lua function include:

NIL is a special empty-value native to Lua, similar to null in other languages.  Tables are a collection of parameters and may themselves contain other tables nested within.

As a convenience, several inline-parameter versions of the Call Lua Function action are provided, bypassing the need to separately push parameters onto the parameter queue.

Push Integer Parameter

Pushes an integer value into a parameter queue, which will be passed with the next lua function call.

Parameters

Value Integer value

Push Floating Parameter

Pushes a floating-point value into a parameter queue, which will be passed with the next lua function call.

Parameters

Value Floating-point value

Push String Parameter

Pushes a string value into a parameter queue, which will be passed with the next lua function call.

Parameters

String String parameter

Push Boolean Parameter

Pushes a boolean value into a parameter queue, which will be passed with the next lua function call.

Parameters

Value 1 = true, 0 = false

Push NIL

Pushes a nil value into a parameter queue, which will be passed with the next lua function call.

Note: the receiving function may require special handling if it uses varargs.

Parameters

None.

Call Lua Function

Suspends the current event and executes a lua function. All parameters pushed since the last function call will be passed as function parameters.

Any valid non-local function can be called, including functions in subtables or using the colon operator.  Acceptable function name syntax is described in more detail here.

Parameters

String Function Name

Copyright 2010 Justin Aquadro