Call a foreign-language function: Difference between revisions

Add Standard ML version using PolyML
(Add Standard ML version using PolyML)
 
(5 intermediate revisions by 2 users not shown)
Line 679:
 
Afterwards usage of the function is just as with any other function.
 
=={{header|Ecstasy}}==
Ecstasy was designed around software containers and a strong security model. As such, Ecstasy does not have an FFI, and Ecstasy code cannot direcly access operating system or other foreign functions. More specifically, code running within an Ecstasy container cannot call foreign functions; any such required capabilities must be implemented outside of Ecstasy and then <i>injected</i> into an Ecstasy container.
 
=={{header|Factor}}==
If you declare a parameter as <code>c-string</code>, Factor automatically converts NULL-terminated C strings to Factor strings and back. In this case we additionally have to free the returned string, so we have to do the conversion explicitly; else the reference to the pointer would be dropped behind the scenes.
Line 2,664 ⟶ 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,835 ⟶ 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="ecmascriptwren">/* call_foreign_language_functionCall_a_foreign-language_function.wren */
 
class C {
Line 2,913 ⟶ 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);
Line 2,935 ⟶ 2,955:
Hello World!
</pre>
 
=={{header|X86-64 Assembly}}==
===UASM 2.52===
23

edits