Macro vs Function: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
mNo edit summary
No edit summary
Line 1: Line 1:
Just making sure this page exists - initial content + formatting and linking to from the FAQ will follow.
''This page is currently in process of heavy editing.  Please do not modify!''
 
Macros and Functions in NSIS are powerful tools to help make coding your installer easier and more flexible.  They can also be very powerful tools, allowing you to extend the NSIS scripting language to an extent - LogicLib is a great example of this.
 
= Definitions =
== Macros ==
From the NSIS help file: "Macros are used to insert code at compile time, depending on defines and using the values of the defines. The macro's commands are inserted at compile time. This allows you to write a general code only once and use it a lot of times but with a few changes."
 
If you are new to macros in any scripting language, then this may sound a bit confusing.  Let's go through a few examples to show what the above means.
 
"Macros are used to insert code at compile time"
What this means is that the code you define in a macro will simply be inserted at the location of your !insertmacro, as if copy/pasted, when you compile your installer script. For example:
<highlight-nsis>
!macro Hello
  DetailPrint "Hello world"
!macroend
 
Section Test
  !insertmacro Hello
SectionEnd
</highlight-nsis>
 
Could be seen as just:
<highlight-nsis>
Section Test
  DetailPrint "Hello world"
SectionEnd
</highlight-nsis>


[[Category:Scripting FAQ]]
[[Category:Scripting FAQ]]

Revision as of 12:42, 16 September 2006

This page is currently in process of heavy editing. Please do not modify!

Macros and Functions in NSIS are powerful tools to help make coding your installer easier and more flexible. They can also be very powerful tools, allowing you to extend the NSIS scripting language to an extent - LogicLib is a great example of this.

Definitions

Macros

From the NSIS help file: "Macros are used to insert code at compile time, depending on defines and using the values of the defines. The macro's commands are inserted at compile time. This allows you to write a general code only once and use it a lot of times but with a few changes."

If you are new to macros in any scripting language, then this may sound a bit confusing. Let's go through a few examples to show what the above means.

"Macros are used to insert code at compile time" What this means is that the code you define in a macro will simply be inserted at the location of your !insertmacro, as if copy/pasted, when you compile your installer script. For example:

!macro Hello
  DetailPrint "Hello world"
!macroend
 
Section Test
  !insertmacro Hello
SectionEnd

Could be seen as just:

Section Test
  DetailPrint "Hello world"
SectionEnd