这主要是好奇心问题,但不过。想象一下,我有一个声明宏:
!define foo "!insertmacro foo"
!macro foo in1 in2 out1 out2 out3
; the code here
!macroend
输入为inX
,输出为outX
。现在,我不太经常需要所有三个输出(例如,其中一个是winapi调用返回的退出状态),但仍然必须将变量作为占位符传递以取悦宏语法:
${foo} $1 $2 $R1 $R2 $R3
是否有像
这样的语法${foo} $1 $2 $R1 nul nul
删除不需要的输出?
编辑:还请解释如何处理混合动力的变量参数。 SCCE:
OutFile sccce.exe
!define foo "!insertmacro foo"
!macro foo in1 out1 out2
Push "${in1}"
Call bar
Pop "${out1}"
!macroend
Section
${foo} $0 $1 $2 ; compilable
${foo} $0 $1 "" ; not compilable
SectionEnd
Function bar
Pop $0
IntOp $0 $0 + 1
Push $0
FunctionEnd
答案 0 :(得分:2)
您可以使用任何您喜欢的魔术字符串来指示未使用的宏参数,然后在宏实现中检查这一点。另一种方法是在脚本的顶部创建自己的$ null变量。
!macro Foo always maybe
IntOp ${always} 666 * 1337
!if "${maybe}" != ""
IntOp ${maybe} 1234 * 1337
!endif
!macroend
!insertmacro Foo $0 ""
!insertmacro Foo $0 $1
编辑:
没有$optimize_me_away
变量且无法PopAndDiscard
,所以你必须找到一种方法来丢弃结果:
!macro foo_alt1 in1 out1 ; The disadvantage with this method is that the common case is "bloated"
Push "${in1}"
Call bar_alt1 ; Will store result in $0
!if "${out1}" == ""
Pop $0
!else if "${out1}" != $0
StrCpy ${out1} $0
Pop $0
!endif
!macroend
Function bar_alt1
Exch $0
IntOp $0 $0 + 1
FunctionEnd
!include LogicLib.nsh
!macro foo_alt2 in1 out1
Push "${in1}"
Call bar_alt2
!if "${out1}" == ""
!insertmacro _LOGICLIB_TEMP ; LogicLib has a internal varible we can use, or you can make your own
Pop $_LOGICLIB_TEMP
!else
Pop ${out1}
!endif
!macroend
Function bar_alt2
Exch $0
IntOp $0 $0 + 1
Exch $0
FunctionEnd
Section
!macro test alt
StrCpy $0 PreserveMe
!insertmacro foo_alt${alt} 1337 $1
DetailPrint r0=$0,r1=$1
!insertmacro foo_alt${alt} 1337 $0
DetailPrint r0=$0
!insertmacro foo_alt${alt} 1337 ""
DetailPrint NoResult
!macroend
!insertmacro test 1
!insertmacro test 2
SectionEnd