Search code examples
booleannsis

NSIS: How to use the preporcessor or


I want something like this

!if (${Flag} == 5) || (${Flag} == 7)
     ...
!endif

But I get the error message !if expects 1-4 parameters, got 7. Usage: !if [!] value [(==,!=,<=,<,>,>=,&&,||) value2] [...]. I tried braces, but doesn't help. The documentation mentions that || is allowed to use.

I found also the solution

!macro test
    ...
!macroend
!if ${Flag} == 5
     !insertmacro test
!else if ${Flag} == 7
     !insertmacro test
!endif

But this solution is very cumbersome and for what is then ||?


Solution

  • !if does not support multiple expressions, it supports 1 or 3 parameters (not counting the ! prefix). || is just a boolean expression (OR) where at least one of the parameters must evaluate to true:

    !if ${Foo} || ${Bar}
         ...
    !endif
    

    Multiple expressions must be evaluated one by one:

    !if ${Flag} = 5
         !insertmacro DoSomething
    !else if ${Flag} = 7
         !insertmacro DoSomething
    !endif