Skip to content
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

Example in the doc of Crystal.main does not work #9688

Closed
lugia-kun opened this issue Aug 21, 2020 · 1 comment · Fixed by #9736
Closed

Example in the doc of Crystal.main does not work #9688

lugia-kun opened this issue Aug 21, 2020 · 1 comment · Fixed by #9736
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:docs

Comments

@lugia-kun
Copy link

lugia-kun commented Aug 21, 2020

The example described in Crystal.main(Int32, UInt8**) does not work because there is Crystal.main(&).

fun alternative_main(argc : Int32, argv : UInt8**, prc : (Int32, UInt8**) -> Int32) : Int32
  0
end

fun main(argc : Int32, argv : UInt8**) : Int32
  alternative_main(argc, argv, ->Crystal.main)
end 
Showing last frame. Use --error-trace for full trace.

error in line 6
Error: 'Crystal.main' is expected to be invoked with a block, but no block was given

https://play.crystal-lang.org/#/r/9kk9

I have also confirmed this with master:

Using compiled compiler at .build/crystal
Crystal 1.0.0-dev [007dcfc78] (2020-08-19)

LLVM: 10.0.1
Default target: x86_64-unknown-linux-gnu

Workaround

Using wrapped Proc can avoid this error.

fun alternative_main(argc : Int32, argv : UInt8**, prc : (Int32, UInt8**) -> Int32) : Int32
  0
end
 
fun main(argc : Int32, argv : UInt8**) : Int32
  wrap = -> (ac : Int32, av : Pointer(Pointer(UInt8))) { Crystal.main(ac, av) }
  alternative_main(argc, argv, wrap)
end

https://play.crystal-lang.org/#/r/9kkh

@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:docs labels Aug 24, 2020
@hugopl
Copy link
Contributor

hugopl commented Sep 9, 2020

This works.

fun alternative_main(argc : Int32, argv : UInt8**, prc : (Int32, UInt8**) -> Int32) : Int32
  0
end

fun main(argc : Int32, argv : UInt8**) : Int32
  alternative_main(argc, argv, ->Crystal.main(Int32,UInt8**))
end

So I think this just need a minor docs update.

hugopl added a commit to hugopl/crystal that referenced this issue Sep 9, 2020
hugopl added a commit to hugopl/crystal that referenced this issue Sep 9, 2020
bcardiff pushed a commit that referenced this issue Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants