Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Live Search
spaceKeyDOC
placeholderSearch

Expand
titleTABLE OF CONTENTS
Table of Contents
minLevel2
maxLevel3
minLevel2

...

LUA scripting in EFS Survey filters and the LUA question type offer users with programming skills more flexibility and convenience. The LUA question type, found in "Advanced", provides an efficient scripting interface to the survey environment, allowing users easily recoding of the survey's variables, execution of complex calculations, verification or processing of user input and extended quota calculations. The question type provides two code boxes, the first one is executed before sending the page to the participant, the second code box is executed when a user submits the page containing the LUA question type. You can also include your own function libraries from the media library (global or project specific, text files with the extension .txt or .lua), allowing you to reuse frequently used functions across projects. Hiding conditions can be employed and you may define whether the script should be executed every time the page is called or only once (e.g. when using a page trigger or the back button).Image Removed

...

Many filters which need a lot of effort when working with EFS standard filter definitions or alternative filter conditions can be realized more easily with the LUA filters. E.g. a function is available which simplifies handling of system missings in filter conditions.

...

EFS specific functions in LUA filters and LUA question type

Info

Please note: Loop variables are not supported within the LUA environment.

setVariableValue(varName, varValue)

...

Replaces os.time() and returns the current time when called without arguments, or a time representing the date and time specified by the given table. Please refer to os.time documentation.

Examples for LUA in EFS

...

Block specific IPs from accessing a survey using a LUA filter

If you have a manageable list of IPs, which you want to block from accessing your survey, you can use a LUA filter to screen out these participants. This example code blocks the IPs 78.34.112.1, 78.34.112.2 and 78.34.112.3 and the list can be extended by providing additional comma-separated IPs. The last item should not have a comma after it.

...

Get current GMT time

This code will always return the time on server side in GMT and can be used for date related calculations. By putting an exclamation mark (!) in front of the formatting in the date function, the returned date will always be using the GMT time zone.

Example code
Code Block
languagedelphi
setVariableValue("v_1", date("!%H %M"))

...

  • LUA 5.1 Reference Manual

  • Programming in LUA 5.0, free for personal use

  • Description of mathematical functions in the math library

  • Lrexlib reference manual (Regular Expressions)

  • Repl.it provides a convenient LUA 5.1 online environment for writing and debugging LUA code in a controlled environment. Some EFS functions can be emulated by rewriting them, see example below.

    Image RemovedImage Added

    Example functions for use in repl.it

    Code Block
    languagedelphi
    -- EFS function getQuotaCurrentValue with array of example quota-values
    function getQuotaCurrentValue(a)
      b = {8, 4, 2, 3, 3, 2, 3, 2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 5, 3, 1, 5, 4}
      return b[a]
    end
    
    -- EFS function setVariableValue function, outputs value to console as v_1=1
    function setVariableValue(a,b)
    	print(a .."="..b)
    end