HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

seq and list for runtextmacro

04-25-2008, 04:05 AM#1
Vexorian
Another random idea:

Collapse JASS:
//! textmacro mytextmacro takes level
     set a[$level$]=b$level$
//! endtextmacro

//! runtextmacro mytextmacro(seq(1,10))


becomes:
Collapse JASS:
    set a1=b[1]
    set a2=b[2]
    set a3=b[3]
    set a4=b[4]
    set a5=b[5]
    set a6=b[6]
    set a7=b[7]
    set a8=b[8]
    set a9=b[9]
    set a10=b[10]
People who have dealt with generated rects should know what this is good for.

An extra argument for seq should be used for padding:
Collapse JASS:
//! runtextmacro mytextmacro(seq(7,10,"0"))

Results in:
Collapse JASS:
    set a07=b[07]
    set a08=b[08]
    set a09=b[09]
    set a10=b[10]
//this one output example is bad since it will cause compile errors,
//hope most of you have noticed the issue with this result block of text.

Also, 'list' would be nice:

//! runtextmacro mytextmacro( list("orange","red","blue") )

becomes:
Collapse JASS:
    set aorange=b[orange]
    set ared=b[red]
    set ablue=b[blue]

What to do if many list or seq are used in multiple arguments? I have decided cycling them until the largest one is consumed is the way to go:

Collapse JASS:
//! textmacro silly takes a, b , c, d
     set $a$$b$$c$$d$ = 0
//! endtextmacro


//! runtextmacro silly("M", seq(1,3), list("X","Y"), seq(9,13,"Z") )

//result:
     set M1XZ9=0
     set M2Y10=0
     set M3X11=0
     set M1Y12=0
     set M2X13=0


Well, perhaps using different sizes is not always the best idea, so using the same size probably makes more sense...
04-25-2008, 10:37 AM#2
Anitarf
Cool stuff, I imagine people who use textmacros will find this very useful.
04-25-2008, 04:15 PM#3
MaD[Lion]
me...
05-08-2008, 01:24 PM#4
Vexorian
I just decided I will include this and also try (really it is hard to do that) to make textmacros nestable.

Why did I change my mind? I just noticed textmacros can allow conditional compiling, but they would require nesting to really work...
05-08-2008, 02:07 PM#5
moyack
That would be orgasmic...