ikreb
ikreb

Reputation: 2785

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 ||?

Upvotes: 0

Views: 277

Answers (2)

Anders
Anders

Reputation: 101746

!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

Upvotes: 1

ikreb
ikreb

Reputation: 2785

I forgot the quotation marks. However the error message is not very helpful.

This is the solution

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

Upvotes: 0

Related Questions