Lua Support¶
Jamplus contains a minimal distribution of LuaPlus. Any LuaBinaries capable module can run in the LuaPlus environment. Just drop it in the appropriate directory.
The scripts in the source:bin/scripts folder are written in Lua.
The Jamplus executable has Lua support built in, available for use during the rule parsing phase and when actions are running.
Using Lua in Rules¶
There are two Lua rules available for use during the rule parsing phase of Jamplus.
LuaString LUA_SCRIPT: ExecuteLUA_SCRIPT, returning any results back to the caller.LuaFile LUA_FILENAME: ExecuteLUA_FILENAME.
Within a Lua script, it is possible to access Jam variables and execute Jam rules.
jam_getvar(VARIABLE_NAME): RetrievesVARIABLE_NAMEfrom the active Jam globals and returns it as a table.jam_getvar(TARGET_NAME, VARIABLE_NAME): RetrievesVARIABLE_NAMEfromTARGET_NAMEas if anon TARGET_NAMEhad been issued. Returns the result as a Lua table.jam_setvar(VARIABLE_NAME, VALUE): SetsVALUEinto the active Jam globalVARIABLE_NAME.VALUEcan be a boolean, number, string, or table. Nested tables are collapsed.jam_setvar(TARGET_NAME, VARIABLE_NAME, VALUE): SetsVALUEintoVARIABLE_NAMEas if anon TARGET_NAMEhad been issued.VALUEcan be a boolean, number, string, or table. Nested tables are collapsed.jam_evaluaterule(RULE_NAME [, PARAMETERS]): Executes ruleRULE_NAMEusing any optionalPARAMETERSspecified. Returns the result as a Lua table.
Using Lua in Actions¶
Using the new lua modifier for an action, Lua script can be run in a thread within the Jam process.
actions lua RunLuaScript
{
require 'iox'; iox.Sleep($(SLEEP)); print([[$(TEXT)]])
}
See source:tests/lua/testluaaction.jam for a more detailed example.