Anonymous user
Call a foreign-language function: Difference between revisions
→64-bit version
m (→{{header|REXX}}: changed wording in the output section header.) |
|||
Line 1,980:
(println 'Duplicate (duptest "Hello world!"))</lang>
===64-bit version===
<lang C>
<lang PicoLisp>(load "@lib/native.l")▼
How to create the shared lib/so file:
gcc -c -Wall
gcc -shared -o duptest.so duptest.o -Wno-undef
*/
#include <stdlib.h>
#include <string.h>
extern char * duptest(char * str)
static char *s;▼
char * duptest(char * str) {
▲ static char * s;
free(s); // We simply dispose the result of the last call
return s = strdup(str);
}
▲/**/
int main() {
}
</lang>
(prinl "Calling custom so/dll library...")
(set 'A NIL)
(set 'A (native "./duptest.so" "duptest" 'S "abc"))
(prinl "A=" A)
(when (not (= A NIL)) (prinl "Success!"))
</lang>
<out>
<pre>
Calling custom so/dll library...
A=abc
Success!
</pre>
</out>
=={{header|PL/I}}==
|