NOTE: this article is outdated and requires to make following changes:


  Core functions:

    === Common use ===

    * Print messages into console and log
    Syntax: function report(message)

    * Check link policies
    Syntax: function checkLinkPolicy(name, policy)

    * Get list of active call sessions
    Syntax: function getCallSessionIterator()
    Syntax: function getCallSessionIterator(TREE_SESSION_BY_SOURCE, 0, number)                        - to get sessions sourced by private ID
    Syntax: function getCallSessionIterator(TREE_SESSION_BY_TARGET, 0, number)                        - to get sessions targeted to private ID
    Syntax: function getCallSessionIterator(TREE_SESSION_BY_TARGET, SESSION_TYPE_FLAG_GROUP, number)  - to get sessions targeted to talk group
    Returns:
      iterator of sessions, each session has parameter set:
        object       - reference to session object
        banner       - UUID of session
        kind         - kind of link, see LINK_TYPE_*
        name         - name of link
        number       - ID of context
        slot         - slot number
        tag          - session tag
        flavor       - type of session, see SESSION_TYPE_FLAG_*
        state        - state of session, see SESSION_STATE_*
        source       - source ID
        destination  - destination ID
        priority     - priority of call

	* Get list of session routes
    Syntax: function getRouteIterator(banner)
    Syntax: function getRouteIterator(object)
    Returns:
      iterator of contexts, each context has parameter set:
        object  - reference to context object
        state   - state of route
        slot    - slot number
        kind    - kind of link, see LINK_TYPE_*
        name    - name of link
        number  - ID of link
        banner  - UUID of link

    * Get list of all active connection contexts
    Syntax: function getContextIterator()
    Syntax: function getContextIterator(name)
    Syntax: function getContextIterator(type, option, value)     - when type is TREE_CONTEXT_BY_VALUE_*
    Syntax: function getContextIterator(type, minimum, maximum)  - when type is LINK_TYPE_* or TREE_CONTEXT_OF_*
    Returns:
      iterator of contexts, each context has parameter set:
        object   - reference to context object
        kind     - kind of link, see LINK_TYPE_*
        name     - name of link
        number   - ID of context
        banner   - UUID of context
        caption  - caption of context
        state    - set of bits that defines lock state
        values   - array of vendor-specific values
 
    * Modify specific values of link
    Syntax: function setSpecificValue(object, index, value)
    Syntax: function setSpecificValue(kind, number, index, value)

    * Set value into key-value storage
    Syntax: setStoredValue(place, key1, key2, value, interval)

    * Get value from key-value storage
    Syntax: getStoredValue(place, key1, key2)

    * Get station profile data
    Syntax: getStationData(number)
    Returns:
      nil or following parameter set:
        number        - station ID
        algorithm     - encryption algorithm (not used)
        key           - encryption key ID (not used)
        interval      - location update interval
        capabilities  - station capabilities, see CAPABILITY_*
        language      - selected language, ISO-639=1 
        station       - AX.25 SSID
        call          - station call-sign
        text          - ARRS comment / D-STAR free-text / DMR talker alias
        symbol        - APRS sympol (table + symbol)

    === Call Routing ===

    * Publish user event to session handlers
    Syntax: function publishEvent(text)

    * Add new routes
    Syntax: function createRoute(banner, slot, tag)
            function createRoute(kind, number, slot, tag)
    Returns: boolean status of new route creation, true on success

    * Drop route of call
    Syntax: function dropCallRoute(object)
    Returns: reference to the session object or null

    * Drop session of call
    Syntax: function dropCallSession(banner)
    Syntax: function dropCallSession(object)
    Returns: boolean status of operation

  Collaborative Multithreading:

    ScriptEngine supports Lua's collaborative multithreading
    List of running threads is placed at global table "threads"

    Note: coroutine will be restarted after finish,
    so to kill it forever you have to remove it manually from the table

    Example:

      local function doTestThread(name, arguments)
        local inspect = require('inspect')
        while true do
          print('*** Multithreading example: ' .. name .. ' - ' .. inspect(arguments))
          coroutine.yield(10)
        end
      end

      _G.threads["thread1"] = 
      { 
        thread = coroutine.create(doTestThread),
        arguments = { 1, 2, 3 } 
      }

      _G.threads["thread2"] = 
      { 
        thread = coroutine.create(doTestThread),
        arguments = { 5, 6, 7 } 
      }


Note

Starting from version 20160228 all scripting is moved to plugins and the documentation is in need of update check back later.

Starting version 20160221-221915 scripting engine moved from interpreter Lua 5.1 to compiler LuaJIT 2.0. Syntax of coding was not changed and now has several extensions. Please read about LuaJIT extensions here - http://luajit.org/extensions.html

Execution under LuaJIT can be checked using following method:

if jit ~= nil
then
  -- Code is executing under LuaJIT
end

Core functions

Common use

Call routing

Call routing scripting

Event handling

Applications

Examples