Call a foreign-language function: Difference between revisions

Add Standard ML version using PolyML
(Add Standard ML version using PolyML)
 
(29 intermediate revisions by 12 users not shown)
Line 17:
*   [[Use another language to call a function]]
<br><br>
 
=={{header|8th}}==
<langsyntaxhighlight lang="forth">
\ tell 8th what the function expects:
"ZZ" "strdup" func: strdup
Line 28 ⟶ 27:
\ the ".s" will show both strings and you can see they are different items on the stack
free \ let the c library free the string
</syntaxhighlight>
</lang>
=={{header|68000 Assembly}}==
{{works with|Sega Genesis}}
 
The Genesis uses a Z80 coprocessor to interface with its sound hardware. The Z80 executes its code from RAM, so before starting this, you have to <code>memcpy</code> the compiled program code from the Genesis cartridge ROM to the shared RAM area at $A00000. Since this task is about calling a function, we'll show the z80 code necessary to do that. Thanks to [https://www.chibiakumas.com/68000/platform2.php#LessonP20 this tutorial] for guidance on how this all works.
 
(Technically, the 68000 isn't calling the function itself, since it doesn't understand Z80 code at all; rather, it's instructing the Z80 to call and execute the function on its behalf. But this is probably as close as we'll ever get.)
 
'''Z80 Code:'''
<syntaxhighlight lang="z80">org &0000 ;execution resets here after the 68000 resets the Z80 and sends a bus request.
jr start
 
org &0038 ;in IM 1 mode, we jump here for an IRQ. But this isn't being used for this example, so we'll just silently return.
reti
 
org &0060
start:
DI
IM 1
LD SP,&2000
 
 
main: ;hardware non-maskable interrupt (NMI) jumps here (address &0066)
 
ld a,(&1F00) ;we'll only allow the 68000 to alter the contents of this memory address.
or a
jr z,main ;just keep looping until it's nonzero.
 
;by counting the bytes each instruction takes, it can be proven that this label points to &006C.
;The call opcode takes 1 byte and the operand that follows takes two bytes.
 
smc:
call &0000 ;we'll overwrite the operand at &006D-&006E with whatever function we want to call.
 
done:
jp done ;loop until next reset
 
ExampleFunction: ;ADDR: &0072($A00072)
ret ;for simplicity this does nothing but in reality you'd have it do something sound-related here.</syntaxhighlight>
 
Here's the 68000 code that will get the Z80 to call this function:
 
<syntaxhighlight lang="68000devpac">Z80_Call:
MOVE.W #$100,$A11100 ;write: z80 reset
.wait:
BTST #8,$A11100 ;read: check bit 8 to see if the z80 is busy
BNE .wait ;loop until not busy
 
 
;now we write the function address
;z80 is little-endian so we need to reverse the byte order.
;also 68000 cannot safely write words at odd addresses so we need to write as bytes.
 
MOVE.B #$72,$A0006D
MOVE.B #$00,$A0006E ;this changes the "call &0000" above to "call ExampleFunction"
 
MOVE.B #$FF,$A01F01 ;unlock the semaphore
MOVE.W #0,$A11100 ;Z80 Bus Request - after this write, the Z80 will start executing code.</syntaxhighlight>
=={{header|Ada}}==
Ada provides standard interfaces to [[C]], [[C++]], [[Fortran]] and [[Cobol]]. Other language interfaces can be provided as well, but are not mandatory. Usually it is possible to communicate to any language that supports calling conventions standard to the [[OS]] ('''cdecl''', '''stdcall''' etc).
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
Line 46 ⟶ 101:
Put_Line (Value (S2));
Free (S2);
end Test_C_Interface;</langsyntaxhighlight>
 
=={{header|Aikido}}==
There are two ways to call a <em>native</em> function in Aikido. The first is to write a wrapper function in C++ that is invoked from the Aikido interpreter. In a C++ file:
<langsyntaxhighlight lang="aikido">#include <aikido.h>
extern "C" { // need C linkage
 
Line 62 ⟶ 116:
}
 
}</langsyntaxhighlight>
 
Then in the Aikido program:
<langsyntaxhighlight lang="aikido">native function strdup(s)
println (strdup ("Hello World!"))</langsyntaxhighlight>
 
The second way is to use a <em>raw native</em> function. These functions must adhere to a defined set of rules and can be called directly from the Aikido interpreter. In the case of <code>strdup</code> we need to play a nasty trick because it returns a pointer that we need to print as a string.
 
<langsyntaxhighlight lang="aikido">native function strdup (s) // declare native
native function free(p) // also need to free the result
 
Line 83 ⟶ 137:
p++
}
free (s) // done with the memory now</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
The designers of Algol 68 made it extremely hard to incorporate code written in other languages. To be fair, this was a long time ago when such considerations weren't thought important and one should be careful to apply Hanlon's razor.
Line 91 ⟶ 144:
 
Note that I chose a non-trivial library function because the suggested strdup() doesn't really demonstrate the technique all that well.
<langsyntaxhighlight lang="algol68">
BEGIN
MODE PASSWD = STRUCT (STRING name, passwd, INT uid, gid, STRING gecos, dir, shell);
Line 159 ⟶ 212:
FI
END
</syntaxhighlight>
</lang>
{{out}}
<pre>
root:x:0:0:root:/root:/bin/bash
</pre>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 221 ⟶ 273:
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
bx lr @ return
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
'''C Library'''
 
<langsyntaxhighlight lang="c">// compile with:
// clang -c -w mylib.c
// clang -shared -o libmylib.dylib mylib.o
Line 239 ⟶ 290:
int doubleNum(int num){
return num * 2;
}</langsyntaxhighlight>
 
'''Calling from Arturo'''
 
<langsyntaxhighlight lang="rebol">; call an external function directly
call.external: "mylib" 'sayHello ["John"]
 
Line 256 ⟶ 307:
loop 1..3 'x [
print ["The double of" x "is" doubleNum x]
]</langsyntaxhighlight>
 
{{out}}
Line 264 ⟶ 315:
The double of 2 is 4
The double of 3 is 6 </pre>
 
=={{header|AutoHotkey}}==
from the documentation for dllcall: <langsyntaxhighlight AutoHotkeylang="autohotkey">; Example: Calls the Windows API function "MessageBox" and report which button the user presses.
 
WhichButton := DllCall("MessageBox", "int", "0", "str", "Press Yes or No", "str", "Title of box", "int", 4)
MsgBox You pressed button #%WhichButton%.</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> SYS "LoadLibrary", "MSVCRT.DLL" TO msvcrt%
SYS "GetProcAddress", msvcrt%, "_strdup" TO `strdup`
SYS "GetProcAddress", msvcrt%, "free" TO `free`
Line 280 ⟶ 329:
PRINT $$address%
SYS `free`, address%
</syntaxhighlight>
</lang>
 
=={{header|C}}==
===Assembly via GCC===
Assembly code can be embedded and compiled via GCC.
<syntaxhighlight lang="c">
<lang C>
#include <stdlib.h>
#include <stdio.h>
Line 310 ⟶ 358:
return 0 ;
}
</syntaxhighlight>
</lang>
Output:
<pre>
Line 323 ⟶ 371:
===Python===
'''IMPORTANT''' : The following implementation has been tested against Python 2.7, this won't work on a system which does not have the relevant files installed. Also pay attention to the compilation flags.
<langsyntaxhighlight Clang="c">#include <python2.7/Python.h>
 
int main()
Line 338 ⟶ 386:
Py_Finalize();
return 0;
}</langsyntaxhighlight>
'''Compilation''' : Change 2.7 and relevant paths for a different Python version / different install location
<pre>
Line 350 ⟶ 398:
First 10 multiples of 3 in reverse order : [30, 27, 24, 21, 18, 15, 12, 9, 6, 3]
</pre>
 
=={{header|C++}}==
While calling C functions from C++ is generally almost trivial, <code>strdup</code> illustrates some fine point in communicating with C libraries. However, to illustrate how to generally use C functions, a C function <code>strdup1</code> is used, which is assumed to have the same interface and behaviour as strdup, but cannot be found in a standard header.
 
