Announcement

Collapse
No announcement yet.

[Newbie] différence between macro and functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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 ??

  • #2
    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.
    My Wiki Pages

    Working now on:
    New projects. (language: any)

    Comment


    • #3
      ok thanks

      Comment


      • #4
        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.
        My Wiki Pages

        Working now on:
        New projects. (language: any)

        Comment


        • #5
          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')

          Comment


          • #6
            Yes, that's the only exception where the !macro wins about the size.
            My Wiki Pages

            Working now on:
            New projects. (language: any)

            Comment


            • #7
              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:
              code:
              Function Blah
              Exch $R0
              Push $R1
              ...

              Pop $R1
              Exch $R0
              FunctionEnd

              !macro CallBlah INPUT
              Push "${INPUT}"
              Call Blah
              !macroend

              Then in sections or functions:
              code:
              !insertmacro CallBlah "input string / var"
              Pop $R0 ;output

              ...

              -Stu

              Comment


              • #8
                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

                Comment


                • #9
                  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.
                  Cheers,
                  Iceman_K

                  EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki

                  Comment


                  • #10
                    Just use the code like that then.

                    -Stu

                    Comment


                    • #11
                      or even integrate function1 into function2
                      hand by comm@nder21
                      ----------
                      WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