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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6 ■ Lua St<strong>and</strong>ard Libraries 105optional numerical argument—init—specifies where to start the search; itsdefault value is 1 <strong>and</strong> may be negative. A value <strong>of</strong> true as a fourth, optionalargument, plain, turns <strong>of</strong>f the pattern matching facilities, so the functiondoes a plain ‘‘find substring’’ operation, with no characters in pattern beingconsidered ‘‘magic.’’ Note that if plain is given, init must also be given.If the pattern has captures, then in a successful match the captured valuesare also returned, after the two indices.Math LibraryThe math library provides an interface to several st<strong>and</strong>ard math functions <strong>and</strong>constants. Table 6-8 describes some <strong>of</strong> the more common functions in the mathlibrary. (It is not a full listing <strong>of</strong> the library; <strong>for</strong> that, please consult a properLua reference, which includes a full set <strong>of</strong> trigonometric functions such asmath.cos, math.sin, math.tan, <strong>and</strong> so on.)Table 6-8: Math FunctionsFUNCTION DESCRIPTION EXAMPLEmath.abs(x) Returns the absolutevalue <strong>of</strong> x.> print(math.abs(13))13> print(math.abs(-13))13math.ceil(x)math.deg(x)math.exp(x)math.floor(x)Returns the smallestinteger larger than orequal to x.Returns the angle x(given in radians) indegrees.Returns the value <strong>of</strong> themathematical constanteraisedtothex power.Returns the largestinteger smaller than orequal to x.> print(math.ceil(1.03))2> print(math.cell(13))13> print(math.cell(17.99))18> print(math.deg(math.pi))180> print(math.deg(math.pi * 2.5))450> print(math.exp(27))532048240601.8> print(math.floor(1.03))1> print(math.floor(13.0))13> print(math.floor(17.99)17Continued

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

Saved successfully!

Ooh no, something went wrong!