Maybe the compiler could give a more meaningful error message...
-- Cedric
brianWed 25 Jun 2008
That is something I've been meaning to fix. I enhanced the launcher code to be more flexible calling main, and to print a more helpful error message. The updated docTool::Fan section follows:
The main method can return Void or Int. If the main method returns an Int, then it is returned as the exit code of the process, otherwise zero is returned (or non-zero if an exception is raised).
The main method either takes no arguments or Str[]. You can access any arguments passed on the command line via the Sys.args method. All of these are valid main methods:
Void make()
Void make(Str[] args)
Void make(Str[] args, Bool flag := true)
Int make()
Int make(Str[] args)
Int make(Str[] args, Bool flag := true)
All of the main method signatures above can be static or instance based. If the main method is static then it is simply invoked using reflection. However if the main method is instance based, a new instance is created via Type.make to use for the main method. This technique can be used perform common initialization via a base class - in fact it is used by the build scripts themselves.
tompalmerWed 25 Jun 2008
That would be great.
jodastephenSat 12 Nov 2011
These main method examples have a method name of "make". Surely the method name should be "main"?
brianSun 13 Nov 2011
These main method examples have a method name of "make". Surely the method name should be "main"?
Yeah that is quite a bad typo - glad you caught it. I pushed a fix.
cbeust Wed 25 Jun 2008
I can't seem to find any example of declaring a "Void main" method with Str[] args in it, and doing so results in the cryptic:
What's the correct syntax?
-- Cedric
gizmo Wed 25 Jun 2008
Note that unlike Java or C# the arguments aren't passed as parameters to main - rather you can access them via Sys.args.
cbeust Wed 25 Jun 2008
Ah, thanks.
Maybe the compiler could give a more meaningful error message...
-- Cedric
brian Wed 25 Jun 2008
That is something I've been meaning to fix. I enhanced the launcher code to be more flexible calling main, and to print a more helpful error message. The updated docTool::Fan section follows:
The main method can return Void or Int. If the main method returns an Int, then it is returned as the exit code of the process, otherwise zero is returned (or non-zero if an exception is raised).
The main method either takes no arguments or
Str[]
. You can access any arguments passed on the command line via theSys.args
method. All of these are valid main methods:All of the main method signatures above can be static or instance based. If the main method is static then it is simply invoked using reflection. However if the main method is instance based, a new instance is created via
Type.make
to use for the main method. This technique can be used perform common initialization via a base class - in fact it is used by the build scripts themselves.tompalmer Wed 25 Jun 2008
That would be great.
jodastephen Sat 12 Nov 2011
These main method examples have a method name of "make". Surely the method name should be "main"?
brian Sun 13 Nov 2011
Yeah that is quite a bad typo - glad you caught it. I pushed a fix.