Skip to content
⌘ NSIS Forum Archive

!macroundef ?

6 posts

Zinthose#

!macroundef ?

Is there a compiler command for undefining a macro?

Example:

!macro Func UN
    Function ${UN}MyFunc
        Call ${UN}ComplexFunc
    FunctionEnd
!macroend
!insertmacro Func ""
!insertmacro Func "un."
!macroundef Func 
Practical use would be limited, but I can think of a few instances were this would be very useful.
Anders#
use the !define foo "!insertmacro foo" trick, then use ${foo} (Not sure if that applies to your code, since it makes no sense at all, why not call directly?)
Zinthose#
Sorry for the confusion, the nested 'ComplexFunc' function within the macro was just meant to be a simple example.

The results of the code would be:

.
    Function MyFunc
        Call ComplexFunc
    FunctionEnd
    Function un.MyFunc
        Call un.ComplexFunc
    FunctionEnd 
Thus permitting a function to be available in both the installer and uninstaller.

The !macroundef command could allow for multiple "myFuncs" but with different contents for each macro.

Primarily this would be useful for headers to destroy macros only used within them selves to avoid conflicts.
Zinthose#
Here is an extended example:
## Macros
    !macro Func UN
        Function ${UN}MyFunc
            Push 'Hello'
            Push 'Macro'
            Call ${UN}ComplexFunc
        FunctionEnd
    !macroend
    !insertmacro Func ""
    !insertmacro Func "un."
    !macroundef Func
    
    !macro Func UN
        Function ${UN}MyFunc2
            Push 0xDEAD
            Push 0xBEEF
            Call ${UN}ComplexFunc2
        FunctionEnd
    !macroend
    !insertmacro Func ""
    !insertmacro Func "un."
    !macroundef Func
## Results of Macros
    Function MyFunc
        Push 'Hello'
        Push 'Macro'
        Call ComplexFunc
    FunctionEnd
    Function un.MyFunc
        Push 'Hello'
        Push 'Macro'
        Call un.ComplexFunc
    FunctionEnd
    Function MyFunc2
        Push 0xDEAD
        Push 0xBEEF
        Call ComplexFunc2
    FunctionEnd
    Function un.MyFunc2
        Push 0xDEAD
        Push 0xBEEF
        Call un.ComplexFunc2
    FunctionEnd 
Zinthose#
Another example that would be cool if the compiler permited...
## If defining a macro in a macro were permited...
!macro _SharedFunctions
    !macro SharedFunction UN
!macroend
!define SharedFunctions `!macro SharedFunction UN`
!macro _SharedFunctionsEnd
    !macroend
    !insertmacro SharedFunction ""
    !insertmacro SharedFunction "un."
    !macroundef SharedFunction
!macroend
!define SharedFunctionsEnd `!macroend !insertmacro _SharedFunctionsEnd`
${SharedFunctions}
    Function ${UN}MyFunc
        DetailPrint '${UN}Test'
    FunctionEnd
${SharedFunctionsEnd} 
kichik#
You can use CallArtificialFunction inside Include\Utils.nsh for automatically creating both installer and uninstaller "functions".