1. Macro directory
  2. Server side macro

Server side macros

To void redundant code in your WarpScripts™, you can develop server side macros. Macros allow for code factorization.

Macro directory

In the /path/to/warp10/etc/conf-standalone.conf file, the directory containing macros is configured by:

warpscript.repository.directory = ${standalone.home}/macros
warpscript.repository.refresh = 5000
  • warpscript.repository.directory: Macro Repository
  • warpscript.repository.refresh: How often (in ms) to scan macro repository for new scripts.

Macros are mc2 files deployed:

  • in a sub directory in Warp 10™ Analytics Engine, for example: /path/to/warp10/macros/domain/app/macro.mc2
  • via jar files for use with WarpScript™ library

Server side macro

For example: /path/to/warp10/macros/domain/app/MAX_ABS.mc2

<%
// Macro's documentation 
  {
    'name' 'MAX_ABS'
    'desc' // Description
      <'
Function to calculate the max absolute value of two parameters
      '>
     // Signature
    'sig' [ [ [ [ 'param2:LONG' 'param1:LONG' ] ]  [ 'result:LONG' ] ] ]
    'params' {
      'param1' 'First parameter'
      'param2' 'Second parameter'
      'result' 'Max absolute value of two parameters'
    }
    // Examples
    'examples' [
    <'
-7 8 @domain/app/MAX_ABS 
    '>
    ]
  } INFO

    // Actual code of the macro
    SAVE 'context' STORE
  
    ABS     	// Absolute value of first parameter
    SWAP    	// Swapping to get 2nd parameter on top
    ABS     	// Absolute value of 2nd parameter
    MAX     	// Max of those two absolute values
    $context RESTORE

%>
'macro' STORE
// Unit tests
-1 -5 $macro EVAL 5 == ASSERT
$macro

Once deployed, you can use it. For example:

-1 -5 @domain/app/MAX_ABS  // To evaluate a macro you use @name