-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C callback example on docs causes compile errors #5528
Comments
It seems like the documentation is just wrong here. This should be a somewhat working example, only on carc.in it doesn't link: https://carc.in/#/r/3c7j |
Even the linking is not the problem, however. |
Ah! The example differs on the official language reference and the "Passing a Proc to a C Function" section in the API Docs. The API Docs for Proc contain a correct example using |
Closed in favor of crystal-lang/crystal-book#186 |
System:
OS: WSL running Ubuntu 16.04
Crystal Version Info:
Issue:
Thought I'd try my hand at passing a closure to a C function using the example on the crystal-lang docs as a learning exercise. I ran into a couple issues trying to make the example work.
An exact copy (aside from an
@Link
I added) of the example code yields the following error:I thought I'd just initialize it as an empty Array to just get past that line, given that there's probably some obvious solution that I missed. I changed lines in the example from:
@@box : Box(Int32 ->)
and@@box = boxed_data
to
@@box : Array(Box(Int32 ->)) = [] of Box(Int32 ->)
and@@box << boxed_data
, respectively. I then get the following error:which sort of makes sense because Box is supposed to give us a
Pointer(Void)
, but why do the types not match?So it seems that either the syntax or the the types used in the module-level variable are causing problems. Are the docs out of date or have I done something wrong myself? I can't really find any alternative examples of this process.
The text was updated successfully, but these errors were encountered: