Call a foreign-language function: Difference between revisions
Content added Content deleted
m (→Python) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 222: | Line 222: | ||
bx lr @ return |
bx lr @ return |
||
</lang> |
</lang> |
||
=={{header|Arturo}}== |
|||
'''C Library''' |
|||
<lang c>// compile with: |
|||
// clang -c -w mylib.c |
|||
// clang -shared -o libmylib.dylib mylib.o |
|||
#include <stdio.h> |
|||
void sayHello(char* name){ |
|||
printf("Hello %s!\n", name); |
|||
} |
|||
int doubleNum(int num){ |
|||
return num * 2; |
|||
}</lang> |
|||
'''Calling the foreign-language functions''' |
|||
<lang rebol>; call an external function directly |
|||
call.external: "mylib" 'sayHello ["John"] |
|||
; map an external function to a native one |
|||
doubleNum: function [num][ |
|||
ensure -> integer? num |
|||
call .external: "mylib" |
|||
.expect: :integer |
|||
'doubleNum @[num] |
|||
] |
|||
loop 1..3 'x [ |
|||
print ["The double of" x "is" doubleNum x] |
|||
]</lang> |
|||
{{out}} |
|||
<pre>Hello John! |
|||
The double of 1 is 2 |
|||
The double of 2 is 4 |
|||
The double of 3 is 6 </pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |