Advanced macro and goddamn indentation - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Advanced macro and goddamn indentation (
/showthread.php?tid=413443)
Advanced macro and goddamn indentation -
Misiur - 05.02.2013
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?
Re: Advanced macro and goddamn indentation -
Misiur - 05.02.2013
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.
Re: Advanced macro and goddamn indentation -
Misiur - 05.02.2013
pawn Код:
#define Foo(%0){ for(new i = 0, %0; i < 5; ++i) { %0 = i;
Foo(bar) {
(...)
}
Gives loose indentation as well