New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to declare a C function pointer with varargs #214
Comments
For now you can use I can see in class_addMethod you must pass an IMP. Can you get an IMP back from an objective-c call? And how do you use it? We can add that feature to the language but I need to know how you would use it in order to implement it well. |
I don't care, at least for now, getting a IMP from obj-c. I just need to create them on crystal and pass it to class_addMethod. Each IMP instance will vary on the arguments after the 3rd param.
If I declare IMP as Void* I get:
if I try to cast, I get:
My only workaround is to define many IMP and menu addMethod aliases, one for each signature :-( At least I would need a generic function pointer. FYI: this crocoa code is WIP and not pushed yet. |
You can try doing |
Same result using with
with
|
…file. Issues regarding IMP signature due to crystal-lang/crystal#214
I push the spike around this on https://github.com/manastech/crocoa/tree/master/samples/bundled_application . Just in case is easier to check further ideas.
|
I forgot our procs are always a pair containing a pointer to the function and a pointer to the closure context (which is null if it's not a closure). You can access that pointer by invoking alias IMP = Void*
f = ->{ 1 }
f.pointer as IMP # works You can use that workaround until we implement variadic function pointers (only for C bindings, I guess). Note that |
Yeap, it did the trick. You choose whether to leave this issue open or not. For me is enough with the workaround. I agree that an exception for closures should be raised. |
The text was updated successfully, but these errors were encountered: