JamPlus has built in Lua support, provided through a minimal distribution of LuaPlus (http://luaplus.org/). Lua script may be run during the Parsing Phase and during the Updating Phase.
Any LuaBinaries capable module can run in the LuaPlus environment. Just drop the binary in the bin/LuaPlus/modules/ directory.
The scripts located in bin/scripts/ are written in Lua, although they are executed external to the Jam executable.
There are two rules for execution of Lua script available for use during the rule parsing phase of JamPlus. They are rule LuaString LUA_SCRIPT and rule LuaFile LUA_FILENAME.
Executes
LUA_SCRIPT, returning any results back to the caller.
- Parameters:
LUA_SCRIPT Syntactically correct Lua script embedded in a string. Only the first string list item is executed.
- Returns:
- If the Lua script doesn't return any values, the return value is an empty list. If the Lua script does return values, the return values are transformed to a Jam string list. Nested tables are collapsed.
Executes
LUA_FILENAME, returning any results back to the caller.
- Parameters:
LUA_FILENAME The filename of the Lua script to run.
- Returns:
- If the Lua script doesn't return any values, the return value is an empty list. If the Lua script does return values, the return values are transformed to a Jam string list. Nested tables are collapsed.
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)) }
Within a Lua script, it is possible to access Jam variables and execute Jam rules.
Retrieves
VARIABLE_NAMEfrom the active Jam globals and returns it as a table of strings.If
TARGET_NAMEis specified,VARIABLE_NAMEis retrieved as if anon TARGET_NAMEhad been issued in Jam.
- Parameters:
TARGET_NAME (optional) The target to make active to retrieve VARIABLE_NAMEfrom.VARIABLE_NAME The Jam variable to retrieve.
- Returns:
- All strings within the
VARIABLE_NAMEstring are returned as a Lua array of strings.
Sets
VALUEinto the active Jam globalVARIABLE_NAME.VALUEcan be a boolean, number, string, or table. Nested tables are collapsed.If
TARGET_NAMEis specified,VALUEis set intoVARIABLE_NAMEas if anVARIABLE_NAME on TARGET_NAMEhad been issued in Jam.
- Parameters:
TARGET_NAME (optional) The target to make active to set VARIABLE_NAMEinto.VARIABLE_NAME The Jam variable to set.
Executes rule
RULE_NAMEusing any optionalPARAMETERSspecified. Returns the result as a Lua table.
- Parameters:
RULE_NAME The name of any valid Jam rule. PARAMETERS (optional) If specifed, the PARAMETERSare collapsed into a Jam string list and passed to the rule.
- Returns:
- If the Jam rule doesn't return any values, the return value is
nil. If the Jam rule does return values, the return values are transformed to a Lua array of strings.
# Hello LuaString "print('Hello')" ; # 10 hi false Echo [ LuaString "return { 10, 'hi', false }" ] ; # 5.suf hello.suf true.suf var = [ LuaString "return { 5, 'hello', true }" ] ; Echo $(var:S=.suf) ; #------------------------------------------------------------------------------ # Hello world! var = Hello world! ; Echo [ LuaString "return jam_getvar('var')" ] ; # Hi everyone LuaString "jam_setvar('var', 'Hi everyone')" ; Echo $(var) ; # Hi everyone Echo [ LuaString "return jam_getvar('var')" ] ; #------------------------------------------------------------------------------ # The Variable Contents MyVariable on mytarget = The Variable Contents ; Echo [ LuaString "return jam_getvar('mytarget', 'MyVariable')" ] ; # **hello** LuaString "jam_setvar('mytarget', 'MyVariable', '**hello**')" ; Echo [ LuaString "return jam_getvar('mytarget', 'MyVariable')" ] ; rule ReturnList INPUT { return **$(INPUT)** ; } # **MyStuff** **YourStuff** Echo [ LuaString "return jam_evaluaterule('ReturnList', { 'MyStuff', 'YourStuff' })" ] ;