Page 1 of 1
TLO Macro.Params broken with 9 - 12 patch
Posted: Wed Sep 13, 2017 6:22 pm
by dewey2461
Call this with no arguments and I get two params, but both arg1 and arg2 are null. Easy to work around.
Code: Select all
Sub Main(string arg1,string arg2)
/echo Macro.Params ${Macro.Params}
/echo arg1 ${arg1}
/echo arg2 ${arg2}
/return
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Wed Sep 13, 2017 7:51 pm
by JudgeD
Macro.Params seems like a really weird thing to have available.
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 5:53 am
by EqMule
Not a bug, all parameters default to NULL when not supplied.
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 10:23 am
by dewey2461
EqMule wrote:Not a bug, all parameters default to NULL when not supplied.
What should ${Macro.Params} be returning under the following conditions?
/mac test -> 2
/mac test p1 -> 2
/mac test p1 p2 -> 2
/mac test p1 p2 p3 -> 3
I modified my code to ignore Macro.Params.
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 12:33 pm
by EqMule
well you only have 2 params within your () so it should always return 2 unless somone calls that sub with 3 params which of course is stupid since the function clearly only takes 2 args...
but anyway... you could use Macro.Params to make sure you only get 2... and if someone supplies a third... /echo a warning then /endm
${Macro.Params} is most useful when you DONT know the number of args (the user?) supplied as in
/mac test.mac 1 2 3 4
Code: Select all
Sub Main
/echo ${Macro.Params}
/return
which doesn't have a fancy (...)
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 12:39 pm
by EqMule
and while we are on this topic, I am considering making the default just empty for strings and an actual number 0 if its an int, not sure yet.
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 12:54 pm
by dewey2461
EqMule wrote:
/mac test.mac 1 2 3 4
Code: Select all
Sub Main
/echo ${Macro.Params}
/return
Given the above case, is there any way to get the actual command line arguments?
I think the TLO really should be ${Macro.Parms} = # of arguments, while ${Macro.Params[N]} returns the actual parameter, but it isn't implemented that way, and I'm probably the ONLY one who has used it in years so ...
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 3:47 pm
by EqMule
The macro above does return 4... which is the number of args supplied to it.
I'm not sure I understand your question
Updated:
Ok yes u want to know what ${Param<x>} actually contains?
Yeah that's easy: using the built in ${Param<x>} macro variables we can check this.
Code: Select all
| Macro Example to show how to get commandline variables without screwing up the macro engine with undeclared variables:
| EqMule 2017
#turbo
Sub Main
/declare pi int local
/declare NumParams int local
| Check for command line variables
/if (${Macro.Params}) {
/varset NumParams ${Math.Calc[${Macro.Params}-1]}
}
/if (${Macro.Params}) {
/for pi 0 to ${NumParams}
/echo Commandline arg ${pi} is: ${Param${pi}}
/next pi
}
/return
if you do /mac testp.mac 1 2 "Hi There"
the macro will output
Commandline arg 0 is: 1
Commandline arg 1 is: 2
Commandline arg 2 is: Hi There
Re: TLO Macro.Params broken with 9 - 12 patch
Posted: Thu Sep 14, 2017 5:59 pm
by dewey2461
I need to re-read the manual. Didn't know we had Param0, Param1, Param2 ...
Learn something new about MQ ... at least once a year
