Archive: !define /redef flag


!define /redef flag
  According to The Official NSIS Documentation, !define supports a /redef flag. I want to use this in my installer, but the latest release version (2.46 at the time of this post) apparently throws an error when I try to use this. The documentation that was installed with this version does not mention the /redef flag. Is this something that's in a development version of NSIS?

Thanks,
Joe


Originally posted by JoeMcC00L
Is this something that's in a development version of NSIS?
according to the development changes, it was added on 10th June so is only available from svn and requires you to build NSIS via Scons to get it ahead of a full release with it included.

-daz

while you wait, just use a !ifdef +!undef + !define macro


Thanks for the quick answer. I'll just wait for the next release then.

FYI, I was trying to do find a better way to do this:

LangString DESC_SecUnecessaryID ${LANG_ENGLISH} "Description"
Section "Section Name" SecUnecessaryID
; regular section code goes here
SectionEnd

;... somewhere near the end of the file
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecUnecessaryID} $(DESC_SecUnecessaryID)
;... do this for all the sections
!insertmacro MUI_FUNCTION_DESCRIPTION_END


If I could use the /redef flag, I could refactor this code into a header file and use my own custom section tags:

${CUSTOM_SECTION} "Section Name" "Description"
; Normal section goes here
${CUSTOM_SECTION_END}


Granted, you do lose some flexibility with internationalization, but our project has no such requirement. The /redef flag would be used to keep count of how many sections were being declared so it could build the MUI_FUNCTION_DESCRIPTION section at the end of the code by calling something like:

!insertmacro CUSTOM_SECTION_DESCRIPTIONS


No big deal. I'll probably end up working on it again once this feature is in the latest stable release.

Thanks,
Joe

I still don't understand why you have to wait

!macro ReDef name val

>!ifdef ${name}
!undef ${name}
!endif
!define ${name} "${val}"
>!macroend
>!define ReDef "!insertmacro ReDef "
>...
!define foo bar
>${ReDef} foo baz
>

I can't get into more specifics, but basically something like this:


!define SecCount 0
!macro CUSTOM_SECTION "Name" "Description"
!define /redef /math SecCount ${SecCount} + 1
LangString DESC_SecCustom${SecCount} ${LANG_ENGLISH} ${Description}
Section ${Name} SecCustom${SecCount}
!macroend


In the code for CUSTOM_SECTION_DESCRIPTIONS, I would use macro recursion to loop through ${SecCount} sections and call MUI_DESCRIPTION_TEXT. Hopefully when the next version of NSIS is released I'll make another post with the full-working code.

Thanks,
Joe

!define SecCountTmp ${SecCount}
!undef SecCount
!define /math SecCount ${SecCountTmp} + 1

Stu



ifdef define

!undef define
>!endif

!macro USER_DEFINE CONSTANT VALUE
!ifndef ${CONSTANT}
!
define ${CONSTANT} ${VALUE}
!endif
!macroend

>!define define '!insertmacro USER_DEFINE'
${define} PI 3.14

Originally posted by Afrow UK
!define SecCountTmp ${SecCount}
!undef SecCount
!define /math SecCount ${SecCountTmp} + 1

Stu
Great work! I actually used this to make an Increment macro that does exactly what I needed it to do.

!macro _increment _value
!define _tempVal ${${_value}}
!undef ${_value}
!define /math ${_value} ${_tempVal} + 1
!undef _tempVal
!macroend

!define INCREMENT "!insertmacro _increment"


The newest problem is that I can't perform any sort of looping by the compiler. Recursive macro calls are unsupported (and probably a bad idea as well). I guess there's a reason I haven't seen anyone else try this. :-)

Thanks for your help!

Wait, why the ${${_value}}? Did I put that in my post? If _value = 1 say then that will evaluate to ${1} (and will stop there unless you happen to have !define 1 somewhere). It might work if /math parses out the 1 but you don't want the double parentheses.

Stu


Sorry, I didn't make it clear:

!define sectionCount 0
${INCREMENT} sectionCount
; Now ${sectionCount} = 1


In other words, _value isn't 1. _value is expected to be a defined symbol with a value. Works every time.

Thanks,
Joe

Ah right yep that's fine.

Stu