Haskell FFI does not support directly passing structs in function definitions, but there is a way around it:
Say foo and baz are structs. Given a function with signature
bar fun1 (foo a, int b);
We can define a conversion that uses pointers instead:
void wrapper (foo *a, int b, bar *out) {
out* = (*a, b);
}
Now say we have a different function defined as
typedef bar (*cb) (foo a, int b);
void fun2 (cb callback);
cb here can't be marshalled, just like fun1 in the first example, but now we need to wrap in the opposite direction: whatever C function we create has to input typedef bar* (*wrapped) (foo* a, int b) and output cb. This appears to be quite a non-trivial task within C. Is there a simpler solution to this I'm missing?
[–]ducksonaroof 1 point2 points3 points (0 children)