Call a foreign-language function: Difference between revisions

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 "str" NIL
gcc -c -Wall (duptest-Werror (Str)-fPIC duptest 'S Str) ).c
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() {
(println 'Duplicate (duptest "Hello world!"))</lang>
}
</lang>
 
<lang PicoLisp>(load "@lib/native.l")
(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>
Output in both cases:
<pre>
<pre>Duplicate "Hello world!"</pre>
Calling custom so/dll library...
A=abc
Success!
</pre>
</out>
 
=={{header|PL/I}}==
Anonymous user