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.
+1跳转到下一条指令(默认的进度),+2将跳过一条指令并从当前指令跳转到第二条指令,-2将向后跳转两条指令,而+10将跳过9条指令,从当前指令跳转到第十条指令。
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.
指令是安装程序运行时在运行时执行的每个命令。
MessageBox,Goto,GetDLLVersion,FileRead,SetShellVarContext都是指令。AddSize,Section,SectionGroup,SectionEnd,SetOverwrite(以及编译器标志下的所有内容),Name,SetFont,LangString不是指令,因为它们是在编译时执行的。
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