Winamp & Shoutcast Forums

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

martijntijn 7th November 2007 15:04

Function with variable
 
I would like to call a function and give a certain variable like:

Call MyFunction "variable string"

Function "MyFunction" $1
MessageBox MB_OK "$1"
FunctionEnd

Is this possible?

Afrow UK 7th November 2007 15:07

code:
Push $1
Call MyFunction
...
Function MyFunction
Exch $1
MessageBox MB_OK "$1"
Exch $1
FunctionEnd


Or use macros:
code:

!insertmacro MyMacro $1
...
!macro MyMacro Param1
MessageBox MB_OK "${Param1}"
!macroend

Stu

galevsky 7th November 2007 16:48

I can't understand clearly how stack and variables are managed.


Can you explain ?

On one hand, there is a stack. On the other hand, many variables... $0..$R0 among them.

What should be passed to the function ? the stack ?
So let's push $1 on top of the stack

code:
StrCpy $1 "value"
push $1



And now run the func

code:
call MyFunction


At this point, I misunderstand what is available to the function and what is not. $1 is a global var, can be seen from anywhere. So MyFunction can read and feed it with some value ... no ? Why dealing with stack ?

code:
Exch $1

Quote:

Originally Posted by doc
[..]When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter[...]

What that means ? Previously, your stack had only one value: "value". You want to exchange "value" at the top of the stack with ... with "value" again ? (yes, global $1 contains "value"). What for ?

code:
wonderful usage of the $1 var... let's suppose $1 becomes "value2"


Then,

code:
Exch $1


again, what for ? saving the new value "value2" of $1 in stack ? (to make the parameter $1 as in and out ?)
Sometimes, functions run "pop $1".... what that does ? remove the value at stack top and feed $1 with it ?

Many thanks to help me to understand a bit, I read again and again the doc but fail to understand.

Gal'

Afrow UK 7th November 2007 17:02

You use the stack so that you can call the function without having to use the same variable to pass a value.
http://nsis.sourceforge.net/Pop,_Pus...h..._The_Stack

Stu

galevsky 7th November 2007 20:26

Okay thank you very much. The link you give me describes the in and out of a stack behaviour, but you point out the key: no need to use global var thanks to this stack-of-parameters.

Many thanks ;)

Gal'


All times are GMT. The time now is 04:37.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.