12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6 ■ Lua St<strong>and</strong>ard Libraries 97Confused yet? More <strong>of</strong>ten than not, you’ll only use a very small subset <strong>of</strong>these options, but it’s good to underst<strong>and</strong> the abilities <strong>and</strong> limitations <strong>of</strong> thestring <strong>for</strong>matting system. The examples in Table 6-2 should help clarify thebasics <strong>of</strong> string <strong>for</strong>matting.Table 6-2: Example Format StringsCOMMANDstring.<strong>for</strong>mat(“%%c: %c“, 83)RESULT%c: Sstring.<strong>for</strong>mat(“%+d“, 17.0) +17string.<strong>for</strong>mat(“%05d“, 17) 00017string.<strong>for</strong>mat(“%o“, 17) 21string.<strong>for</strong>mat(“%u“, 3.14) 3string.<strong>for</strong>mat(“%x“, 13)string.<strong>for</strong>mat(“%X“, 13)string.<strong>for</strong>mat(“%e“, 1000)string.<strong>for</strong>mat(“%E“, 1000)DD1.000000e+031.000000E+03string.<strong>for</strong>mat(“%6.3f“, 13) 13.000string.<strong>for</strong>mat(“%q“, [[“One“, “Two“]])string.<strong>for</strong>mat(“%s“, “monkey“)string.<strong>for</strong>mat(“%10s“, “monkey“)string.<strong>for</strong>mat(“%5.3s“, “monkey“)“\“One\“, \“Two\““monkeymonkeymonIN WORLD OF WARCRAFT<strong>WoW</strong> includes an extra option <strong>for</strong> string.<strong>for</strong>mat() that allows you tochoose a specific argument from the argument list, rather than having themin consecutive order. This option is not included in st<strong>and</strong>ard Lua 5.1, so youwill need to use one <strong>of</strong> the interpreters provided on the book’s website(http://wowprogramming.com/utils) to test this. If you are using the<strong>WoW</strong>Lua addon, it should work correctly.To select a specific argument, include the number <strong>of</strong> the argument, followedby the dollar sign ($), immediately after the percent sign (%). For example:> print(string.<strong>for</strong>mat(“%2$d, %1$d, %d“, 13, 17))17, 13, 17The first type identifier is modified to request the second argument, <strong>and</strong> thesecond identifier consumes the second argument to the <strong>for</strong>mat string. Whenselecting parameters in this way, you can’t skip any <strong>and</strong> leave them unused.(continued)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!