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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -