Swift + C functions -
i have following c function
struct answer* create(struct callbacks *callbacks);
i need create struct of function pointers , call function swift
what have far is:
func aa(state: cint, user_data: unsafemutablepointer<void>) {} func bb(state: cint, user_data: unsafemutablepointer<void>) {} struct callbacksstruct { let on_aa = aa let on_bb = bb }
and try call function this:
var callbackstruct = callbacksstruct() let ans = create(&callbackstruct)
but, without success
is possible in swift ?
yes, should possible. in swift 2, 1 can send swift closure parameter c, when c expects function pointer. in case, have wrapped in struct, addition of '@convention(c)' explicitly state it's c, might help.
see examples here new-conventionc-in-swift-2-how-can-i-use-it
Comments
Post a Comment