Advanced macro and goddamn indentation
#1

pawn Код:
#define each(%0,%1=>%2,%3,%4){      for(new %3 = 0, %4 = sizeof(%0)-1, %2[%1]; %3 <= %4; ++%3){\
                                        %2=%0[%3];
This is final version of my macro, it works like:
pawn Код:
each(EArray, etype => item, i, j){
}
//Changes into
for(new i = 0, j = sizeof(EArray) - 1, item[etype]; i <= j; ++i) {
item = EArray[i];
}
Anyway - because of the assignment of value in new line my indentation is screwed up, and compiler complains about loose indentation. How to solve it without hiding the error instead of fixing it?
Reply
#2

I was struck by lightbulb - so I'm posting solution for future use:

pawn Код:
#define each(%0,%1=>%2,%3,%4){      for(new %3 = 0, %4 = sizeof(%0), %2[%1]; %3 < %4 && (%2=%0[%3]); ++%3){

//Usage
each(EArray, type => item, i, j) {}
//Changes to
for(new i = 0, j = sizeof(EArray), item[type]; i < j && (item = EArray[i]); ++i) {}
Where's the magic? Well, I simply treated assignment as a boolean, so it happens only if i < j (&& goes left to right). Without the && you'll run into array out-of-bonds crash.
Reply
#3

pawn Код:
#define Foo(%0){    for(new i = 0, %0; i < 5; ++i) { %0 = i;

Foo(bar) {
(...)
}
Gives loose indentation as well
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)