Loading

  1. Functions
  2. Packaging extensions
  3. Loading extensions

WarpScript Extension

WarpScript is fully extensible through a mechanism called extensions which modify the set of functions known to WarpScript.

WarpScript extensions are Java classes extending io.warp10.warp.sdk.WarpScriptExtension. The getFunctions method of the base class should be overridden, it will return a map of function name to function instance that will modify the functions known to WarpScript. Extension classes must have a parameter less constructor.

By associating a null value with a function name key the named function will be removed from WarpScript when the extension is registered.

The template for creating a WarpScript extension is available on github.

Functions

A WarpScript function is a Java class which extends NamedWarpScriptFunction and implement the WarpScriptStackFunction. This latter interface has a method named apply which is called with a stack as parameter. It is within this method that the function performs its actions, interacting with the stack.

Packaging extensions

The template for WarpScript extensions provides a build.gradle build file with a shadowJar task. This task will build a jar which will contain the compiled code for the extension with possible dependencies.

This jar should be placed in the class path known of the JVM launching Warp 10. For example, it can be placed in the directory /path/to/warp10/lib.

Loading extensions

WarpScript extensions declared in the configuration are loaded at startup by Warp 10.

The declaration of an extension is done either via the warpscript.extensions property which contains a comma separated list of class names to load, or, as a preferred solution via properties prefixed with warpscript.extension, each one declaring a single extension.

The value of each of those properties is the fully qualified name of the WarpScriptExtension class to instantiate.

//
// Comma separated list of WarpScriptExtension classes to instantiate to modify the defined WarpScript functions
//
warpscript.extensions = ext.TutorialExtension

//
// Or Individual extension
//
warpscript.extension.template = ext.TutorialExtension

If you prefix such name by a sorting key followed by #. This capability exists so you can control the order in which the extensions are loaded.

warpscript.extension.template1 = 1#ext.TutorialExtensionOne
warpscript.extension.template3 = 3#ext.TutorialExtensionThree
warpscript.extension.template2 = 2#ext.TutorialExtensionTwo

If the configuration file contains a property named after the fully qualified class name prefixed by warpscript.namespace., the value will be used as a prefix of the name under which functions will be registered within WarpScript.

warpscript.extension.test = test.TestWarpScriptExtension
warpscript.namespace.test.TestWarpScriptExtension = foo.

will register all functions of the TestWarpScriptExtension with foo. prefixed.

Note that the name of the function will appear in error messages WITHOUT the namespace.