In addition, this code demonstrates a call to a FORTRAN function defined as
<langsyntaxhighlight lang="cpp">FUNCTION MULTIPLY(X, Y)
DOUBLE PRECISION MULTIPLY, X, Y</langsyntaxhighlight>
Note that the calling convention of FORTRAN depends on the system and the used FORTRAN compiler, and sometimes even on the command line options used for the compiler; here, GNU Fortran with no options is assumed.
<langsyntaxhighlight lang="cpp">#include <cstdlib> // for C memory management
#include <string> // for C++ strings
#include <iostream> // for output
Line 399 ⟶ 446:
// free, not delete, nor delete[], nor operator delete
std::free(msg2);
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
{{libheader|clojure-jna}}
Since Clojure is hosted on the JVM, you can follow the same approach as the [[#Java|Java]] solution and invoke your Java class from Clojure:
<langsyntaxhighlight lang="clojure">(JNIDemo/callStrdup "Hello World!")</langsyntaxhighlight>
 
Alternatively, to avoid having to create a library in native code you could use JNA and the clojure-jna library for convenience. Here's how you can invoke ''strcmp'' from the libc shared library:
<langsyntaxhighlight lang="clojure">(require '[net.n01se.clojure-jna :as jna])
 
(jna/invoke Integer c/strcmp "apple" "banana" ) ; returns -1
Line 413 ⟶ 459:
(jna/invoke Integer c/strcmp "banana" "apple" ) ; returns 1
 
(jna/invoke Integer c/strcmp "banana" "banana" ) ; returns 0</langsyntaxhighlight>
 
=={{header|CMake}}==
''This code uses a deprecated feature of CMake.'' In 2014, CMake 3.0 deprecated load_command(). CMake 3.0 can run this code but shows a deprecation warning. When a future version of CMake removes load_command(), this code will stop working, and there will be no way to call C functions from CMake.
Line 421 ⟶ 466:
 
'''CMakeLists.txt'''
<langsyntaxhighlight lang="cmake">cmake_minimum_required(VERSION 2.6)
project("outer project" C)
 
Line 445 ⟶ 490:
2012 / 500 = ${quot}
2012 % 500 = ${rem}
")</langsyntaxhighlight>
 
'''div/CMakeLists.txt'''
<langsyntaxhighlight lang="cmake">cmake_minimum_required(VERSION 2.6)
project(div C)
 
Line 455 ⟶ 500:
 
# Compile cmDIV from div-command.c
add_library(cmDIV MODULE div-command.c)</langsyntaxhighlight>
 
'''div/div-command.c'''
<langsyntaxhighlight lang="c">#include <cmCPluginAPI.h>
#include <stdio.h>
#include <stdlib.h>
Line 512 ⟶ 557:
info->InitialPass = initial_pass;
api = info->CAPI;
}</langsyntaxhighlight>
 
=={{header|COBOL}}==
Tested with GnuCOBOL
 
<langsyntaxhighlight lang="cobol"> identification division.
program-id. foreign.
 
Line 543 ⟶ 587:
display "error calling free" upon syserr
end-if
goback.</langsyntaxhighlight>
 
{{out}}
Line 551 ⟶ 595:
Hello, world
</pre>
 
=={{header|Common Lisp}}==
 
{{libheader|CFFI}}
 
<langsyntaxhighlight lang="lisp">CL-USER> (let* ((string "Hello World!")
(c-string (cffi:foreign-funcall "strdup" :string string :pointer)))
(unwind-protect (write-line (cffi:foreign-string-to-lisp c-string))
Line 562 ⟶ 605:
(values))
Hello World!
; No value</langsyntaxhighlight>
 
=={{header|Crystal}}==
Crystal allows to easily interface with C functions, both from object files and shared libraries.
<langsyntaxhighlight lang="ruby">@[Link("c")] # name of library that is passed to linker. Not needed as libc is linked by stdlib.
lib LibC
fun free(ptr : Void*) : Void
Line 577 ⟶ 619:
LibC.free p # pointer can be freed as String.new(Char*) makes a copy of data
 
puts s2</langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio: writeln;
import std.string: toStringz;
import std.conv: to;
Line 615 ⟶ 656:
free(str1);
free(str2);
}</langsyntaxhighlight>
{{out}}
<pre>str1: Hello World!
str2: Hello World!</pre>
 
=={{header|Delphi}}==
===Importing the function from a shared library===
Line 629 ⟶ 669:
The file first has to be bound to your unit:
 
<langsyntaxhighlight lang="delphi">
{$O myhello.obj}
</syntaxhighlight>
</lang>
 
The next step is to do an external declaration for the function:
<langsyntaxhighlight lang="delphi">
procedure Hello(S: PChar); stdcall; external;
</syntaxhighlight>
</lang>
 
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}}==
Line 644 ⟶ 687:
 
libc is already loaded, it is used by Factor elsewhere.
<langsyntaxhighlight lang="factor">FUNCTION: char* strdup ( c-string s ) ;
 
: my-strdup ( str -- str' )
strdup [ utf8 alien>string ] [ (free) ] bi ;</langsyntaxhighlight>
 
( scratchpad ) "abc" my-strdup .
"abc"
 
=={{header|FBSL}}==
Alongside its interpretative BASIC-style layer, FBSL also hosts built-in Intel-style Dynamic Assembler JIT and ANSI-C Dynamic C JIT compiler layers. BASIC, DynAsm and DynC procedures can be mixed freely to best suit the host script's intended purposes. The procedures follow their own respective syntaxes but are called in the host script in exactly the same way:
Line 718 ⟶ 760:
 
FBSL features a built-in stack balancing mechanism which eliminates stack corruption regardless of whether the API calls are using STDCALL or CDECL calling conventions. Please note that FBSL's BASIC and DynAsm '''do not''' make use of forward function declarations or header files.
 
=={{header|Forth}}==
{{works with|GNU Forth|0.7.0}}
Line 724 ⟶ 765:
Every version of GNU Forth has experimented with a different means to do C foreign function calls. The current implementation resolves various incompatibilities which had plagued earlier mechanisms by parsing C header files and using the host's native toolchain (i.e. gcc and ld) to generate thunks.
 
<langsyntaxhighlight lang="forth">c-library cstrings
 
\c #include <string.h>
Line 746 ⟶ 787:
duped dup strlen type \ testing
 
duped free throw \ gforth ALLOCATE and FREE map directly to C's malloc() and free()</langsyntaxhighlight>
 
=={{header|Fortran}}==
Since Fortran 2003, the standard provides the ISO_C_BINDING module to help interface with C programs. Before this, compiler vendors often provided nonstandard extensions to do this. Even with this new facility, some features, such as calling a STDCALL function on Windows, need some nonstandard extension.
Line 757 ⟶ 797:
Here is an example using the ISO_C_BINDING standard module to link against the C API functions ''strdup'', ''free'' and ''puts''. The program will print two copies of the string ''"Hello, World!"'' using the ''puts'' function. One copy is obtained from ''strdup'', then released with ''free''. The C bindings are placed in an interface module to simplify reuse. The addresses of the two copies are also printed.
 
<langsyntaxhighlight lang="fortran">module c_api
use iso_c_binding
implicit none
Line 801 ⟶ 841:
transfer(ptr, 0_c_intptr_t)
call free(ptr)
end program</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
Normally it's an easy matter to call a function in the C Standard Library, statically, from FreeBASIC.
Line 808 ⟶ 847:
As this uses LocalAlloc in kernel32.dll internally to allocate memory for the duplicated string, we need to call
LocalFree to free this memory using the pointer returned by strdup.
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
'Using StrDup function in Shlwapi.dll
Line 827 ⟶ 866:
DyLibFree(library) '' unload first dll
DyLibFree(library2) '' unload second fll
End</langsyntaxhighlight>
 
{{out}}
<pre>
duplicate
</pre>
 
=={{header|FutureBasic}}==
The C Standary Library doesn't include the strdup() function. In the code below, strdup has been declared, written and executed in C. FB allows users to pass-through and compile C code, while it treating its execution as if it's native FB. That's what been chosen for this example.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
BeginCDeclaration
char *strdup(const char *src);
EndC
 
BeginCFunction
char *strdup(const char *src) {
char *dst = malloc(strlen (src) + 1); // Space for length plus null
if (dst == NULL) return NULL; // No memory
strcpy(dst, src); // Copy the characters
return dst; // Return the new string
}
EndC
 
BeginCCode
NSLog( @"%s", strdup( "Hello, World!" ) );
EndC
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Hello, World!
</pre>
 
=={{header|Go}}==
Using cgo, part of the standard Go command set.
<langsyntaxhighlight lang="go">package main
 
// #include <string.h>
Line 863 ⟶ 931:
// demonstrate we have string contents intact
fmt.Println(go2)
}</langsyntaxhighlight>
Output:
<pre>
hello C
</pre>
=={{header|Hare}}==
<syntaxhighlight lang="hare">// hare run -lc ffi.ha
 
use fmt;
use strings;
 
@symbol("strdup") fn cstrdup(_: *const char) *char;
@symbol("free") fn cfree(_: nullable *void) void;
 
export fn main() void = {
let s = strings::to_c("Hello, World!");
defer free(s);
 
let dup = cstrdup(s);
fmt::printfln("{}", strings::fromc(dup))!;
cfree(dup);
};</syntaxhighlight>
=={{header|Haskell}}==
 
<langsyntaxhighlight Haskelllang="haskell">{-# LANGUAGE ForeignFunctionInterface #-}
 
import Foreign (free)
Line 885 ⟶ 969:
s2_hs <- peekCString s2 -- marshall the C string called s2 into a Haskell string named s2_hs
putStrLn s2_hs
free s2) -- s is automatically freed by withCString once done</langsyntaxhighlight>
 
==Icon and {{header|Unicon}}==
Line 893 ⟶ 977:
The first step is to create a shared library, to wrap the target C functions and do type conversions on the input and returned values. The arguments to the wrapper functions form a list, and this list must be unpacked to retrieve the arguments to send to the target function. To get at <code>strdup</code> and <code>strcat</code> we would have:
 
<syntaxhighlight lang="c">
<lang C>
#include <string.h>
#include "icall.h" // a header routine from the Unicon sources - provides helpful type-conversion macros
Line 912 ⟶ 996:
RetString (result);
}
</syntaxhighlight>
</lang>
 
Then the Unicon program must 'access' the function in the shared library: the important step is 'loadfunc' which accesses the named function in the shared library. After that, the C function can be called from within a program:
 
<syntaxhighlight lang="unicon">
<lang Unicon>
$define LIB "libstrdup-wrapper.so"
 
Line 940 ⟶ 1,024:
write (strcat ("abc", "def"))
end
</syntaxhighlight>
</lang>
 
Output:
Line 948 ⟶ 1,032:
abcdef
</pre>
 
=={{header|J}}==
 
Here is a windows specific implementation (for relatively recent versions of windows):
 
<langsyntaxhighlight Jlang="j">require 'dll'
strdup=: 'msvcrt.dll _strdup >x *' cd <
free=: 'msvcrt.dll free n x' cd <
getstr=: free ] memr@,&0 _1</langsyntaxhighlight>
 
With these definitions:
<langsyntaxhighlight Jlang="j"> getstr@strdup 'Hello World!'
Hello World!</langsyntaxhighlight>
 
Portability is possible, but often irrelevant for a task of this sort. To make this work with a different OS, you would need to use the appropriate file name for libc for the os in question. For example, on linux, replace msvcrt.dll with /lib/libc.so.6 (or whichever version of libc you are using).
 
See also: [http://www.jsoftware.com/help/user/call_procedure.htm J's documentation]
 
=={{header|Java}}==
Java uses JNI to call other languages directly. Because it is a managed language, a "shim" layer needs to be created when dealing with things outside of the managed environment.
Line 972 ⟶ 1,054:
 
'''JNIDemo.java'''
<langsyntaxhighlight lang="java">public class JNIDemo
{
static
Line 983 ⟶ 1,065:
private static native String callStrdup(String s);
}</langsyntaxhighlight>
 
Two things to note: First, the "native" stub which will be linked with a native library, and second, the call to System.loadLibrary to actually do the linking at runtime. The class must then be compiled without the native library.
Line 992 ⟶ 1,074:
 
The generated file, '''JNIDemo.h''':
<langsyntaxhighlight lang="c">/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNIDemo */
Line 1,012 ⟶ 1,094:
}
#endif
#endif</langsyntaxhighlight>
 
Next, the C code which utilizes JNI to bridge between the managed and unmanaged environments. It should include the "h" file, and implement the exported function declared in that file. The specifics of writing JNI code are beyond the scope of this task.
 
'''JNIDemo.c'''
<langsyntaxhighlight lang="c">#include "string.h"
#include "JNIDemo.h"
 
Line 1,060 ⟶ 1,142:
return dupeString;
}
</syntaxhighlight>
</lang>
 
In a Windows environment, a dll by the same name should be created ("JNIDemo.dll"). In a Linux environment, a shared object marked executable and with a name preceded by "lib" should be created (in this case, "libJNIDemo.so"). Your compiler will need to know the location of "jni.h", which is in the "include" directory of the JDK. Linux may also need includes that are in the "include/linux" directory. Linux example using gcc:
Line 1,071 ⟶ 1,153:
Hello World!
</pre>
=={{header|JavaScript}}==
'''Node.js'''
 
Node.js provides the node-api tool to help you create native C or C++ addons.
This example will implement openssl's MD5 function in C++, and create Node.js bindings for it.
 
'''md5sum.cc'''
<syntaxhighlight lang="cpp">#include <napi.h>
#include <openssl/md5.h>
 
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
using namespace Napi;
 
Napi::Value md5sum(const Napi::CallbackInfo& info) {
std::string input = info[0].ToString();
 
unsigned char result[MD5_DIGEST_LENGTH];
MD5((unsigned char*)input.c_str(), input.size(), result);
 
std::stringstream md5string;
md5string << std::hex << std::setfill('0');
for (const auto& byte : result) md5string << std::setw(2) << (int)byte;
return String::New(info.Env(), md5string.str().c_str());
}
 
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "md5sum"),
Napi::Function::New(env, md5sum));
return exports;
}
 
NODE_API_MODULE(addon, Init)</syntaxhighlight>
Then compile the file with [https://github.com/nodejs/node-gyp node-gyp].
<syntaxhighlight lang="bash">node-gyp build</syntaxhighlight>
Once it has compiled, create the JavaScript bindings.
 
'''binding.js'''
<syntaxhighlight lang="javascript">const addon = require('../build/Release/md5sum-native');
 
module.exports = addon.md5sum;</syntaxhighlight>
Then, you're able to call the function from any Node.js JavaScript file.
 
''Using Require:''
<syntaxhighlight lang="javascript">const md5sum = require('../lib/binding.js');
console.log(md5sum('hello'));</syntaxhighlight>
{{out}}
<pre>
5d41402abc4b2a76b9719d911017c592
</pre>
''Using Import:''
 
If you wish to use the ESM import syntax, you need to modify your ''binding.js'' file.
 
'''binding.js'''
<syntaxhighlight lang="javascript">import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const addon = require('../build/Release/md5sum-native');
 
export default addon.md5sum;</syntaxhighlight>
And call the function as follows:
<syntaxhighlight lang="javascript">import md5sum from '../lib/binding.js';
 
console.log(md5sum('hello'));</syntaxhighlight>
{{out}}
<pre>
5d41402abc4b2a76b9719d911017c592
</pre>
Learn more on the Node.js [https://nodejs.org/api/addons.html docs].
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
Julia has a built-in keyword <code>ccall</code> to call external C-like functions. For example:
<langsyntaxhighlight lang="julia">p = ccall(:strdup, Ptr{Cuchar}, (Ptr{Cuchar},), "Hello world")
@show unsafe_string(p) # "Hello world"
ccall(:free, Void, (Ptr{Cuchar},), p)</langsyntaxhighlight>
 
'''PyCall''', [https://github.com/JuliaPy/PyCall.jl source]:
<langsyntaxhighlight lang="julia">using PyCall
@pyimport math
@show math.cos(1) # 0.5403023058681398</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<langsyntaxhighlight lang="scala">// Kotlin Native v0.2
 
import kotlinx.cinterop.*
Line 1,095 ⟶ 1,246:
val hw = strdup ("Hello World!")!!.toKString()
println(hw)
}</langsyntaxhighlight>
 
{{out}}
Line 1,101 ⟶ 1,252:
Hello World!
</pre>
 
=={{header|LabVIEW}}==
Use Connectivity >> Libraries & Executables >> Call Library Function Node to call an external .dll file. This example uses the WinAPI's MessageBoxA function.<br/>{{VI snippet}}<br/>
[[File:LabVIEW Call a foreign-language function.png]]
 
=={{header|Lisaac}}==
Use backtick notation (`...`) for referencing foreign language (C) features.
<langsyntaxhighlight Lisaaclang="lisaac">Section Header
 
+ name := TEST_C_INTERFACE;
Line 1,131 ⟶ 1,280:
// this will also be inserted in-place, expression type disregarded
`free(@p)`;
);</langsyntaxhighlight>
=={{header|Locomotive Basic}}==
WinAPE has a built-in Z80 assembler that can copy the assembled program into the Amstrad CPC's memory. Whatever address your <code>org</code> directive was at can be <code>CALL</code>ed in BASIC.
 
<syntaxhighlight lang="z80">org &1000
ld a,'A'
call &bb5a
ret</syntaxhighlight>
 
{{out}}
<pre>call &1000
A
Ready</pre>
=={{header|Lua}}==
 
Using the [http://luajit.org/ext_ffi.html FFI library] available in [http://luajit.org/ LuaJIT]:
 
<langsyntaxhighlight lang="lua">local ffi = require("ffi")
ffi.cdef[[
char * strndup(const char * s, size_t n);
Line 1,151 ⟶ 1,311:
print("Copy: " .. s2)
print("strlen: " .. ffi.C.strlen(s2))
</syntaxhighlight>
</lang>
 
=={{header|Luck}}==
 
Luck supports interfacing with most C libraries out of the box:
 
<langsyntaxhighlight lang="luck">import "stdio.h";;
import "string.h";;
 
Line 1,163 ⟶ 1,322:
let s2:char* = strdup(cstring(s1));;
puts(s2);;
free(s2 as void*)</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
=== Call C Functions from Dll===
There is a difference between Windows and Wine implementation of _strdump and swprintf.
Value of '''a''' has to hold chars to read from sBuf$ as returned from msvcrt.swprintf, but this can't work in Ubuntu using Wine and in Windows as expected, so we can use '''LeftPart$(string, string as delimiter sign not included as result)'''
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
 
Module CheckCCall {
Line 1,192 ⟶ 1,350:
}
CheckCCall
</syntaxhighlight>
</lang>
 
Output:
Line 1,200 ⟶ 1,358:
===Call VbScript===
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
Global a()
Line 1,244 ⟶ 1,402:
}
CheckIt
</syntaxhighlight>
</lang>
 
===Call Javascript===
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckJavaScript {
Clear
Line 1,301 ⟶ 1,459:
}
CheckJavaScript
</syntaxhighlight>
</lang>
 
 
===Call A System Function (Win32)===
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Declare MessageBox Lib "user32.MessageBoxW" {long alfa, lptext$, lpcaption$, long type}
Print MessageBox(Hwnd, "HELLO THERE", "GEORGE", 2)
Remove "user32"
</syntaxhighlight>
</lang>
 
===Make, use and remove a C Dll at runtime===
H C dll to produce an array of primes. We can
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module checkit {
Static DisplayOnce=0
Line 1,439 ⟶ 1,597:
checkit
 
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
We can call strdup, as requested, in the following way
<langsyntaxhighlight Maplelang="maple">> strdup := define_external( strdup, s::string, RETURN::string, LIB = "/lib/libc.so.6" ):
> strdup( "foo" );
"foo"
</syntaxhighlight>
</lang>
However, this doesn't make a lot of sense in Maple, since there can be only one copy of any Maple string in memory. Moreover, I don't see any easy way to free the memory allocated by strdup. A more sensible example for Maple follows. (It might be sensible if you wanted to compare your system library version of sin with the one built-in to Maple, for instance.)
<langsyntaxhighlight Maplelang="maple">> csin := define_external( sin, s::float[8], RETURN::float[8], LIB = "libm.so" );
csin := proc(s::numeric)
option call_external, define_external(sin, s::float[8],
Line 1,458 ⟶ 1,615:
 
> csin( evalf( Pi / 2 ) );
1.</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
This works on windows and on linux/mac (through Mono)
<langsyntaxhighlight Mathematicalang="mathematica">Needs["NETLink`"];
externalstrdup = DefineDLLFunction["_strdup", "msvcrt.dll", "string", {"string"}];
Print["Duplicate: ", externalstrdup["Hello world!"]]</langsyntaxhighlight>
output
<pre>Duplicate: Hello world!</pre>
Also there is ExternalEvaluate that can call many other languages.
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">/* Maxima is written in Lisp and can call Lisp functions.
Use load("funcs.lisp"), or inside Maxima: */
 
Line 1,478 ⟶ 1,633:
 
f(5, 6);
11</langsyntaxhighlight>
 
=={{header|Mercury}}==
 
Mercury is designed to interact sensibly with foreign code, even while keeping itself as pure and as safe as is possible in such circumstances. Here is an example of calling C's strdup() function from within Mercury:
 
<langsyntaxhighlight lang="mercury">:- module test_ffi.
 
:- interface.
Line 1,506 ⟶ 1,660:
io.write_string(strdup("Hello, worlds!\n"), !IO).
 
:- end_module test_ffi.</langsyntaxhighlight>
 
Only the lines wrapped in comments matter for this. The rest is an application skeleton so this can be compiled and tested.
Line 1,514 ⟶ 1,668:
After this the Mercury strdup/1 function itself is declared. For purposes of exposition it has been declared fully with types and modes. The modes, however, are redundant since by default functions in Mercury have all input parameters and an output return value. Also, the determinism is declared which is again redundant. By default Mercury functions are deterministic. That line could easily have been written thusly instead:
 
<langsyntaxhighlight lang="mercury">:- func strdup(string) = string.</langsyntaxhighlight>
 
The next block of code is the foreign_proc pragma declaration. In this declaration the language ("C") is declared, the footprint of the function is again provided, this time with variable names and modes but without the determinism, a set of properties is declared and the actual C code to be executed is provided. This last piece is trivial, but the properties themselves are worth looking more closely at.
Line 1,521 ⟶ 1,675:
 
Of note is that '''no separate C source file needs to be provided'''. The compiler takes care of putting in all the required boilerplate code necessary to conform to the specifications provided. The resulting code can be treated as much a part of the program as any native Mercury code would be: types, modes, determinism, purity, etc. all managed similarly.
 
=={{header|Modula-2}}==
The first file (Vga.c) creates the function prototypes.
<langsyntaxhighlight lang="c">#include <vga.h>
 
int Initialize (void)
Line 1,591 ⟶ 1,744:
{
*ch = vga_getkey ();
}</langsyntaxhighlight>
The next file is the definition module, but in this context it is called a '''FOREIGN MODULE'''.
<langsyntaxhighlight lang="modula2">FOREIGN MODULE Vga;
 
TYPE EGAcolour = (black, blue, green, cyan, red, pink, brown, white,
Line 1,624 ⟶ 1,777:
PROCEDURE GetKey (VAR ch : CHAR);
 
END Vga.</langsyntaxhighlight>
The third file is an example program.
<langsyntaxhighlight lang="modula2">MODULE svg01;
 
FROM InOut IMPORT Read, Write, WriteBf, WriteString;
Line 1,658 ⟶ 1,811:
Write (ch);
WriteBf;
END svg01.</langsyntaxhighlight>
 
=={{header|Modula-3}}==
Modula-3 provides many predefined interfaces to C files. Here we use <tt>Cstring</tt> which uses C string functions. Note we have to convert strings of type <tt>TEXT</tt> into C strings (NULL terminated character arrays). Also note the code requires the <tt>UNSAFE</tt> keyword because it interfaces with C (which is unsafe).
<langsyntaxhighlight lang="modula3">UNSAFE MODULE Foreign EXPORTS Main;
 
IMPORT IO, Ctypes, Cstring, M3toC;
Line 1,678 ⟶ 1,830:
M3toC.FreeCopiedS(string1);
M3toC.FreeCopiedS(string2);
END Foreign.</langsyntaxhighlight>
Output:
<pre>
string1 # string2
</pre>
 
=={{header|Mosaic}}==
<langsyntaxhighlight lang="mosaic">import clib
 
importdll msvcrt =
Line 1,696 ⟶ 1,847:
str2:=_strdup(&.str)
println str2
end</langsyntaxhighlight>
 
=={{header|Never}}==
Never includes libffi for access to foreign functions, but currently only supports very basic types, int, float, string. ''strdup'' will work, but the ''voidness'' of ''free'' is not yet supported. This solution uses some of the Math functions in libm instead.
 
<langsyntaxhighlight lang="fsharp">extern "libm.so.6" func sinhf(x : float) -> float
extern "libm.so.6" func coshf(x : float) -> float
extern "libm.so.6" func powf(base : float, exp : float) -> float
Line 1,720 ⟶ 1,870:
 
0
}</langsyntaxhighlight>
 
 
Line 1,731 ⟶ 1,881:
1.18
</pre>
 
=={{header|NewLISP}}==
newLISP has two FFI APIs. The simple API needs no type specifiers but is limited to integers and pointers.
The extended API can specify types for return values and parameters and can also be used for floats and structs.
<langsyntaxhighlight NewLISPlang="newlisp">; simple FFI interface on Mac OSX
(import "libc.dylib" "strdup")
(println (get-string (strdup "hello world")))
Line 1,742 ⟶ 1,891:
(import "libc.dylib" "strdup" "char*" "char*")
(println (strdup "hello world"))
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Since Nim compiles to C by default, this task is easily done:
 
<langsyntaxhighlight lang="nim">proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
echo strcmp("abc", "def")
echo strcmp("hello", "hello")
Line 1,754 ⟶ 1,902:
 
var x = "foo"
printf("Hello %d %s!\n", 12, x)</langsyntaxhighlight>
 
=={{header|OCaml}}==
 
===Outline of what is linked against===
For the hypothetical [[C]] library that contains functions described by a header file with this in:
<langsyntaxhighlight lang="ocaml">void myfunc_a();
float myfunc_b(int, float);
char *myfunc_c(int *, int);</langsyntaxhighlight>
 
The header file is named "<tt>mylib.h</tt>", and linked against the library with <tt>-lmylib</tt> and compiled with <tt>-I/usr/include/mylib</tt>.
Line 1,769 ⟶ 1,916:
 
====file "mylib.ml":====
<langsyntaxhighlight lang="ocaml">external myfunc_a: unit -> unit = "caml_myfunc_a"
external myfunc_b: int -> float -> float = "caml_myfunc_b"
external myfunc_c: int array -> string = "caml_myfunc_c"</langsyntaxhighlight>
 
====file "wrap_mylib.c":====
<langsyntaxhighlight lang="c">#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <mylib.h>
Line 1,803 ⟶ 1,950:
free(arr);
return caml_copy_string(s);
}</langsyntaxhighlight>
 
====the Makefile:====
(replace spaces by tabs)
<langsyntaxhighlight lang="makefile">wrap_mylib.o: wrap_mylib.c
ocamlc -c -ccopt -I/usr/include/mylib $<
 
Line 1,832 ⟶ 1,979:
 
clean:
rm -f *.[oa] *.so *.cm[ixoa] *.cmxa</langsyntaxhighlight>
 
the file <tt>mylib.cma</tt> is used for the interpreted and bytecode modes, and <tt>mylib.cmxa</tt> is for the native mode.
Line 1,841 ⟶ 1,988:
There is another solution for calling C functions from a C library which is to use '''ocaml-ctypes'''. We can then define bindings by writing only OCaml code without any C stubs. The equivalent for wrapping the previous hypothetical [[C]] library will be:
 
<langsyntaxhighlight lang="ocaml">open Ctypes
open Foreign
 
Line 1,851 ⟶ 1,998:
let arr = CArray.of_list int lst in
myfunc_c (to_voidp (CArray.start arr)) (CArray.length arr)
;;</langsyntaxhighlight>
 
=={{header|Ol}}==
<langsyntaxhighlight lang="scheme">
(import (otus ffi))
 
Line 1,861 ⟶ 2,007:
 
(print (strdup "Hello World!"))
</syntaxhighlight>
</lang>
 
Windows has no a "strdup" function, so windows version should look like this.
<langsyntaxhighlight lang="scheme">
(import (otus ffi))
 
Line 1,874 ⟶ 2,020:
 
(print (strdup "Hello World!"))
</syntaxhighlight>
</lang>
 
Note: this simplest way is not freeing allocated by "strdup" function string.
 
Ol provides a way to call ol functions directly from native code (means callbacks).
<langsyntaxhighlight lang="scheme">
; The sample usage of GTK3+ library
(import (otus ffi)
Line 1,914 ⟶ 2,060:
 
(g_application_run app 0 #false)
</syntaxhighlight>
</lang>
 
=={{header|Odin}}==
 
<syntaxhighlight lang="odin">package main
 
import "core:fmt"
 
foreign import libc "system:c"
 
@(default_calling_convention="c")
foreign libc {
@(link_name="strdup") cstrdup :: proc(_: cstring) -> cstring ---
@(link_name="free") cfree :: proc(_: rawptr) ---
}
 
main :: proc() {
s1 : cstring = "hello"
s2 := cstrdup(s1)
fmt.printf("{}\n", s2)
cfree(rawptr(s2))</syntaxhighlight>
 
=={{header|Oz}}==
First we need to create a so-called "native functor" that converts the arguments and describes the C functions:
<langsyntaxhighlight lang="cpp">#include "mozart.h"
#include <string.h>
 
Line 1,938 ⟶ 2,104:
};
return table;
}</langsyntaxhighlight>
 
Save this file as "strdup.cc". To automate compiling and linking, we need a makefile for <code>ozmake</code>, the Oz build tool. Save this file as "makefile.oz":
<langsyntaxhighlight lang="oz">makefile(
lib : [
'strdup.o' 'strdup.so'
]
rules:o('strdup.so':ld('strdup.o'))
)</langsyntaxhighlight>
Call <code>ozmake</code> in the same directory.
 
Now we can write some code that uses the wrapped C function (make sure Emacs' working directory is set to the same directory):
 
<langsyntaxhighlight lang="oz">declare
[Strdup] = {Module.link ['strdup.so{native}']}
in
{System.showInfo {Strdup.strdup "hello"}}</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
Of course it is trivial to include C functions in PARI, and not uncommon. C++ functions are similar, as PARI is written in a C++-friendly style. The <code>system</code> and <code>install</code> commands allow foreign-language functions to be called from within gp.
 
=={{header|Pascal}}==
See [[Call_a_foreign-language_function#Delphi | Delphi]]
 
=={{header|Perl}}==
Perl code calls a C function <code>c_dup()</code> passing a string <code>'Hello'</code> as an argument, which gets transparently converted to a C string, the <code>c_dup()</code> function makes a copy of that string using <code>strdup()</code> function, stores pointer to the copy in the <code>copy</code> variable and returns it. The returned <code>char</code> pointer gets converted transparently to a Perl string value and gets returned to the calling Perl code which prints it. Then the Perl code calls a C function <code>c_free()</code> to free the allocated memory. Both of the C functions are defined inline in the Perl program and are automatically compiled (only once, unless they change) and linked at runtime. Here is the entire program:
<langsyntaxhighlight lang="perl">use Inline C => q{
char *copy;
char * c_dup(char *orig) {
Line 1,974 ⟶ 2,137:
};
print c_dup('Hello'), "\n";
c_free();</langsyntaxhighlight>
 
Another example, instead of returning the copy to Perl code it prints it using C printf:
<langsyntaxhighlight lang="perl">use Inline C => q{
void c_hello (char *text) {
char *copy = strdup(text);
Line 1,984 ⟶ 2,147:
}
};
c_hello 'world';</langsyntaxhighlight>
 
=={{header|Phix}}==
The foreign language functions must be compiled to .dll (or .so) form.<br>
Line 1,991 ⟶ 2,153:
a library component which can be re-used in different applications.<br>
See also builtins/cffi.e, a text-based C interface that handles C-style structs, unions, and function declarations directly.
<!--<syntaxhighlight lang="phix">(notonline)-->
<lang Phix>constant shlwapi = open_dll("shlwapi.dll")
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- not from a browser, mate!</span>
constant xStrDup = define_c_func(shlwapi,"StrDupA",{C_PTR},C_PTR)
<span style="color: #008080;">constant</span> <span style="color: #000000;">shlwapi</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_dll</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"shlwapi.dll"</span><span style="color: #0000FF;">),</span>
constant kernel32 = open_dll("kernel32.dll")
<span style="color: #000000;">kernel32</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_dll</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"kernel32.dll"</span><span style="color: #0000FF;">)</span>
constant xLocalFree = define_c_func(kernel32,"LocalFree",{C_PTR},C_PTR)
<span style="color: #008080;">constant</span> <span style="color: #000000;">xStrDup</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">define_c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">shlwapi</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"StrDupA"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">C_PTR</span><span style="color: #0000FF;">},</span><span style="color: #000000;">C_PTR</span><span style="color: #0000FF;">),</span>
constant HelloWorld = "Hello World!"
<span style="color: #000000;">xLocalFree</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">define_c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">kernel32</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"LocalFree"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">C_PTR</span><span style="color: #0000FF;">},</span><span style="color: #000000;">C_PTR</span><span style="color: #0000FF;">)</span>
 
<span style="color: #008080;">constant</span> <span style="color: #000000;">HelloWorld</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Hello World!"</span>
atom pMem = c_func(xStrDup,{HelloWorld})
?peek_string(pMem)
<span style="color: #004080;">atom</span> <span style="color: #000000;">pMem</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xStrDup</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">HelloWorld</span><span style="color: #0000FF;">})</span>
if c_func(xLocalFree,{pMem})!=NULL then ?9/0 end if</lang>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">peek_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pMem</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xLocalFree</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">pMem</span><span style="color: #0000FF;">})==</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
"Hello World!"
</pre>
=={{header|PHP}}==
{{works with|PHP|7.4}}
 
PHP 7.4+ has as support to call external C-like functions using extension . See this Windows example:
<syntaxhighlight lang="php">$ffi = FFI::cdef("char *_strdup(const char *strSource);", "msvcrt.dll");
 
$cstr = $ffi->_strdup("success");
$str = FFI::string($cstr);
echo $str;
FFI::free($cstr);
</syntaxhighlight>
=={{header|PicoLisp}}==
The easiest is to inline the C code. Another possibility would be to write it
Line 2,014 ⟶ 2,189:
 
===32-bit version===
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/gcc.l")
 
(gcc "str" NIL # The 'gcc' function passes all text
Line 2,032 ⟶ 2,207:
/**/
 
(println 'Duplicate (duptest "Hello world!"))</langsyntaxhighlight>
===64-bit version===
<syntaxhighlight lang="c">
<lang C>
/*
How to create the shared lib/so file:
Line 2,055 ⟶ 2,230:
int main() {
}
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="picolisp">
<lang PicoLisp>
(prinl "Calling custom so/dll library...")
(set 'A NIL)
Line 2,063 ⟶ 2,238:
(prinl "A=" A)
(when (not (= A NIL)) (prinl "Success!"))
</syntaxhighlight>
</lang>
 
<out>
Line 2,072 ⟶ 2,247:
</pre>
</out>
 
=={{header|PL/I}}==
<syntaxhighlight lang="text">declare strdup entry (character (30) varyingz) options (fastcall16);
 
put (strdup('hello world') );</lang>
 
put (strdup('hello world') );</syntaxhighlight>
=={{header|Prolog}}==
In SWI-Prolog we need to do two things. First we need to declare a mapping from a Prolog file to a C implementation:
 
<langsyntaxhighlight lang="prolog">:- module(plffi, [strdup/2]).
:- use_foreign_library(plffi).</langsyntaxhighlight>
 
This declares a module "plffi" that exports the '''predicate''' (''not'' function!) "strdup/2". This predicate has two arguments: the first being the atom being strduped, the second being the duped atom. (You can think of these as an in parameter and an out parameter and be about 2/3 right.)
Line 2,088 ⟶ 2,261:
Then we need to write a C file that gives us the interface to the underlying C function (strdup in this case), mapping the ''predicate''' call to a C '''function''' call:
 
<langsyntaxhighlight lang="c">#include <string.h>
#include <stdio.h>
#include <SWI-Prolog.h>
Line 2,107 ⟶ 2,280:
{
PL_register_foreign("strdup", 2, pl_strdup, 0);
}</langsyntaxhighlight>
 
This C code provides us with two things. The function install_plffi() is provided to register the name "strdup" and to map it to its C implementation pl_strdup(). Here we're saying that "strdup" has an arity of 2, is implemented by pl_strdup and has no special flags.
Line 2,115 ⟶ 2,288:
We compile this very easily:
 
<langsyntaxhighlight lang="sh">$ swipl-ld -o plffi -shared plffi.c</langsyntaxhighlight>
 
Then, from within the SWI-Prolog interactor:
 
<langsyntaxhighlight Prologlang="prolog">?- [plffi].
% plffi compiled into plffi 0.04 sec, 1,477 clauses
true.
Line 2,133 ⟶ 2,306:
 
?- X = booger, strdup(booger, X).
X = booger.</langsyntaxhighlight>
 
=={{header|PureBasic}}==
Here we will use [http://flatassembler.net/ Fasm (flat assembler)] to create an object file and then import the function
Line 2,140 ⟶ 2,312:
the resulting executable. [http://www.purebasic.com/ PureBasic] supports {Windows, Linux, MacOS}.
 
<syntaxhighlight lang="purebasic">
<lang PureBasic>
; Call_a_foreign_language_function.fasm -> Call_a_foreign_language_function.obj
; the assembler code...
Line 2,180 ⟶ 2,352:
 
public strucase as "_strucase@4"
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="purebasic">
<lang PureBasic>
; the PureBasic code...
 
Line 2,193 ⟶ 2,365:
; cw(peeks(*r))
Debug peeks(*r)
</syntaxhighlight>
</lang>
 
 
Line 2,200 ⟶ 2,372:
HELLO WORLD!!
</pre>
 
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">import ctypes
libc = ctypes.CDLL("/lib/libc.so.6")
libc.strcmp("abc", "def") # -1
libc.strcmp("hello", "hello") # 0</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket/base
(require ffi/unsafe)
Line 2,251 ⟶ 2,421:
;; Let's try it:
(strdup "Hello World!")
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2016.07}}
<syntaxhighlight lang="raku" perl6line>use NativeCall;
 
sub strdup(Str $s --> Pointer) is native {*}
Line 2,264 ⟶ 2,433:
my $p = strdup("Success!");
say 'puts returns ', puts($p);
say 'free returns ', free($p);</langsyntaxhighlight>
{{out}}
<pre>Success!
puts returns 9
free returns 0</pre>
 
=={{header|REALbasic}}==
<syntaxhighlight lang="vb">
<lang vb>
Declare Function CreateFileW Lib "Kernel32" (FileName As WString, DesiredAccess As Integer, ShareMode As Integer, SecurityAttributes As Integer, _
CreateDisposition As Integer, Flags As Integer, Template As Integer) As Integer
Line 2,294 ⟶ 2,462:
MsgBox("Error Number: " + Str(GetLastError))
End If
</syntaxhighlight>
</lang>
 
=={{header|REXX}}==
The use of the &nbsp; '''address''' &nbsp; statement isn't normally required, but it's shown here as an illustrative example.
<langsyntaxhighlight lang="rexx">/*REXX program calls (invoke) a "foreign" (non-REXX) language routine/program. */
 
cmd = "MODE" /*define the command that is to be used*/
Line 2,305 ⟶ 2,472:
address 'SYSTEM' cmd opts /*invoke a cmd via the SYSTEM interface*/
 
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when executing under a Microsoft Windows system in the USA, &nbsp; code pages vary upon the country:}}
<pre>
Line 2,312 ⟶ 2,479:
Code page: 437
</pre>
 
