Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   macro with parameters (http://forums.winamp.com/showthread.php?t=325959)

isawen 14th January 2011 13:56

macro with parameters
 
Hi guys,

I would really appreciate your help over this issue I have.

I have a macro with 2 parameters like below:

PHP Code:

!macro TestMacro _PARAM1 _PARAM2
Push 
$1
StrCpy 
$1 $OUTDIR
// ... do some stuff here with the ${_PARAM1} and ${_PARAM2}
SetOutPath $1
Pop 
$1
!macroend 

The problem is that when I call it like this:
PHP Code:

${TestMacro} $$

inside the macro the ${_PARAM1} gets set to the $OUTDIR.

Is there a way to avoid this kind bad macro usage, beside:

PHP Code:

!macro TestMacro _PARAM1 _PARAM2
!define LastKnownOutDir $OUTDIR
// ... do some stuff here with the _PARAM1 and _PARAM2
SetOutPath ${LastKnownOutDir }
!
undef LastKnownOutDir 
!macroend 

Many thanks in advance,
Isawen

Afrow UK 14th January 2011 15:27

Well you could do:
code:
!macro TestMacro _PARAM1 _PARAM2
!if `${_PARAM1}` == $1
!error `_PARAM1 cannot be $1`
!endif
...

Stu

Afrow UK 14th January 2011 15:32

And a more sophisticated solution is to switch $1 to something else if one of the macro parameters is $1, i.e.
code:
!macro TestMacro _PARAM1 _PARAM2
!if `${_PARAM1}` == $1
!define _Var1 $2
!else
!define _Var1 $1
!endif
Push ${_Var1}
...
Pop ${_Var1}
!undef _Var1
!macroend

Here if the parameter is $1, you instead use $2 and leave $1 as it is. In fact, this is how some of the macros in Sections.nsh should be changed to use (those macros were written before !if).

Edit: I should point out that neither of these solutions will work if for example "some string containing $1" is used for _PARAM1. You are stuck there. Perhaps usage of !searchparse may work but you have to match $1 and ignore $$1 somehow.

Stu

isawen 14th January 2011 16:00

I'm somehow satisfied with the !define command to store the OUTDIR and to restore it at the end.
Thanks.

MSG 14th January 2011 18:03

Edit: Err, nvm, not applicable here.

Afrow UK 14th January 2011 20:46

I am probably wrong to ask but you do realise that !define is a compile time instruction. It will not be set to the value of $OUTDIR because that is not known until run time. Storing $OUTDIR in a constant will not benefit you at all except to save you from having to repeat $OUTDIR throughout the macro. Wherever you use that constant, $OUTDIR will be inserted.

Stu

isawen 19th January 2011 00:11

Yes, sorry my bad. Thanks for your correction.
I didn't notice that the functionality was wrong until I changed some paths that I needed inside the macro.

Much appreciated.
Isa


All times are GMT. The time now is 17:40.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.