Originally Posted by semlar
Something else declaring the function locally does is prevent any addons loaded after that from modifying its behavior. Whether or not that's a good thing sort of depends on the situation.
|
A local variable of any type isn't available for access outside the scope it's defined in. There are few exceptions such as a table who's pointer is stored in another variable too.
Originally Posted by Jarod24
hehe, nevermind. I figured it out on my own.
math is a simple table wrapper that holds all the functions related to math of corse.
math.abs() simply points to the function abs() etc.
The same goes for string.upper(), it points to strupper(). its all simple aliases.
(curses his object oriented mind)
|
Actually, the
math and
string tables along with
table are function libraries that are stock in any Lua distribution. Blizzard just relinked them to different globals. Practically the same explanation, corrections only on a really minor detail, the global versions are the wrappers. There is a difference though in the trig functions (
sin(),
cos(),
tan(), etc.) as the Lua ones found in the
math table use Radians and the ones in the global namespace use Degrees.
If you're looking for easier ways to manipulate strings, all strings share the
string table as their metatable. This means you can call these functions directly from a string and by using the
obj:func() syntax, it'll pass the string itself as the first argument.
Example:
Code:
local str="some string";
print(str:upper());-- Prints "SOME STRING"
You can call these from a literal string too, but this requires some ingenuity.
Code:
print(("some string"):upper());-- Prints "SOME STRING"
Note parenthesis are used to theoretically convert the literal string into a value before the metatable can be accessed. If this isn't done, Lua will throw a syntax error.