Step 3 - Defining a trigger
to use the Execute Lua Function From File action
This page describes how to use the Workbench to define an On-Demand event type trigger that uses the Execute Lua Function From File action.
Components of this example
For this example, the following applies:
- An On-Demand event type trigger is used, other trigger event types could be used.
- Reporting will be used to see the details of the trigger execution
Defining the trigger, adding local variables, and setting trigger reporting to On
The following describes how to create a trigger that
uses an On Demand event, two local
variables, and the Reporting
feature:
- From Workbench left pane, select the
Projects icon.
The Projects window appears. - Double-click the project you want to add a trigger
to.
The project tab appears. - Select the New button from the
bottom of the Projects tab to define a
new trigger.
- In the Name box, type a name for
the trigger.
- From the Event tab, select the
Trigger Event Type down-arrow, and
then select On-Demand.
- Next you will add two local variables. You will use
these variables when you specify the action for the
trigger.
Select the Local Variables tab. From the Local Variables tab, select Add.
The New Variable window appears. - Name the variable, and then select the data type
(for this example STRING).
- Enter a string length of 256, and
a default value of
This,Is,A,Test,1,2,3,4,5,6.
- In the Count box, accept the
default value of 1 and select
Add.
The variable is added to the Local Variables tab.
You will assign this variable as input for the trigger. - Add the second local variable as a
STRING, with a count of
10, and length of 8
as shown:
- Select Add.
The variable is added to the Local Variables tab.
For this example, there are now two local variables defined for the trigger: - Setting trigger reporting to On.
By default, trigger reporting is set to Off.
For this example, you will set trigger reporting to On so that each time the trigger executes, a report is generated. The trigger report will be viewed to see the details of the trigger execution.
Be careful with the trigger reporting feature, as the trigger reports require system resources. - From the Trigger window, click the
Settings tab.
- Select inside the Reporting box to display a list of reporting options and select On.
Adding the Execute Lua Function from File action
In this example we are using the trigger List
Editor:
- In the Actions section at the bottom of the New
Trigger window, select Add to add an
action.
The New Action window appears. - Expand the Lua Scripting category,
select Execute Lua Function From File,
and then select Add.
The right pane changes to accommodate the specifics of the Execute Lua Function From File action. - Fill in the parameters for the action as
follows:The parameter values appear as follows:
Parameter
Description
Script File
The name of your Lua script file. Use the Browse button to search the Staging Browser to locate the file. For this example: /scripts/stringsplit.lua.
Function Name
This is the name of the Lua function you want to execute. For this example: stringsplit.
- Next to Input Variables, click
Configure to define the input
variables that will pass data to the Lua
function.
- When the Variables window appears,
select Add.
- For this example, a single input named
IN of type STRING is
added. Enter the Length value as
256 and leave the default
Count.
- Click Add, and then click
OK.
The variable is added to the Input tab. - From the Input tab, on the
IN row, click the
Value column.
- Locate and expand LocalVariables,
and then select the appropriate local variable. For
this example, in.
- Next, you will define what variables you want to
pass back from the script when it executes.
- Next to Output Variables, select
Configure.
- When the Variables window appears, select
Add.
The New Variable window appears. - For this example add a single output named
OUT, of type STRING,
and set Count to
10.
- Select Add, and then select
OK.
The variable is added to the Output tab. - From the Output tab, on the
OUT row, select the
Value column.
- Locate and expand LocalVariables,
and then select the appropriate local variable. For
this example, out[0].
The variable is added to the Value column.
Saving, starting, and executing the trigger
You can now validate and save the trigger. After saving
the trigger, you will start the trigger so that it can be
executed. In addition, the project that the trigger belongs
to must also be started.
Remember that this is an On-Demand event trigger, which
means it can be executed manually from the Triggers
window.
- Click Validate. If no errors are
reported, select Save.
If any errors are reported, correct the errors, select Validate again and then select Save.
The trigger is added to the project tab. - Right click the trigger to display its pop-up menu,
and then select Start.
The State column for the trigger changes to Started. - Right click the trigger to display its pop-up menu,
and then click Fire Trigger.
This will cause the trigger to execute, which in turn will execute the actions defined in it. In this example, there is just the one Execute Lua Function From File action.
Viewing the trigger report
Because the trigger reporting setting was set to On, a
trigger report will be generated each time the trigger
executes.
To review the report:
- From the Workbench left pane, expand Logs
& Reports.
- From the right pane, select the
Reports tab.
- In the top half of the Reports
window lists the reports by project and trigger
name.
Select the trigger report, the lower portion of the Reports window provides a report viewer. - Right click the report in the lower portion of the
window and then select Expand All to expand all
sections of the trigger report.
The report of the trigger's execution will show the action and the variables and show that your script split the string into its individual parts. - Remember to turn reporting off after you have
finished developing and debugging a trigger.
The trigger reporting feature takes system resources, and use during regular execution may degrade performance.