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?
Archive: Function with variable
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?
Push $1
Call MyFunction
...
Function MyFunction
Exch $1
MessageBox MB_OK "$1"
Exch $1
FunctionEnd
!insertmacro MyMacro $1
...
!macro MyMacro Param1
MessageBox MB_OK "${Param1}"
!macroend
Stu
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
StrCpy $1 "value"
push $1
call MyFunction
Exch $1
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 ?
wonderful usage of the $1 var... let's suppose $1 becomes "value2"
Exch $1
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
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'