SpecStruc-EMBED.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="EMBED_Structure">
  5. <title>EMBED Structure<indexterm>
  6. <primary>EMBED Structure</primary>
  7. </indexterm></title>
  8. <para><emphasis>resulttype funcname</emphasis> <emphasis
  9. role="bold">(</emphasis> <emphasis>parameterlist</emphasis> <emphasis
  10. role="bold">) := EMBED(<indexterm>
  11. <primary>EMBED</primary>
  12. </indexterm></emphasis> <emphasis>language</emphasis> <emphasis
  13. role="bold">)</emphasis></para>
  14. <para><emphasis>code</emphasis></para>
  15. <para><emphasis role="bold">ENDEMBED<indexterm>
  16. <primary>ENDEMBED</primary>
  17. </indexterm>;</emphasis></para>
  18. <para><emphasis>resulttype funcname</emphasis> <emphasis
  19. role="bold">(</emphasis> <emphasis>parameterlist</emphasis> <emphasis
  20. role="bold">) := EMBED(</emphasis> <emphasis>language, code</emphasis>
  21. <emphasis role="bold">);</emphasis></para>
  22. <informaltable colsep="1" frame="all" rowsep="1">
  23. <tgroup cols="2">
  24. <colspec align="left" colwidth="122.40pt" />
  25. <colspec />
  26. <tbody>
  27. <row>
  28. <entry><emphasis>resulttype</emphasis></entry>
  29. <entry>The ECL return value type of the function.</entry>
  30. </row>
  31. <row>
  32. <entry><emphasis>funcname</emphasis></entry>
  33. <entry><para>The ECL definition name of the function.</para></entry>
  34. </row>
  35. <row>
  36. <entry><emphasis>parameterlist</emphasis></entry>
  37. <entry>The parameters to pass to the function.</entry>
  38. </row>
  39. <row>
  40. <entry><emphasis>language</emphasis></entry>
  41. <entry>The name of the programming language being embedded. A
  42. language support module for that language must have been installed
  43. in your plugins directory. Modules are provided for languages such
  44. as Java, R, Javascript, and Python. You can write your own pluggable
  45. language support module for any language not already supported by
  46. using the supplied ones as examples or starting points.</entry>
  47. </row>
  48. <row>
  49. <entry><emphasis>code</emphasis></entry>
  50. <entry>The source code to embed.</entry>
  51. </row>
  52. </tbody>
  53. </tgroup>
  54. </informaltable>
  55. <para>The <emphasis role="bold">EMBED</emphasis> structure makes it possible
  56. to add in-line <emphasis>language</emphasis> code to your ECL. This is
  57. similar to the BEGINC++ structure, but available for any
  58. <emphasis>language</emphasis> with a pluggable language support module
  59. installed, such as R, Javascript, and Python. Others may follow or people
  60. can write their own using the supplied ones as templates/examples/starting
  61. points. This may be used to write Javascript, R, or Python code, but is not
  62. usable with Java code (use the IMPORT function for Java code).</para>
  63. <para>The parameter types that can be passed and returned will vary by
  64. <emphasis>language</emphasis>, but in general the simple scalar types
  65. (INTEGER, REAL, STRING, UNICODE, BOOLEAN, and DATA) and SETs of those scalar
  66. types are supported, so long as there is an appropriate data type in the
  67. <emphasis>language</emphasis> to map them to.</para>
  68. <para>The first form of EMBED is the structure that must terminate with
  69. ENDEMBED. This may contain any code in the supported
  70. <emphasis>language</emphasis>.</para>
  71. <para>The second form of EMBED is a self-contained function. The
  72. <emphasis>code</emphasis> parameter contains all the code to execute, making
  73. this useful only for very simple expressions.</para>
  74. <para><emphasis role="bold">WARNING: This feature could create memory
  75. corruption and/or security issues, so great care and forethought are
  76. advised—consult with Technical Support before using.</emphasis></para>
  77. <para>Example:</para>
  78. <programlisting>//First form: a structure
  79. IMPORT Python; //make Python language available
  80. INTEGER addone(INTEGER p) := EMBED(Python)
  81. # Python code that returns one more than the value passed to it
  82. if p &lt; 10:
  83. return p+1
  84. else:
  85. return 0
  86. ENDEMBED;
  87. //Second form: a function
  88. INTEGER addtwo(INTEGER p) := EMBED(Python, 'p+2'); </programlisting>
  89. <para>See Also: <link linkend="BEGINCplus_Structure">BEGINC++
  90. Structure</link>, <link linkend="IMPORT">IMPORT</link>, <link
  91. linkend="IMPORT_function">IMPORT function</link></para>
  92. </sect1>