module Crystal
Defined in:
nested_scheduler/monkeypatch/main.crClass Method Summary
-
.main(&)
Defines the main routine run by normal Crystal programs:
- .main_exit(status : Int32, exception : Exception | Nil) : Int32
Class Method Detail
def self.main(&)
#
Defines the main routine run by normal Crystal programs:
- Initializes the GC
- Invokes the given block
- Handles unhandled exceptions
- Invokes
at_exit
handlers - Flushes
STDOUT
andSTDERR
This method can be invoked if you need to define a custom main (as in C main) function, doing all the above steps.
For example:
fun main(argc : Int32, argv : UInt8**) : Int32
Crystal.main do
elapsed = Time.measure do
Crystal.main_user_code(argc, argv)
end
puts "Time to execute program: #{elapsed}"
end
end
Note that the above is really just an example, almost the
same can be accomplished with at_exit
. But in some cases
redefinition of C's main is needed.