Call a function in a shared library: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
m (→{{header|Wren}}: Capitalize Wren & C file names.) |
||
Line 2,079: | Line 2,079: | ||
{{trans|C}} |
{{trans|C}} |
||
An embedded program so we can ask the C host to call the shared library function for us. |
An embedded program so we can ask the C host to call the shared library function for us. |
||
<syntaxhighlight lang="wren">/* |
<syntaxhighlight lang="wren">/* Call_a_function_in_a_shared_library.wren */ |
||
var RTLD_LAZY = 1 |
var RTLD_LAZY = 1 |
||
Line 2,120: | Line 2,120: | ||
<br> |
<br> |
||
Finally, we embed the Wren script in the following C program, compile and run it: |
Finally, we embed the Wren script in the following C program, compile and run it: |
||
<syntaxhighlight lang="c">/* gcc |
<syntaxhighlight lang="c">/* gcc Call_a_function_in_a_shared_library.c -o Call_a_function_in_a_shared_library -ldl -lwren -lm */ |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 2,219: | Line 2,219: | ||
WrenVM* vm = wrenNewVM(&config); |
WrenVM* vm = wrenNewVM(&config); |
||
const char* module = "main"; |
const char* module = "main"; |
||
const char* fileName = " |
const char* fileName = "Call_a_function_in_a_shared_library.wren"; |
||
char *script = readFile(fileName); |
char *script = readFile(fileName); |
||
WrenInterpretResult result = wrenInterpret(vm, module, script); |
WrenInterpretResult result = wrenInterpret(vm, module, script); |