Call a function in a shared library: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl example) |
No edit summary |
||
Line 287: | Line 287: | ||
<pre>500</pre> |
<pre>500</pre> |
||
=={{header|Dart}}== |
|||
add.c |
|||
<lang c> |
|||
int add(int num1, int num2) { |
|||
return num1 + num2; |
|||
} |
|||
</lang> |
|||
Dart code |
|||
<lang javascript>import 'dart:ffi' |
|||
show DynamicLibrary, NativeFunction, Int32; |
|||
main(){ |
|||
final lib = DynamicLibrary.open('add.dylib'); // Load library |
|||
final int Function(int num1,int num2) add = lib // Write Dart function binding |
|||
.lookup<NativeFunction<Int32 Function( Int32, Int32 )>>('add') // Lookup function in library |
|||
.asFunction(); // convert to Dart Function |
|||
print( add( 1, 2 ) ); |
|||
} |
|||
</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |