[Gambas-user] gb.args: Negative numbers as arguments

Benoît Minisini gambas at ...1...
Mon Nov 17 18:57:37 CET 2014


Le 15/11/2014 11:51, Tobias Boege a écrit :
> Hi,
>
> with the attached project, negative numbers (indicated by a minus sign in
> fron of them) are treated differently under various circumstances:
>
> 0. Setup:
>       $ tar -zxvf ColorSelect-1.1.37.tar.gz
>       $ cd ColorSelect
>       $ gbc3 -ga
>       $ gba3
>     Nothing to see here.
>
> 1. gbr3 -- everything as expected:
>       $ gbr3 ColorSelect.gambas -- -10 10 10
>     Correctly transfers the "-10" as an argument to the program which then
>     displays an error.
>
> 2. gbx3 -- not working:
>       $ gbx3 -- -10 10 10
>       ColorSelect: unknown option: -1
>
> 3. gbx3 (when the project does NOT call Args.End()) -- working:
>       $ vim .src/FColor.class  # Remove the Args.End(), line 17
>       $ gbc3 -ga
>       $ gbx3 -- -10 10 10
>     Correctly transfers the argument.
>
> (Now change the FColor.class back to again contain the Args.End() and
>   recompile.)
>
> 4. gbx3 (with a cheap masking trick) -- working:
>       $ gbx3 -- " -10" 10 10
>     Correctly transfers the argument and Val()'ing it does the trick.
>
> Why does gbr3 get it right?

As the project file argument of gbx3 is optional, you have to issue one 
more "--". See the subtle difference between the output of 'gbr3 -h' and 
'gbx3 -h'.

So you must do:

$ gbx3 -- -- -10 10 10

One "--" for gbx3 itself, and another one for your project. Yeah, it's a 
bit weird. :-)

> Why does the behaviour seem to depend on the
> call to Args.End()?

Because Args.Ends() checks for unknown options and abort the program if 
it detects some.

And because you can't use directly Args[] if you use Args.Ends().

You have to use the array returned by Args.Ends() which is the list of 
arguments that you are free to deal with.

Regards,

-- 
Benoît Minisini




More information about the User mailing list