Skip to content

[FFI] How can I specify C types? #161

Answered by arshajii
iuridiniz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @iuridiniz -- your code is almost correct; here's what these arguments would be in Codon:

  • MY_STRUCT *self: Can just be cobj, which represents a generic (void * / char *) pointer in C
  • const char *cont_arg: Ptr[byte] in Codon or cobj if you don't care about the pointer's type
  • int (*callback)(void*): This can also be cobj, and you can cast it to the correct type and call it as in Function[[cobj], i32](callback)(arg)
  • void *cb_arg: Again cobj
  • int16_t: i16 in Codon (or Int[16]; it's the same)
  • void **output: Ptr[cobj], or just cobj if you don't care about the pointer's type

It looks like your from C import is missing the last cobj? i.e. there should be 6 arguments but your code has 5.

Now f…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@iuridiniz
Comment options

@arshajii
Comment options

@iuridiniz
Comment options

Answer selected by iuridiniz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants