Search code examples
ffiidris

bind to abstract types for c struct with idris


I can not find how to treat this typedef struct TF_Status TF_Status; as abstract types and bind to that

the c function is TF_Status* TF_NewStatus();

data TF_Status
tfNewStatus : IO TF_Status 
tfNewStatus = foreign FFI_C "TF_NewStatus" (IO TF_Status)

http://docs.idris-lang.org/en/latest/reference/ffi.html

it complains that When checking argument fty to function foreign: Can't find a value of type FTy FFI_C [] (IO TF_Status)


Solution

  • TF_Status* TF_NewStatus(); returns a pointer to a TF_Status when called. So you only need

    tfNewStatus : IO Ptr 
    tfNewStatus = foreign FFI_C "TF_NewStatus" (IO Ptr)