Composed Lua Scripts

Composing Lua Scripts


Lua scripts may be composed into other JSLEE services as the extensible engine used for hooks and plugins. Where a service offers such composition, the Lua scripting functionality is derived from the core Lua script service.

When run as a composed solution, Lua scripts are run within the controlling service. As with the scripting service, Lua scripts may still send and receive events and fully access the JSLEE API.

While a service which composes in Lua may initalise scripts in any manner, the general Lua configuration is consistently provided through a lua section in the configuration section of the service:

    "smpp": {
      "handler": "",
      "instance-count": 1,
      "configuration": {
        "message-handler": "EventBus|DevNull",
        "endpoints": [
        "lua": {
          "scripts": [
          "lib-path": [
              , "lua/?/?.lua"
              , "lua/?/?/?.lua"

The lua section of the service defines the library path for Lua, and any other general configuration required (see the lua script engine documentation for more information).

The approach each service takes to defining the script(s) to run differs, however the following rules apply as these are enforced by the Lua script engine:

  1. All Lua scripts may define their script in external files, using the //!scriptfile.lua format.
  2. All Lua scripts may include a begin() method, which will be called as part of script initialisation once.
  3. The result from running the script as defined in the configuration file will be passed to begin().

Each service will determine itself the method(s) it may wish to call within the Lua scripts which it uses. While the script engine calls the handle() method, other services will define their own interfaces, and may request (or require) multiple methods are available within a particular Lua script.