I am trying to use define_external to use a C dll from inside MAPLE. The C dll exports a function that has a argument of type function pointer which has a return type of pointer. The function itself returns pointers.
Pointers are needed as return types as the C function needs to return arrays.
When I try to pass the C function, as maple procedure as the argument, it errs saying "Error, (in rk4_vec) number expected for float parameter, got proc () option remember; table( [( 1 ) = HFloat(1.0), ( 2 ) = HFloat(-0.0) ] ) 'procname(args)' end proc"
rk4_vec is as follows:
rk4_vec := define_external("rk4vec", 't0' :: float, 'm' :: integer, 'u0' :: ARRAY(1..2,datatype=float), 'dt' :: float, 'f' :: PROC('t' :: float, 'm' :: integer, 'u' :: ARRAY(1..2,datatype=float), 'RETURN' :: REF(float)), 'RETURN' ::REF(float), "WRAPPER", LIB="rk4.dll");
rk4vec in C looks like this:
double *rk4vec ( double t0, int m, double u0, double dt,
double *f ( double t, int m, double u ) )
I am passing f as :
rk4vec_test_f := proc(t, n, u)
local uprime :: REF(float);
#uprime := Array(n);
uprime(1) := u(2);
uprime(2) := -u(1);
I have tried the RETURN type on the define_external call as : float, ARRAY(1..2, datatype=float) , but that didnt work either. I got the idea of using REF from times2 example on this link.
Any guidance in this matter is highly appreciated.
Attached are the C file, the dll, maple worksheet. Tested on Windows, with 64-bit, Maple 2016 standard. rk4.zip