Call a foreign-language function: Difference between revisions

Add Standard ML version using PolyML
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Add Standard ML version using PolyML)
 
(2 intermediate revisions by one other user not shown)
Line 2,668:
 
Transcript showCR:( CallDemo strdup:'Hello' )</syntaxhighlight>
 
=={{header|Standard ML}}==
{{works with|Poly/ML}}
<syntaxhighlight lang="sml">local
val libc = Foreign.loadLibrary "libc.so.6"
val sym = Foreign.getSymbol libc "strdup"
in
val strdup = Foreign.buildCall1(sym, (Foreign.cString), Foreign.cString)
end</syntaxhighlight>
{{out}}
<pre>
> strdup "test string";
val it = "test string": string
>
</pre>
 
=={{header|Stata}}==
Here are examples showing how to build and call from Stata a plugin written in C or Java. See also the entries 29 to 32 in the ''[https://blog.stata.com/2016/01/15/programming-an-estimation-command-in-stata-a-map-to-posted-entries/ Programming an estimation command in Stata]'' series by David M. Drukker, on [https://blog.stata.com/ Stata Blog].
Line 2,839 ⟶ 2,855:
Although RC task solutions are usually written for execution by Wren CLI, the language's main purpose is for embedding and the embedding API is written in C. It is therefore a relative easy matter to call a C function from Wren after first embedding the latter in a suitable C program.
 
<syntaxhighlight lang="wren">/* call_foreign_language_functionCall_a_foreign-language_function.wren */
 
class C {
Line 2,917 ⟶ 2,933:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "call_foreign_language_functionCall_a_foreign-language_function.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
23

edits