Overview

Applies to: RS3 Scripting Engine 2016 version 1.1 LUA version 5.3 January 2016 
Revised December 2017 - version 1.2

RS3 is a scripting language based on LUA (the license is reproduced verbatim below). LUA is a lightweight multi-paradigm programming language designed primarily for embedded systems and clients. Redtitan use LUA to automate document production using RedTitan EscapeE and the uberED HTML5/CSS3/SVG1.1authoring systemRedTitan extends LUA by providing a number of functions that interface to EscapeE automation API. The RS3 application will execute the content of a script file (default extension .LUA) specified as the first parameter on the command line.

In addition to the functions documented below, RS3 defines the global table
cmd . This contains the command line parameters.
print(cmd.str0) --> c:\program files\redtitan\software\rs3.exe
Example
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
Copyright © 1994–2015 Lua.org, PUC-Rio.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This is not a user guide. This reference guide documents the extension made to LUA for RedTitan RS3. The examples use LUA syntax and data types refer to LUA conventions



Parts of RS3 are based on Lua which is free software distributed under the terms of the MIT license reproduced here
Function csvopen

Applies to: RS3 Scripting Engine 2016 version 1.1

Opens a file for processing in COMMA SEPARATED FILE format and specifies initial conditions.

Syntax
csvopen(filename:string[,separator:string=","[,fieldnames:boolean=true]]):number
Parameters
filename


separator




fieldnames 
 
required


optional




optional 
 
Full path to filename.


Defaults to the comma character. Note: Inter-field separator may only be specified as a single character.

Specifies if the first record is treated as a list of field names. Fields from the CSV file are read as name/value pairs. If this parameter is set to false the first record will be treated as a data record and fields will be named
field1, field2, field3 etc. Note: Field names (if explicitly specified in the first record) must be legal LUA identifiers and they are case sensitive,
Return value
If the function succeeds an integer handle is returned that may be used in subsequent calls to the function csvrecord to read data records.

Return value -1 indicates the specified file does not exist or cannot be opened for reading.
Example

See function csvrecord. Version 1.2 (Dec 2017) publishes a class wrapper for CSV functions called TCSV (see init.LUA, HL.LUA).  
 
e.g.  
 
CSV=TCSV.Create("account-summary1.csv",",",false); -- create an instance of the CSV class 
 
-- The "Record" method of the TCSV class is called using the ":" operator 
Fields=CSV:Record()
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
Function csvrecord

Applies to: RS3 Scripting Engine 2016 version 1.1

Reads and parses a CSV record as a LUA table from a file previuosly opened with function csvopen.

Syntax
csvrecord(handle:number):table
Parameters
handle
required
File handle obtained from csvopen call.
Return value
The function returns a LUA table consisting on name/value assignments. If there are no further records in the file (EOF) a LUA nil value is returned
Example (see TCSV class wrapper)
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
--[[ LUA script - If test.csv contains

alpha,beta,delta
one,two,three

output will be

field2 = beta
field1 = alpha
field3 = delta
field2 = two
field1 = one
field3 = three --]]

csvhandle = csvopen("test.csv", ",", false)

if csvhandle==-1 then print("Error reading CSV file") return end

repeat

fields=csvrecord(csvhandle)
if fields==nil then break end
for k,v in pairs(fields) do print(k,'=',v) end

until fields==nil
Function html -- deprecated, replaced by THTML class functions

Applies to: RS3 Scripting Engine 2016 version 1.1

Streams actual parameters to RedTitan EscapeE for substitution in RedTitan uberED HTML5/CSS3 template
html(htmlfile:string,actualparameters:table,streamname:string):boolean
Parameters
htmlfile



actualparameter



streamname
required



required



required
1. Full path to an HTML file created by uberED or
2. If the parameter starts with the character "<" the value is treated as a complete HTML document.

1. LUA Table specifying name/value pairs.
or
2. LUA nil value indicating the named stream ends

The name of the memory mapped stream that will be processed by EscapeE. Note: EscapeE command is of the form EscapeE x.html,streamname
Return value
LUA boolean value TRUE if the function succeeds. FALSE indicates an error and a modal dialogue is displayed..
Example
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
--[[ Publish the contents of a CSV file using an HTML template.
--]]

csvhandle = csvopen("pete.CSV")

if csvhandle==-1 then
print("Error reading CSV file")
return
end

repeat

fields = csvrecord(csvhandle)

if not html("pete.html",fields,"tiger") then break end

until fields==nil
Function pause

Applies to: RS3 Scripting Engine 2016 version 1.1

Display a message dialogue with an optional timeout.

Syntax
pause(message:string[,timeout:number=0]):number
Parameters
message



timeout
required



optional
Message to be displayed


Default - no timeout. i.e. wait for the user to click the OK button. If the timeout parameter is used the dialogue will be automatically closed after the period specified in milliseconds.
Return value

nil
Example
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
pause("program complete",3000)
Function popup

Applies to: RS3 Scripting Engine 2016 version 1.1

Display a non-modal message (Tooltip)

Syntax
popup(message:string[,severity:number=0]):number
Parameters
message



severity
required



optional
Message to be displayed


value 0 - display no icon
value 1 - display an informtion icon.(default)
value 2 - display a warning icon.
value 3 - display an error icon.
Return value

nil
Example
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
popup("Wait please\nprocessing 10456 records")
Function currency

Applies to: RS3 Scripting Engine 2016 version 1.1

Display a non-modal message . Formats a LUA number in currency format. Two decimal places with thousand range separator.

Syntax
currency(value:number):string
Parameters
value
required
Number to be formatted
Return value

LUA string
Example
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
n=0123707.4
a=currency(n)
print(a) --> 123,707.40
Function command-- deprecated use THTML class functions

Applies to: RS3 Scripting Engine 2016 version 1.1

Send special command to EscapeE stream

Syntax
command(streamname:string,command:string):string
Parameters
streamname

command
required

required
Name of stream being processed by EscapeE

name=value command defined by RTHMLIN
Return value

none
Example
RedTitan RS3/LUA extensions reference guide
© Redtitan Technology 2017
command("s5","file=result5") -- EscapeE selects new output file name.