Define Macro: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(Initial Release) |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category: | [[Category:Compile-Time Macros]] | ||
{{PageAuthor|Zinthose}} | {{PageAuthor|Zinthose}} | ||
Line 8: | Line 8: | ||
* ReDefine macro to reassign a define easily. | * ReDefine macro to reassign a define easily. | ||
== Usage == | == Usage == | ||
=== Command List === | |||
* ${Define} _Name _Value | |||
* ${ReDefine} _Name _Value | |||
* ${DefineOnce} _Name | |||
* ${ReDefineOnce} _Name | |||
=== Example === | === Example === | ||
<highlight-nsis> | <highlight-nsis> | ||
## Recursive Define trick for one time value setting | ## Recursive Define trick for one time value setting | ||
${ | ${DefineOnce} MSI_FilePath | ||
${MSI_FilePath} `$TEMP` | ${MSI_FilePath} `$TEMP` | ||
DetailPrint `MSI_FilePath = "${MSI_FilePath}"` | |||
## Recursive ReDefine trick for one time value setting | |||
${ReDefineOnce} MSI_FilePath | |||
${MSI_FilePath} `$PROGRAMFILES` | |||
DetailPrint `MSI_FilePath = "${MSI_FilePath}"` | DetailPrint `MSI_FilePath = "${MSI_FilePath}"` | ||
Line 59: | Line 71: | ||
!macroend | !macroend | ||
!endif | !endif | ||
!endif | |||
!ifndef DefineOnce | |||
!define DefineOnce `!insertmacro _DefineOnce` | |||
!macro _DefineOnce _Name | |||
${Define} ${_Name} `${Define} ${_Name}` | |||
!macroend | |||
!endif | |||
!ifndef ReDefineOnce | |||
!define ReDefineOnce `!insertmacro _ReDefineOnce` | |||
!macro _ReDefineOnce _Name | |||
${ReDefine} ${_Name} `${ReDefine} ${_Name}` | |||
!macroend | |||
!endif | !endif | ||
</highlight-nsis> | </highlight-nsis> |
Latest revision as of 19:51, 12 October 2009
Author: Zinthose (talk, contrib) |
Summary
Pure Pre-compiler macro that enhances the !define command.
- Once defined, value is locked and will not raise an error or be redefined. This is useful for assigning default values.
- Recursive define trick to allow a define to assign itself.
- ReDefine macro to reassign a define easily.
Usage
Command List
- ${Define} _Name _Value
- ${ReDefine} _Name _Value
- ${DefineOnce} _Name
- ${ReDefineOnce} _Name
Example
## Recursive Define trick for one time value setting ${DefineOnce} MSI_FilePath ${MSI_FilePath} `$TEMP` DetailPrint `MSI_FilePath = "${MSI_FilePath}"` ## Recursive ReDefine trick for one time value setting ${ReDefineOnce} MSI_FilePath ${MSI_FilePath} `$PROGRAMFILES` DetailPrint `MSI_FilePath = "${MSI_FilePath}"` ## Standard Define ${Define} MSI_FileName `Install.msi` DetailPrint `MSI_FileName = "${MSI_FileName}"` ## Redefine a previously defined value or create a new one ${ReDefine} MSI_FileName `Setup.msi` DetailPrint `MSI_FileName = "${MSI_FileName}"` ${ReDefine} MSI_FileName `Deployment.msi` DetailPrint `MSI_FileName = "${MSI_FileName}"`
Macro Source
!ifmacrondef _Define !ifndef Define !define Define `!insertmacro _Define` !macro _Define _Name _Value !ifdef ${_Name} !if `${${_Name}}` == `` !undef ${_Name} !define ${_Name} `${_Value}` !else if `${${_Name}}` == `!insertmacro _Define ${_Name}` !undef ${_Name} !define ${_Name} `${_Value}` !endif !else !define ${_Name} `${_Value}` !endif !macroend !endif !endif !ifmacrondef _ReDefine !ifndef ReDefine !define ReDefine `!insertmacro _ReDefine` !macro _ReDefine _Name _Value !ifdef ${_Name} !undef ${_Name} !endif !insertmacro _Define ${_Name} `${_Value}` !macroend !endif !endif !ifndef DefineOnce !define DefineOnce `!insertmacro _DefineOnce` !macro _DefineOnce _Name ${Define} ${_Name} `${Define} ${_Name}` !macroend !endif !ifndef ReDefineOnce !define ReDefineOnce `!insertmacro _ReDefineOnce` !macro _ReDefineOnce _Name ${ReDefine} ${_Name} `${ReDefine} ${_Name}` !macroend !endif