Skip to content
⌘ NSIS Forum Archive

[Newbie] différence between macro and functions

11 posts

mumuri#

[Newbie] différence between macro and functions

I only want to know the différence between a macro and a function in NSIS.

What is the 'influence' on the finale exe file ?? Is this file bigger if i use a macro ??
deguix#
Functions:

- Create smaller installers. The reason is that they are permanent codes called from one point in the script.

- They are difficult to use. You have to keep pushing and poping variables to get the parameters and create an output.

- They are only used at run time.

- They are used to create custom pages and modify other installer aspects.

Macros:

- Create bigger installers (except when using only for compile time instructions). The reason is that they are copied codes pasted where you want to "!insertmacro" them.

- They are easy to use. They are called in the form of "!insertmacro Command Parameters".

- They are used on both compile time and run time.
deguix#
Just a comment, a macro create a bigger installer when used more than once. If you would use a macro and a function with the same contents for 1 time, they would occupy the same size.
mumuri#
i understand

Juste one more thing

IF the function is just use once, we d better use a macro ??

I mean ,to use a function you must 'call' it, so the 'éxécution time' will be longer than if we had use a macro, right ??

Or does the compiler understand that the function is just use once and then, insert the function code directly in the main code (without the 'call')
Afrow UK#
If you want to use the same code more than once, you should use it within a Function, and call it with a macro.

Example:
Function Blah
Exch $R0
Push $R1
...

Pop $R1
Exch $R0
FunctionEnd

!macro CallBlah INPUT
Push "${INPUT}"
Call Blah
!macroend
Then in sections or functions:
!insertmacro CallBlah "input string / var"
Pop $R0 ;output

...
-Stu
mumuri#
yes you "re right the code will be easyer to understand

thanks

but there is a little problem

if we have this case
call Function1
Pop $R1

Push $R1
call Function2
With the macro we can not do that (if we put the Push $R1 / call Function2 in the macro).

call Function1
call Function2
iceman_k#
Doesn't MakeNSIS compress the instructions as well?
In that case repeated macros would get compressed as well.
So, the resulting installer may be a little bit bigger (in the order of bytes rather than kb) but it would be more than repaid by the increase in ease of development.