=={{header|Ruby}}==
 
Line 2,324 ⟶ 2,490:
 
{{works with|MRI}}
<langsyntaxhighlight lang="c">/* rc_strdup.c */
#include <stdlib.h> /* free() */
#include <string.h> /* strdup() */
Line 2,357 ⟶ 2,523:
VALUE mRosettaCode = rb_define_module("RosettaCode");
rb_define_module_function(mRosettaCode, "strdup", rc_strdup, 1);
}</langsyntaxhighlight>
 
<langsyntaxhighlight lang="ruby"># extconf.rb
require 'mkmf'
create_makefile('rc_strdup')</langsyntaxhighlight>
 
<langsyntaxhighlight lang="ruby"># demo.rb
require 'rc_strdup'
puts RosettaCode.strdup('This string gets duplicated.')</langsyntaxhighlight>
 
=== FFI ===
Line 2,371 ⟶ 2,537:
A recent effort to make it easier to write libraries, portable across platforms and interpreters, led to the creation of a [http://sourceware.org/libffi/ libffi] binding simply called [http://wiki.github.com/ffi/ffi/ ffi] for completely dynamic calls.
 
<langsyntaxhighlight lang="ruby">
require 'ffi'
 
Line 2,386 ⟶ 2,552:
puts duplicate.get_string(0)
LibC.free(duplicate)
</syntaxhighlight>
</lang>
 
 
Line 2,394 ⟶ 2,560:
 
{{works with|Ruby|2.0+}}
<langsyntaxhighlight lang="ruby">require 'fiddle'
 
# Find strdup(). It takes a pointer and returns a pointer.
Line 2,406 ⟶ 2,572:
duplicate = strdup.call("This is a string!")
puts duplicate.to_s # Convert the C string to a Ruby string.
Fiddle.free duplicate # free() the memory that strdup() allocated.</langsyntaxhighlight>
 
Fiddle::Importer is also part of Ruby's standard library.
 
{{works with|Ruby|2.0+}}
<langsyntaxhighlight lang="ruby">require 'fiddle'
require 'fiddle/import'
 
Line 2,422 ⟶ 2,588:
duplicate = C.strdup("This is a string!")
puts duplicate.to_s
Fiddle.free duplicate</langsyntaxhighlight>
 
=== RubyInline ===
Line 2,428 ⟶ 2,594:
Using {{libheader|RubyGems}} package [http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline], which compiles the inlined code on demand during runtime.
 
<langsyntaxhighlight lang="ruby">require 'rubygems'
require 'inline'
 
Line 2,460 ⟶ 2,626:
t = InlineTester.new
11.upto(14) {|n| p [n, t.factorial_ruby(n), t.factorial_c(n)]}
p t.my_ilogb(1000)</langsyntaxhighlight>
 
outputs (note Ruby's implicit use of Bignum past 12!, while C is stuck with a long int):
Line 2,468 ⟶ 2,634:
[14, 87178291200, 1278945280]
9</pre>
 
=={{header|Rust}}==
 
<langsyntaxhighlight lang="rust">extern crate libc;
 
//c function that returns the sum of two integers
Line 2,483 ⟶ 2,648:
add_input(in1, in2) };
assert!( (output == (in1 + in2) ),"Error in sum calculation") ;
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">object JNIDemo {
try System.loadLibrary("JNIDemo")
 
Line 2,492 ⟶ 2,656:
 
println(callStrdup("Hello World!"))
}</langsyntaxhighlight>
=={{header|Smalltalk}}==
The way external functions are declared is different among Smalltalk dialects. However, there are not many situations where you'd need them (and especially not for simple things like strdup).
 
