Archive: Extending $0 - $9 and $R0 - $R9


Extending $0 - $9 and $R0 - $R9
  I have simply run out of all the $x and $Rx functions in my script, and am wondering if you can make up new ones that can be used in StrCpy, ReadINIstr etc

I know you can...
!define TEMP1 "$0"
StrCmp ${TEMP1} $0 "" +2
...but that uses up $0

-Stuart


Defining TEMP1 as $0 is nothing more but telling the compiler to replace every ${TEMP1} it sees with $0, it doesn't create a new variable.

The best way to clear up some variables for usage is to push them to the stack and when you are finished with them pop them back. For example:

Push$0

Push$1
># use $1 and $0 here...
>Pop $1
Pop$0
># $0 and $1 are same as before the push now
Another way you might want to try is to read data from INI files or the registry only when you need it and not to keep it ready from the beginning. This also applies to section selections (use SectionGetFlags instead of setting a variable to 1 when the section executes).

Thanks

I'll have a look into where I can push and pop them around!
Here is the script...

http://myweb.tiscali.co.uk/afrowuk/map-compiler.nsi


-Stuart


Well, for functions, its always best to Push all the variables on the stack that you are going to use. Then when the function is over, pop them back in (making sure you use the right order). Then you will still have every variable available outside of the function since that function takes care of any previous variables that were used.


Hi,

I guess I am a little slow at this pushing and popping idea.

Can someone explain a little more on when to use PUSH and when to use POP?

Do I Pop or Push a variable when I wish to know the value of that variable?

Thanks.
:)


Push adds a value to the stack, Pop removes one and sets the variable.

For example, the value of $0 is 123.

Now you are going to call the function bla:

Function bla

Push $0 ;123 added to the stack

...the function can use $0...

Pop $0 ;Remove 123 from the stack and set $0 back to 123

FunctionEnd

After calling the funtion, the variables contain the same value as before.


Note the order when using multiple variables (last-in first-out):

Function bla

Push $0
Push $1

...code...

Pop $1
Pop $0

FunctionEnd

And how can we, for example, since $9 is for the Startmenu, use it once and then "empty" the value so startmenu use it.
In my case I use $9 for my name in the script; but I copy the value:


StrCpy $9 "${MUI_PRODUCT}"

So the startmenu recognize.

The first option is to define MUI_STARTMENUPAGE_VARIABLE with another variable ($8 for example), so another variable will be used.

If you have to use all 20 variables, you can also Push/Pop it if you want to use the variable temporary.

Push ${MUI_STARTMENUPAGE_VARIABLE}
...code...
Pop ${MUI_STARTMENUPAGE_VARIABLE}

Why are you using a variable for the name? The name is always the same, so you can use a define.


!define MyName "Dude"


I already have done that :D
But checking my script, I forgot that
I'm using the System plugin to detect RAM and "stole" $9.
Yeah! I'll "Pop it" :up:

Clearing the stack...
  Is there a way to clear the stack and start over?

mlm(aka digitalda)


Here is an article about the stack: http://nsis.sourceforge.net/archive/...52&instances=0.

Try this code (may contain errors, couldn't test it) to clear the stack:

LoopAgain:

>Pop $R9
IfErrors Done LoopAgain
Done:
This will use the $R9 variable.