AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

#define C style macros

 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
senseful



Joined: 26 Nov 2009
Posts: 13

PostPosted: Thu Mar 11, 2010 5:19 am    Post subject: #define C style macros Reply with quote

[Moderator's note: Split from AutoHotkey_L thread.]

Is there any place to request new features?

More specifically, I would like to see C style macros implemented for debugging purposes mainly, which can take advantage of script variables (A_LineNumber, A_ThisFunc, etc).

For example:

Code:
#define Assert(CONDITION) AssertFn(CONDITION, #CONDITION, A_LineNumber)

; ...

AssertFn(bCondition, sCondition, lineNumber) {
  if (!bCondition) {
    MsgBox, % "Assertion Failure: " . sCondition . " @ line " . lineNumber
    ExitApp
  }
}

; ...

Assert(myVar != "invalid")


Would expand to the following code:

Code:
; #define Assert(CONDITION) AssertFn(CONDITION, #CONDITION, A_LineNumber)

; ...

AssertFn(bCondition, sCondition, lineNumber) {
  if (!bCondition) {
    MsgBox, % "Assertion Failure: " . sCondition . " @ line " . lineNumber
    ExitApp
  }
}

; ...

AssertFn(myVar != "invalid", "myVar != ""invalid""", A_LineNumber)


The reason that both an Assert macro and AssertFn is needed is because if the assert macro expanded to two lines, it would mess up A_LineNumber, causing it to report the line number plus one, which is bad. Thus, we must make sure each macro only produces one line of code. Additionally, #define commands should be commented at the top (instead of removed) to also prevent the first few lines from messing up A_LineNumber.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Thu Mar 11, 2010 9:21 am    Post subject: Re: #define C style macros Reply with quote

senseful wrote:
Is there any place to request new features?
There's a whole forum for it. There's even at least one thread where this feature has already been requested: #define.

One thing about pre-processors: they don't need to be built-in. For instance, AHK preprocessor supports #define identifier and #ifdef identifier .. #endif. It doesn't support the usage of #define you're after, but it could be done. A_LineNumber need not be out of sync - the preprocessor could replace it with the original line number.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group