Getting Started > Use Lua Scripts > Method Reference > General Methods

General Methods
abs_path
Returns the supplied path as an absolute path.
Syntax
abs_path( String path )
Arguments
 
Returns
A string of the supplied path as an absolute path.
convert_date_time
Converts date and time formats using standard Autonomy syntax.
Syntax
String convert_date_time (String InputDateTime, String InputFormatCSV, String OutputFormat, [Boolean OutputGMT = false])
Arguments
 
Discussion
All date and time input is treated as local time unless it contains explicit time zone information.
Returns
Date and time in the desired format.
convert_encoding
This method converts the encoding of the string passed in from UTF8 and returns the converted string.
Syntax
convert_encoding ( String content, String encodingname)
Arguments
 
Returns
The converted string.
copy_file
Copy the source file to the destination path. The copy will fail if the destination file already exists. This can be overridden by providing the optional overwrite argument which forces the copy if the destination exists.
Syntax
copy_file( String src, String dest [, Boolean overwrite] )
Arguments
 
Returns
Returns a Boolean indicating success/failure.
create_path
Creates the specified directory tree.
Syntax
void create_path (String Path)
Arguments
 
create_uuid
Creates a universally unique identifier.
Syntax
String create_uuid()
Returns
A universally unique identifier.
delete_file
Delete the file specified by path.
Syntax
delete_file( String path )
Arguments
 
Returns
Returns a Boolean indicating success/failure.
encrypt
This method encrypts a string passed in and returns the encrypted string. It uses the same encryption as is used for ACL encryption.
Syntax
encrypt (String content)
Arguments
 
Returns
The encrypted string.
encrypt_security_field
Encrypts the ACL.
Syntax
String encrypt_security_field (String ACL)
Arguments
 
Returns
An encrypted string.
file_setdates
Sets the given file times on the file specified by path. If the format parameter is not specified, it is assumed that the dates are provided as seconds since the epoch (1st January 1970).
Syntax
file_setdates( String path, String created, String modified, String accessed [, String format] )
Arguments
 
Used to format the strings coming in at system time. The format parameter is the same as for other Autonomy products.
getcwd
Returns the current working directory of the application.
Syntax
getcwd()
Returns
Returns a string of the current working directory.
get_config
Load a configuration file.
Syntax
get_config( path )
Arguments
 
Discussion
Config files are cached after the first call to get_config, to avoid unnecessary disk I/O in the likely event that the same config is accessed frequently by subsequent invocations of the Lua script. One cache is maintained per Lua state, so the maximum number of reads for a config file is equal to the number of threads which are running Lua scripts
An error is raised if the configuration file does not exist.
Returns
A Config object.
gobble_whitespace
Reduces multiple adjacent white spaces (tab, carriage return, space, and so on in the specified field) to a single space.
Syntax
String gobble_whitespace (String Input)
Arguments
 
Returns
A string without adjacent white spaces.
hash_file
Hashes the specified file using the SHA1 or MDA5 algorithm, or both.
Syntax
String, [String] hash_file (String FileName, String Algorithm1, [String Algorithm2])
Arguments
 
Returns
The hashed file.
hash_string
Hashes the specified string using the SHA1 or MDA5 algorithm.
Syntax
String hash_string (String StringToHash, String Algorithm)
Arguments
 
Returns
The hashed input string.
is_dir
Check if the supplied path is a directory.
Syntax
is_dir( String path )
Arguments
 
Returns
Returns a Boolean indicating if the supplied path is a directory.
log
Appends log messages to the specified file.
Syntax
log( String file, String message )
Arguments
 
Returns
Nothing.
move_file
Move the source file to the destination path. The move will fail if the destination file already exists. This can be overridden by providing the optional overwrite argument which forces the move if the destination exists.
Syntax
move_file( String src, String dest [, Boolean overwrite] )
Arguments
 
Returns
Returns a boolean indicating success/failure.
parse_csv
Parse the given separated values string into a collection of individual strings.
Syntax
parse_csv( csv_string [, delimiter])
Arguments
 
Discussion
The method understands quoted values (such that parsing 'foot, "leg, torso", elbow' produces three values) and ignores white space around delimiters.
Returns
The elements are returned as multiple return values. You may wish to put them in a table like this:
local results = { parse_csv("cat,tree,house", ",") };
parse_xml
Parse the given XML string to an XMLDocument.
Syntax
parse_xml( xml_string )
Arguments
 
Returns
An XMLDocument containing the parsed data, or nil if the string could not be parsed.
regex_match
This method performs a regular expression match on a string.
Syntax
regex_match (String name, String regex [, Boolean case])
Arguments
 
Returns
A table of strings.
regex_search
This method performs a regular expression search on a string.
Syntax
regex_search (String name, String regex [, Boolean case])
Arguments
 
Returns
A regular expression match-object.
send_aci_action
Sends the given query to the ACI server at host:port with optional time-out (ms) and retries settings. Takes the action parameters as a table instead of the full action as a string, as with send_aci_command, to avoid issues with parameter values containing “&”.
Syntax
send_aci_action( host, port, action [, parameters][, timeout]
[, retries] )
Example
send_aci_action( “localhost”, 9000, “query”, {text = “*”, print = “all”} );
Arguments
 
This takes a Lua table containing the action parameters, for example, { param1=”foo”, param2=”bar” }
Returns
The xml response is returned as a string.
If the request has failed, then nil is returned.
send_aci_command
Sends the given query to the ACI server at host:port with optional time-out (ms) and retries settings.
Syntax
send_aci_command( host, port, query [, timeout] [, retries] )
Arguments
 
Returns
The xml response is returned as a string.
If the request has failed, then nil is returned.
sleep
Pause the executing thread for a number of milliseconds.
Syntax
sleep( Integer milliseconds )
Arguments
 
Returns
Nothing.
string_uint_less
This method takes two strings and returns True if the second one is longer than the first. Will return False otherwise.
Syntax
string_uint_less (String1, String2)
Arguments
 
Returns
A Boolean.
unzip_file
Extracts the zip file specified by path to the location specified by dest.
Syntax
unzip_file( String path, String dest )
Arguments
 
Returns
Returns a boolean indicating success/failure.
xml_encode
This method takes a string and encodes it to a string that is valid to be put into XML.
Syntax
xml_encode (String content)
Arguments
 
Returns
A string.
zip_file
Zip the supplied path (file or directory). The output file will only be overwritten if true is supplied for the optional overwrite argument.
Syntax
zip_file( String path [, Boolean overwrite] )
Arguments
 
Returns
The output path is written to path.zip. Returns Boolean indicating success or failure.