以下是 #emit
directive documentation 中的示例:
[Files] #emit 'Source: "file1.ext"; DestDir: {' + MyDestDir + '}' Source: "file2.ext"; DestDir: {#MyDestDir} #emit GenerateVisualCppFilesEntries ; user defined function
在第一行中,我不理解 DestDir
部分。看起来那里缺少 #
符号。
我理解第二行。但为什么我们需要像第 1 行那样使用 #emit
指令呢?
最佳答案
Inno Setup preprocessor directives可以使用两种语法调用。
基本语法:
#directive params
以及内联语法:
{#directive params}
除此之外,#emit
directive是默认的内联指令,当没有指定明确的指令名称时假定。
所以这三个是等价的:
#emit MyDestDir
{#emit MyDestDir}
{#MyDestDir}
虽然第一个对于 path 变量没有意义,因为它会导致无效的脚本语法 - 但它可以与包含有效脚本语法的变量一起使用:
#define FileSectionEntry 'Source: ' + MySource + '; DestDir: ' + MyDestDir
#emit FileSectionEntry
虽然其他两个内联示例可以有意义,但仅限于同一行上的其他代码,例如您问题中的代码:
Source: "file2.ext"; DestDir: {#MyDestDir}
此外,带有(字符串)常量的 #emit
基本上毫无意义,因为无需预处理器即可实现相同的效果。
这三个是等效的:
Source: "file2.ext"; DestDir: "{app}"
#emit 'Source: "file2.ext"; DestDir: "{app}"'
{#'Source: "file2.ext"; DestDir: "{app}"'}
所以回到脚本中的代码,这些(几乎)是等效的:
#emit 'Source: "file1.ext"; DestDir: {' + MyDestDir + '}'
Source: "file1.ext"; DestDir: {#MyDestDir}
唯一的问题是我认为第一行中的大括号不应该在那里。该行应该是:
#emit 'Source: "file1.ext"; DestDir: ' + MyDestDir
我已提交fix for this 。这基本上是您上一个问题中的拼写错误的另一个副本:Why is there an additional pair of curly braces on the Inno Setup Preprocessor:#emit page?
关于inno-setup - Inno Setup 中的 #emit 指令有什么意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64803379/