Skip to main content

EMBED Structure

resulttype funcname ( parameterlist ) := EMBED( language )

code

ENDEMBED;

resulttype funcname ( parameterlist ) := EMBED( language, code );

resulttypeThe ECL return value type of the function.
funcname

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.

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 
ENDEMBED

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

Example:

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

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

//Second form: a function
INTEGER addtwo(INTEGER p) := EMBED(Python, 'p+2');  

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