{{works with | Smalltalk/X}}
<langsyntaxhighlight Smalltalklang="smalltalk">Object subclass:'CallDemo'!
!CallDemo class methods!
strdup:arg
Line 2,503 ⟶ 2,667:
! !
 
Transcript showCR:( CallDemo strdup:'Hello' )</langsyntaxhighlight>
 
=={{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}}==
Line 2,513 ⟶ 2,692:
As an example let's build a '''[https://en.wikipedia.org/wiki/Hilbert_matrix Hilbert matrix]''' in C.
 
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include "stplugin.h"
 
Line 2,526 ⟶ 2,705:
}
return 0;
}</langsyntaxhighlight>
 
The DLL can be built from '''Visual Studio''', or in the console with <code>cl /LD hilbertmat.c stplugin.c</code>. With '''MinGW''', compile with <code>gcc -shared stplugin.c hilbertmatrix.c -o hilbertmat.plugin</code>. With '''Pelles C''', compile with <code>cc /Tx64-coff /Ze stplugin.c hilbertmat.c /DLL /OUT:hilbertmat.plugin</code>. The DLL must be renamed with the '''.plugin''' extension, and put in a directory visible in [https://www.stata.com/help.cgi?adopath adopath].
Line 2,532 ⟶ 2,711:
Declare also an ADO file to call the plugin:
 
<langsyntaxhighlight lang="stata">program hilbert
matrix define `1'=J(`2',`2',0)
plugin call hilbertmat, `1' `2'
end
 
