EMBED Structure

resulttype funcname ( parameterlist ) := EMBED( language [:TIME [(label)]]



resulttype funcname ( parameterlist ) := EMBED( language, code [: TIME [(label)]]);

resulttypeThe ECL return value type of the function.

The ECL definition name of the function.

parameterlistA comma separated list of the parameters to pass to the function.
languageThe name of the programming language being embedded. A language support module for that language must have been installed in your plugins directory. Modules are provided for languages such as Java, R, Javascript, and Python. You can write your own pluggable language support module for any language not already supported by using the supplied ones as examples or starting points.
codeThe source code to embed.
TIMETracks timing of an external function call or embedded source code and reports them back as metrics to the user.
labelOptional. A string constant containing the name to associate with the timer. If omitted, the default is used.

The EMBED structure makes it possible to add in-line language code to your ECL. This is similar to the BEGINC++ structure, but available for any language with a pluggable language support module installed, such as R, Javascript, and Python. Others may follow or people can write their own using the supplied ones as templates/examples/starting points. This may be used to write Javascript, R, or Python code, but is not usable with Java code (use the IMPORT function for Java code).

The parameter types that can be passed and returned will vary by language, but in general the simple scalar types (INTEGER, REAL, STRING, UNICODE, BOOLEAN, and DATA) and SETs of those scalar types are supported, so long as there is an appropriate data type in the language to map them to.

The first form of EMBED is the structure that must terminate with ENDEMBED. This may contain any code in the supported language.

The second form of EMBED is a self-contained function. The code parameter contains all the code to execute, making this useful only for very simple expressions.

You can use EMBED instead of BEGINC++ to embed C++ code and specify additional options (for example, DISTRIBUTED) using this form:

myFunction(string name) := EMBED(C++ [: options]) 
  ... text 

WARNING: This feature could create memory corruption and/or security issues, so great care and forethought are advised--consult with Technical Support before using.


//First form: a structure
IMPORT Python3 AS Python;  //make Python language available

INTEGER addone(INTEGER p) := EMBED(Python :TIME('MyTime'))
# Python code that returns one more than the value passed to it
if p < 10:
  return p+1
  return 0

//Second form: a function
IMPORT Python3 as Python;
INTEGER addtwo(INTEGER p) := EMBED(Python, 'p+2' : TIME('MyTime'));  

See Also: BEGINC++ Structure, IMPORT, IMPORT function