JohnChen
20th May 2011 16:34 UTC
The usage of macro
If I define a macro, for example, !define MY_WALLET "empty". When I use MY_WALLET this way, MessageBox MB_OK $MY_WALLET, then "$MY_WALLET" will be displayed. In order to display "empty", I have to use it like MessageBox MB_OK ${MY_WALLET}. Why? Thanks.
Afrow UK
20th May 2011 19:18 UTC
You define macros with !macro, not !define. Why would you use $MY_WALLET? It's not a variable. The ${} is there for that distinction.
Stu
JohnChen
20th May 2011 20:55 UTC
Originally posted by Afrow UK
You define macros with !macro, not !define. Why would you use $MY_WALLET? It's not a variable. The ${} is there for that distinction.
Stu
But we use $1 or $R0 as variables. So I guess ${} is for user defined variable and $ is system defined variable like $1 or $R0. Am I right? Thanks.
Afrow UK
20th May 2011 21:06 UTC
No! You really need to read the manual. !define creates a constant not a variable. Var creates a user variable. User variables and NSIS registers ($R0-$R9, $0-$9) use the same syntax ($var). Constants use ${constant}. Constants are evaluated at compile time, i.e. their place-holder (${constant}) is substituted with their value at compile time. The actual constant no longer exists in the built installer executable. This goes for every command that begins with a !, hence why they are in the manual under compile time commands. Not sure why I am answering this - you really should look this stuff up.
Edit: And don't confuse run-time constants (e.g. $SYSDIR) with compile-time constants (${myconstant}). They are not the same. $SYSDIR (etc.) is like a special variable which has its value set before .onInit, but you cannot write to it.
Stu
JohnChen
20th May 2011 22:33 UTC
Originally posted by Afrow UK
No! You really need to read the manual. !define creates a constant not a variable. Var creates a user variable. User variables and NSIS registers ($R0-$R9, $0-$9) use the same syntax ($var). Constants use ${constant}. Constants are evaluated at compile time, i.e. their place-holder (${constant}) is substituted with their value at compile time. The actual constant no longer exists in the built installer executable. This goes for every command that begins with a !, hence why they are in the manual under compile time commands. Not sure why I am answering this - you really should look this stuff up.
Edit: And don't confuse run-time constants (e.g. $SYSDIR) with compile-time constants (${myconstant}). They are not the same. $SYSDIR (etc.) is like a special variable which has its value set before .onInit, but you cannot write to it.
Stu
Thanks for your explainations! I will also check the manual.