Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Object-oriented programming
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Instantiation and Construction ==== A class is constructed typically by a function. This provides a single point of creation which is very modular. Typically this function is called "new," though it is not required. First, the function must create a blank table. Then, it must imbue the table with the properties of the class. This may be functions, variables, or other contents which the class must store. the following example shows a simplistic class which creates a Character instance, which stores only the name of the character. Character = {}; function Character:new() local self = {}; -- Create a blank table self.name = "Unknown"; -- Make a name variable in the class return self; -- Return the instance end We can now create multiple instances of the class very quickly: local player1 = Character:new(); -- Create a Character local player2 = Character:new(); -- Create another player1.name = UnitName("player"); player2.name = UnitName("target"); We will discuss later why the name "self" is logical for this table we create, but it can actually be any name of your choosing. It is, however, typically seen as "self" because it has logical connections to the syntax used in functions, as will be discussed later.
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)