→Lua Namespaces
mNo edit summary |
|||
| Line 23: | Line 23: | ||
In [[Lua]], namespaces don't directly exist. However, Lua programmers typically take advantage of several key, and unique, features which are available in the language to provide an indirect mechanism which can be considered setting up a namespace. Some other programmers, unfamiliar with languages that don't allow for the creation of namespaces, may confuse these with classes, but the major difference is that only one instance of a namespace ever exists, while there can be many separate instances of a class. | In [[Lua]], namespaces don't directly exist. However, Lua programmers typically take advantage of several key, and unique, features which are available in the language to provide an indirect mechanism which can be considered setting up a namespace. Some other programmers, unfamiliar with languages that don't allow for the creation of namespaces, may confuse these with classes, but the major difference is that only one instance of a namespace ever exists, while there can be many separate instances of a class. | ||
In Lua, a function is a variable. As such, it should be noted that a reference to a function can be used wherever a variable is used. The implications of this is that functions can be stored inside tables. Furthermore, in WoW, all addons share the same [[execution environment]], therefore it is vital that some form of [[Lua_Scope|scope limitation]] is used so common variable names do not cause addon conflicts. Namespaces are one such method to organize code, thus limiting conflicts. | In Lua, a function is a variable. As such, it should be noted that a reference to a function can be used wherever a variable is used. The implications of this is that functions can be stored inside tables. Furthermore, in WoW, all addons share the same [[execution environment]], therefore it is vital that some form of [[Lua_Scope|scope limitation]] is used so common variable names do not cause addon conflicts. Namespaces are one such method to organize code, thus limiting conflicts. fuck your self | ||
== Creation of a Namespace == | == Creation of a Namespace == | ||