senseful
Joined: 26 Nov 2009 Posts: 13
|
Posted: Thu Mar 11, 2010 5:19 am Post subject: #define C style macros |
|
|
[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. |
|