I am learning Dart now and I playing with Dart's Interoperability with C. I am able to use a C method with two int params. Code below:
hello.dart
import 'dart:ffi' as ffi;
typedef sum_func = ffi.Int32 Function(ffi.Int32 a, ffi.Int32 b);
typedef Sum = int Function(int a, int b);
...
final dylib = ffi.DynamicLibrary.open(path);
final sumPointer = dylib.lookup<ffi.NativeFunction<sum_func>>('sum');
final sum = sumPointer.asFunction<Sum>();
print('3 + 5 = ${sum(3, 5)}');
hello.c
int sum(int a, int b){
return a + b;
}
hello.h
int add(int x, int y)
hello.def
LIBRARY hello
EXPORTS
sum
This all works really well, but I also want to have an max
C method, which takes an int array as an input and returns the biggest number. How can I do this? I've implemented all the required code in C, but I am not sure how do I "link" it with Dart. Could anyone help me please?