program hilbertmat, plugin</langsyntaxhighlight>
 
Then, you may call
 
<langsyntaxhighlight lang="stata">. hilbert mymat 4
 
. matrix list mymat
Line 2,550 ⟶ 2,729:
r2 .5 .33333333
r3 .33333333 .25 .2
r4 .25 .2 .16666667 .14285714</langsyntaxhighlight>
 
Notice the program as is has minimal protection against invalid arguments. Production code should be more careful.
Line 2,559 ⟶ 2,738:
As an example let's build a '''[https://en.wikipedia.org/wiki/Hilbert_matrix Hilbert matrix]''' in Java.
 
<langsyntaxhighlight lang="java">import com.stata.sfi.*;
 
public class HilbertMatrix {
Line 2,574 ⟶ 2,753:
return 0;
}
}</langsyntaxhighlight>
 
Compile with <code>javac -cp %STATA%\utilities\jar\sfi-api.jar HilbertMatrix.java</code>, assuming %STATA% is the path to the Stata install directory.
Line 2,580 ⟶ 2,759:
In Stata, assuming HilbertMatrix.class resides in K:\java:
 
<langsyntaxhighlight lang="stata">. javacall HilbertMatrix run, classpath(K:\java) args(mymat 4)
 
. matrix list mymat
Line 2,589 ⟶ 2,768:
r2 .5 .33333333
r3 .33333333 .25 .2
r4 .25 .2 .16666667 .14285714</langsyntaxhighlight>
 
Notice that Mata has the builtin function '''[https://www.stata.com/help.cgi?mf_Hilbert Hilbert]''' to do the same:
 
<langsyntaxhighlight lang="stata">. mata: Hilbert(4)
[symmetric]
1 2 3 4
Line 2,601 ⟶ 2,780:
3 | .3333333333 .25 .2 |
4 | .25 .2 .1666666667 .1428571429 |
+---------------------------------------------------------+</langsyntaxhighlight>
 
=={{header|Swift}}==
Because Swift uses the Objective-C runtime it is trivial to call C/Objective-C functions directly in Swift.
<langsyntaxhighlight Swiftlang="swift">import Foundation
 
let hello = "Hello, World!"
let fromC = strdup(hello)
let backToSwiftString = String.fromCString(fromC)</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{libheader|critcl}}
In this solution, we wrap up the <code>ilogb</code> function from C's math library with critcl so that it becomes one of Tcl's normal functions (assuming Tcl 8.5):
<langsyntaxhighlight lang="tcl">package require critcl
critcl::code {
#include <math.h>
Line 2,621 ⟶ 2,798:
return ilogb(value);
}
package provide ilogb 1.0</langsyntaxhighlight>
Note that we do not show <code>strdup</code> here because Tcl manages the memory for strings in complex ways and does not guarantee to preserve string pointers from one call into the C API to the next (e.g., if it has to apply an encoding transformation behind the scenes).
<!-- TODO: a basic thunk, and show off using SWIG -->
 
=={{header|TXR}}==
 
Line 2,640 ⟶ 2,816:
 
There is no way to use the <code>str</code> family of types, yet do manual memory management; FFI manages automatically. Code that wants to manually manage a foreign resource referenced by pointer should use <code>cptr</code> or <code>carray</code>, depending on required semantics.
 
=={{header|V (Vlang)}}==
Note: Vlang also has a C2V transpiler.
<syntaxhighlight lang="vlang">
#include "stdlib.h"
#include "string.h"
 
// Declare C functions that will be used.
fn C.strdup(txt &char) &char
fn C.strcat(dest &char, src &char) &char
 
fn main() {
txt_1 := "Hello World!"
txt_2 := " Let's Wish for Peace!"
// Memory-unsafe operations must be marked as such (unsafe {...}), or won't compile.
unsafe {
dup := C.strdup(txt_1.str)
println('${cstring_to_vstring(dup)}')
addto := C.strcat(dup, txt_2.str)
println('${cstring_to_vstring(addto)}')
 
// Must manually free memory or program can hang because unsafe.
free(dup)
free(addto)
}
exit(0)
}
</syntaxhighlight>
 
{{out}}
<pre>
Hello World!
Hello World! Let's Wish for Peace!
</pre>
 
=={{header|Wren}}==
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_a_foreign-language_function.wren */
<lang ecmascript>/* call_foreign_language_function.wren */
 
class C {
Line 2,651 ⟶ 2,862:
 
var s = "Hello World!"
System.print(C.strdup(s))</langsyntaxhighlight>
 
which we embed in the following C program and run it.
 
Note that it's safe to free the pointer returned by strdup after passing it to Wren because wrenSetSlotString copies the C string to a new String object managed by Wren’s garbage collector.
<langsyntaxhighlight Clang="c">#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Line 2,722 ⟶ 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,738 ⟶ 2,949:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 2,748 ⟶ 2,959:
===UASM 2.52===
Calling C functions in Assembly is trivial at best. It's not anymore complicated than using them in C itself. Strdup for example..
<langsyntaxhighlight lang="asm">
option casemap:none
 
Line 2,779 ⟶ 2,990:
;main endp
;end
</syntaxhighlight>
</lang>
====Lua====
Using the liblua that comes with Lua 5.2(?). Assembling is the same as always, Link with a -llua using clang or gcc.
<langsyntaxhighlight lang="asm">
option casemap:none
 
Line 3,029 ⟶ 3,240:
 
end
</syntaxhighlight>
</lang>
Addition.lua
<langsyntaxhighlight lang="lua">
function addition(a, b)
print('---> Lua calc: ' .. a .. ' + ' .. b .. ' = ' .. a+b)
return a + b
end
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,050 ⟶ 3,261:
===NASM===
{{trans|Wren}}
So yeah. This inits Wrens WMVM in Assembly to call strdup in C. Now PIE(Position independent executable) compliant.
<langsyntaxhighlight lang="asm">
;; Libc libc stuff..
extern printf
extern exit
extern malloc
extern free
extern fopen
extern fclose
extern fread
extern fseek
extern ftell
extern rewind
 
;; Wren importsstuff..
extern wrenNewVM
extern wrenInterpret
extern wrenFreeVM
extern wrenGetSlotString
extern wrenSetSlowStringwrenSetSlotString
extern wrenInitConfiguration
 
%define WREN_RESULT_SUCCESS 0
;; Our C function
%define WREN_RESULT_COMPILE_ERROR 1
%define WREN_RESULT_RUNTIME_ERROR 2
 
;; Stuff...
extern C_strdup
 
;; time saver 'macros' for PIC(mmm, PIE..)
;; Wren Interpret results
;; These Macros basically end up being exactly what they look
%assign WREN_RESULT_SUCCESS 0
;; like in code, there's very little preprocessing in NASM,
%assign WREN_RESULT_COMPILE_ERROR 1
;; unlike M/UASM's macro systems.(Still more than Gas doe..)
%assign WREN_RESULT_RUNTIME_ERROR 2
%macro xlea 2
lea %1, [rel %2]
%endmacro
 
%macro xcall 1
call [rel %1 wrt ..got]
%endmacro
 
section .bss
wrenConfig resb 84
WrenConfig resb 84 ;; The config struct is 84 bytes(10qwords(8 bytes), 1dword(4 bytes))
WrenVMwrenVM resq 1 ;; wren VM handle
 
section .rodata
;; Messages and shit..
szmsg db "--> Starting and configuring WrenVM",10,0
vm_err_strsznoargs db "--> Returned! anNo error",10,"-->args passed. ErrorSupply number:a %dfilename.",10,0
sznofile db "--> ! Invaild file passed.",10,0
 
modszothererr db "--> ! Wren Error, check db "mainscript...",10,0
msg szmod db "--> %smain",0
pfmt db "%s",0
 
szread db "r",0 ;; Why does this have to be a string? Seriously.
;; Hard coded wren script..
;; If you care that much, write a filereader yaself T_T
c_strdup_wren db 'class C {',10
db ' foreign static strdup(s)',10
db '}',10
db 'var s = "Hello World!"',10
db 'System.print(C.strdup(s))',10
 
;; Let this freakshow begin...
section .text
global main
Line 3,099 ⟶ 3,322:
push rbp
mov rbp, rsp
leasub rdirsp, szmsg16
cmp edi, 1 ;; argc
call printf
jle _main_noargs ;; if(argc <= 1)
lea rdi, WrenConfig
mov rax, qword [rsi+1*8] ;; argv[1] - dun dun dunnnn
call wrenInitConfiguration
leamov raxqword [rbp-8], WrenConfigrax
leaxlea rbxrdi, bindfuncszmsg
xcall printf
mov qword [rax+24], rbx ;; wrenconfig.WrenBindForeignMethodFn
leaxlea rbxrdi, writefnwrenConfig
xcall wrenInitConfiguration
mov qword [rax+40], rbx ;; wrenconfig.WrenWriteFn
leaxlea rbxrax, errfnwrenConfig
xlea rbx, bindfn
mov qword [rax+48], rbx ;; wrenconfig.WrenErrorFn
mov qword [rax+24], rbx ;; wrenconfig.WrenBindForeignFn
lea rdi, WrenConfig
callxlea wrenNewVMrbx, writefn
mov qword [rax+40], rbx ;; wrenconfig.WrenWriteFn
mov [WrenVM], rax
xlea rbx, errfn
lea rdx, c_strdup_wren ;; script
leamov rsiqword [rax+48], mod rbx ;; modulewrenconfig.WrenErrorFn
movxlea rdi, [WrenVM] ;; WrenVM wrenConfig
callxcall wrenInterpretwrenNewVM
mov [rel wrenVM], rax
mov rdi, qword [rbp-8]
call srcread
mov qword [rbp-16], rax ;; char *wrenScript;
mov rdx, qword [rbp-16]
xlea rsi, szmod
mov esi, 0
mov rdi, [rel wrenVM]
xcall wrenInterpret
cmp rax, WREN_RESULT_SUCCESS
jg _main_noargs
jg _wrenvm_err ;; if > RESULT_SUCCESS = error.
jmp _exit ;; Time to gtfo.
 
jmp _main_exit ;; Let's gtfo of dodge.
_wrenvm_err:
mov rsi, rax
_main_noargs:
lea rdi, vm_err_str
callxlea printfrdi, sznoargs
xcall printf
 
;; At this point we should free the mem but
_exit:
;; the program ends so who gives a ....
mov rdi, [WrenVM]
_main_exit:
call wrenFreeVM
movadd raxrsp, 016
pop rbp
xor rdi, rdi
callxcall exit
ret
 
;; We only care about the file name once, So.. No keepy keepy.
srcread:
push rbp
mov rbp, rsp
sub rsp, 32
xlea rsi,szread
xcall fopen
cmp rax, 0
jle _srcread_nofile
mov qword [rbp-8], rax ;; file handle.
mov edx, 2 ;; SEEK_END
mov esi, 0
mov rdi, qword [rbp-8]
xcall fseek
mov rdi, qword [rbp-8]
xcall ftell
mov qword [rbp-16], rax
mov rdi, qword [rbp-8]
xcall rewind
mov rax, qword [rbp-16]
add rax, 1
mov rdi, rax
xcall malloc
mov qword [rbp-24], rax
mov rcx, qword [rbp-8] ;; file handle
mov rdx, qword [rbp-16] ;; size
mov esi, 1
mov rdi, qword [rbp-24] ;; buffer
xcall fread
mov rdi, qword [rbp-8]
xcall fclose
mov rcx, qword [rbp-16]
mov rax, qword [rbp-24]
add rax, rcx
mov byte [rax], 0
jmp _srcread_exit
 
_srcread_nofile:
xlea rdi, sznofile
xcall printf
 
_srcread_exit:
mov rax, qword [rbp-24]
add rsp, 32
pop rbp
ret
 
;; Just prints whatever's given to it's one argument.
;;Callback functions for the WrenVM
;; writefn(rdi, rsi) - WrenVM isn't used so just overwrite it.
writefn:
push rbp
mov rbp, rsp
leaxlea rdi, msgpfmt
callxcall printf
pop rbp
ret
 
;; Just print generic message and return the error number
errfn:
push rbp
mov rbp, rsp
movxlea rdi, vm_err_strszothererr
callxcall printf
mov rax, 0
pop rbp
ret
 
;; Still to lazy to do those if checks... -.-
bindfunc:
;; I'll do it properly one day, I promise. :]
push rbp
bindfn:
mov rbp, rsp
push rbp
lea rax, C_strdup
mov rbp, pop rbprsp
xlea rax, retC_strdup
pop rbp
</lang>
ret
<lang c>
 
</syntaxhighlight>
strdup.wren
<syntaxhighlight lang="wren">
class C {
foreign static strdup(s)
}
var s = "Goodbye, World!"
System.print(C.strdup(s))
</syntaxhighlight>
strdup.c
<syntaxhighlight lang="c">
void free( void* ptr );
char * strdup( const char *str1 );
Line 3,176 ⟶ 3,464:
free(t);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
--> Starting and configuring WrenVM
--> HelloGoodbye, World!
</pre>
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
const c = @cImport({
@cInclude("stdlib.h"); // `free`
@cInclude("string.h"); // `strdup`
});
 
pub fn main() !void {
const string = "Hello World!";
var copy = c.strdup(string);
 
try std.io.getStdOut().writer().print("{s}\n", .{copy});
c.free(copy);
}</syntaxhighlight>
=={{header|zkl}}==
In my opinion, FFIs are very problematic and it is better, if you really need external functionality, to spend the effort to write a glue library. Certainly a lot more work. And it only works for C or C++.
Line 3,189 ⟶ 3,490:
 
flf.c:
<langsyntaxhighlight lang="c">//-*-c-*-
// flf.c, Call a foreign-language function
 
Line 3,224 ⟶ 3,525:
}
return methodCreate(Void,0,zkl_strlen,vm);
}</langsyntaxhighlight>
In use on Linux:
{{out}}
Line 3,239 ⟶ 3,540:
3
</pre>
{{omit from|360 Assembly|A CPU only understands its own machine language. So no assembly language can do this.}}
 
{{omit from|6502 Assembly}}
 
{{omit from|8051 Assembly}}
{{omit from|8080 Assembly}}
{{omit from|8086 Assembly}}
{{omit from|68000 Assembly}}
{{omit from|AArch64 Assembly}}
{{omit from|ARM Assembly}}
{{omit from|Batch File|Can only execute other programs but cannot call arbitrary functions elsewhere.}}
{{omit from|GUISS}}
{{omit from|M4}}
{{omit from|MIPS Assembly}}
{{omit from|ML/I}}
{{omit from|Order|Doesn't allow to call functions from other languages.}}
Line 3,250 ⟶ 3,558:
{{omit from|TI-89 BASIC|Does not have a standard FFI.}}
{{omit from|Unlambda|Doesn't allow to call functions from other languages.}}
{{omit from|x86 Assembly}}
{{omit from|Z80 Assembly}}
23

edits