Nsis 将宏的输出转储为null

Nsis 将宏的输出转储为null,nsis,Nsis,这主要是一个好奇的问题,但无论如何。假设我有一个宏和声明: !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}

这主要是一个好奇的问题,但无论如何。假设我有一个宏和声明:

!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

您可以使用任何您喜欢的魔术字符串来表示未使用的宏参数,然后在宏实现中检查这一点。另一种选择是在脚本顶部创建自己的$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\u me\u away
变量,也没有
popanddcard
方法,因此您必须找到一种方法来丢弃结果:

!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

谢谢你的回复,安德斯!安德斯,但是我忘了问一下混合动力车了,请考虑我的编辑问题。混合动力车不允许使用空字符串吗?弹出到$\u LOGICLIB\u TEMP是最好的选择。再次感谢您的解释,Anders!您是NSIS的真正导师:-)