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?
Function with variable
5 posts
Or use macros:Push $1
Call MyFunction
...
Function MyFunction
Exch $1
MessageBox MB_OK "$1"
Exch $1
FunctionEnd
Stu
!insertmacro MyMacro $1
...
!macro MyMacro Param1
MessageBox MB_OK "${Param1}"
!macroend
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
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'
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
And now run the funcStrCpy $1 "value"
push $1
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 ?call MyFunction
Exch $1
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 ?Originally Posted by doc[..]When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter[...]
Then,wonderful usage of the $1 var... let's suppose $1 becomes "value2"
again, what for ? saving the new value "value2" of $1 in stack ? (to make the parameter $1 as in and out ?)Exch $1
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'
You use the stack so that you can call the function without having to use the same variable to pass a value.
Stu
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'
Many thanks 😉
Gal'