LuP
22nd December 2011 09:24 UTC
Beginner's Q: Acessing a variable
Hello,
the registry key is defined in the following manner:
# Auto-generated by EclipseNSIS Script Wizard
# 21.12.2011 11:50:16
Name MyAppName
# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"
Could anyone explain to me why
...
!define REGKEY "SOFTWARE\$Name"
is wrong?
I think that the variable "Name" is to be used, so what's wrong accessing it via "$Name"?
And why the tag [strange for me] "$(^Name)" must be used - what "$(^...)" means or what kind of "syntax sugar" is this? I didn't google anything useful...
TIA.
LuP
MSG
22nd December 2011 09:31 UTC
$Name is a variable, and gets a value at runtime. http://nsis.sourceforge.net/Docs/Chapter4.html#4.2.1.1
${Name} is a !define, and therefore gets a value at compiletime. http://nsis.sourceforge.net/Docs/Chapter5.html#5.4.1
${^Name} is an NSIS constant, and always contains the installer's name as set by the (compiletime!) Name command. http://nsis.sourceforge.net/Docs/Chapter4.html#4.8.1.30
Theoretically, you could write to a regkey stored in a variable:
StrCpy $Name "Foo"
WriteRegStr HKCU "Software\$Name" "Bar" "baz" ; writes the value baz to a regstring called Bar in the regkey HKCU\Software\Foo
But in your case, you probably want to reference the constant ${^Name}.
LuP
22nd December 2011 10:21 UTC
Thank you for the answer and for the links.
But in your case, you probably want to reference the constant ${^Name}.
${^Name} gives syntax error:
"
warning: unknown variable/constant "{^Name}" detected, ignoring
"
So I deduce that one cannot write "${^Name}" as there is no "^Name" !define.
And also that "$(^VARIABLE)" allows to access a NSIS "internal variable" (or what), provided that it exists; in this case, parentheses are required instead of braces.
So e.g.:
"SOFTWARE\$(^Name)" yields "SOFTWARE\MyAppName"
(probably ^Name exists due to preceeding Name statement) and
"SOFTWARE\$(^AAA)" yields "SOFTWARE\"
as there is no [internal] AAA variable.
Do I understand well?
One more question:
Are the following statement equal - can quotes be omitted, is it syntactically OK?
StrCpy $Name "Foo"
StrCpy $Name Foo
LuP
Afrow UK
22nd December 2011 11:42 UTC
MSG meant $(^Name) I think, which is a actually a built-in language string (constant). There are others such as $(^SetupCaption) which you can see in the language files.
Quotes can be omitted for single tokens (i.e. no spaces).
Stu
LuP
22nd December 2011 11:48 UTC
OK, I see now, thx.
I found ^Name, ^SetupCaption etc. in c:\Program Files\NSIS\Contrib\Language files\[Czech].nlf.
LuP
LuP
3rd January 2012 16:05 UTC
${something} vs. !insertmacro something
Hello,
one more question: when to call a macro (?) / function (?) by
${something}
and when via
!insertmacro something
- I encountered two ways:
${EnvVarUpdate} $R0 Ponton A HKLM "$INSTDIR" ; Needs '!include EnvVarUpdate.nsh'
; Versus
!insertmacro APP_ASSOCIATE ext ftype desc ico operation command ; Needs '!include FileAssoc.nsh'
Are both ways equal or only one method may be used under which contitions?
TIA.
LuP
Afrow UK
3rd January 2012 18:23 UTC
${EnvVarUpdate} is just a constant which the compiler evaluates to an !insertmacro (i.e. !define EnvVarUpdate `!insertmacro EnvVarUpdate`). In other words you can use !insertmacro EnvVarUpdate or ${EnvVarUpdate} and both will evaluate to the same thing on compile. You do not call macros; they are just blocks of code which are inserted at compile time by the compiler. This is very different to Call which actually jumps to another block of code at run time.
Stu