Overview of Lua scripts

Lua is one type of script language. Compared to general script languages, Lua is advanced for its faster processing speeds. Lua can also be embedded into programs so that some parts of the data processing processes of DataMagic can be created by using Lua.

Creating common component information from processing developed in Lua scripts allows you to update all the data processing processes that use the common components simply by updating Lua scripts even if business procedures are changed.

For the language specifications of Lua, see the Lua documentation.

(1) Lua language specifications supported by DataMagic

Below are the Lua language specifications supported by DataMagic. Other language specifications are not supported.

Table 5.7 Lua language specifications supported by DataMagic

Function

Description

Statements

All of Lua's syntax statements are supported.

Basic functions

tonumber and tostring, for example

String functions

Operations of character strings

Math functions

Math functions

If you intend to use Lua scripts in DataMagic, use the function as follows:

  • Write only statements inside the called function, and then return the result (return value).

(2) Specifications of character encodings in Lua

In a Lua script, character codes are all handled as UTF-8.

The following describes the specifications of character code conversion to be applied to input arguments during Lua script execution.

Table 5.8 Character code conversion of arguments when executing a Lua script

Argument

Character code conversion

Description

av0 (actual data to be processed)

Type I

None

Checksum and binary data, for example; processed as-is.

Other than Type I

From the input character encoding to UTF-8

Handles the character string as-is in Lua.

av1 to 5 (arguments 1 to 5)

Handles a value as-is in Lua. For example, a fixed value is handled as the original character string in Lua.

The following describes the specifications of character code conversion to be applied to a return value during Lua script execution.

Table 5.9 Character code conversion of returned arguments after executing a Lua script

Argument

Character code conversion

Description

av0 (actual data to be processed)

From UTF-8 to the input character code

Handles a character string of UTF-8 generated by Lua as the input character string.

av1 to 5 (arguments 1 to 5)

Note
  • If the following two conditions are met, character codes are not converted.

    • The output type is I (image, unconverted)

    • The target Lua is executed at the end of the common component

    If you want to perform binary processing within a Lua script and return a binary value, place the target Lua code at the end of the component and use the type I (image, unconverted) for output.

  • In character code conversion of arguments input or returned value from Lua script execution, the external characters are not converted.