Relative Jumps

NSIS

Previous | Contents | Next

4.4 Relative Jumps

Unlike labels, relative jumps are, as the name suggests, relative to the place they are called from. You can use relative jumps wherever you can use labels. Relative jumps are marked by numbers. +1 jumps to the next instruction (the default advancement), +2 will skip one instruction and go to the second instruction from the current instruction, -2 will jump two instructions backward, and +10 will skip 9 instructions, jumping to the tenth instruction from the current instruction.

A instruction is every command that is executed at run-time, when the installer is running. MessageBox, Goto, GetDLLVersion, FileRead, SetShellVarContext are all instructions. AddSize, Section, SectionGroup, SectionEnd, SetOverwrite (and everything under Compiler Flags), Name, SetFont, LangString, are not instructions because they are executed at compile time.

Examples:

 Goto +2
   MessageBox MB_OK "You will never ever see this message box"
 MessageBox MB_OK "The last message was skipped, this one should be shown"
 Goto +4
 MessageBox MB_OK "The following message will be skipped"
 Goto +3
 MessageBox MB_OK "You will never ever see this message box"
 Goto -3
 MessageBox MB_OK "Done"

Note that macro insertion is not considered as one instruction when it comes to relative jumps. The macro is expanded before relative jumps are applied, and so relative jumps can jump into code inside an inserted macro. The following code, for example, will not skip the macro. It will show a message box.

!macro relative_jump_test
  MessageBox MB_OK "first macro line"
  MessageBox MB_OK "second macro line"
!macroend

Goto +2
!insertmacro relative_jump_test

Previous | Contents | Next