Old 28th June 2010, 21:59   #1
JoeMcC00L
Junior Member
 
Join Date: Mar 2006
Location: Orlando, FL
Posts: 38
!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
JoeMcC00L is offline   Reply With Quote
Old 28th June 2010, 22:18   #2
DrO
 
Join Date: Sep 2003
Posts: 27,873
Quote:
Originally Posted by JoeMcC00L View Post
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
DrO is offline   Reply With Quote
Old 28th June 2010, 22:24   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,163
while you wait, just use a !ifdef +!undef + !define macro

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 29th June 2010, 01:42   #4
JoeMcC00L
Junior Member
 
Join Date: Mar 2006
Location: Orlando, FL
Posts: 38
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:

code:
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:

code:
${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:

code:
!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
JoeMcC00L is offline   Reply With Quote
Old 29th June 2010, 02:05   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,163
I still don't understand why you have to wait
PHP Code:
!macro ReDef name val
!ifdef ${name}
!
undef ${name}
!endif
!
define ${name"${val}"
!macroend
!define ReDef  "!insertmacro ReDef "
...
!
define foo bar
${ReDeffoo baz 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 29th June 2010, 17:40   #6
JoeMcC00L
Junior Member
 
Join Date: Mar 2006
Location: Orlando, FL
Posts: 38
I can't get into more specifics, but basically something like this:

code:

!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
JoeMcC00L is offline   Reply With Quote
Old 29th June 2010, 19:43   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
!define SecCountTmp ${SecCount}
!undef SecCount
!define /math SecCount ${SecCountTmp} + 1

Stu
Afrow UK is offline   Reply With Quote
Old 1st July 2010, 02:04   #8
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Shanghai, China
Posts: 206
PHP Code:
!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
jiake is offline   Reply With Quote
Old 7th July 2010, 01:38   #9
JoeMcC00L
Junior Member
 
Join Date: Mar 2006
Location: Orlando, FL
Posts: 38
Quote:
Originally Posted by Afrow UK View Post
!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.

code:
!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!
JoeMcC00L is offline   Reply With Quote
Old 7th July 2010, 09:10   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 7th July 2010, 23:02   #11
JoeMcC00L
Junior Member
 
Join Date: Mar 2006
Location: Orlando, FL
Posts: 38
Sorry, I didn't make it clear:

code:
!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
JoeMcC00L is offline   Reply With Quote
Old 7th July 2010, 23:24   #12
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Ah right yep that's fine.

Stu
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
define, redef

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump