KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
| |
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 08:37 PM |
A metatable is a table, literally, but it is useful because of it's metamethods. It's very powerful and in some cases, essential to use it (OOP in some cases, sandboxing, etc.).
Anyways, you can set a metatable of a table by using the setmetatable function (and yes, you can set a metatable to a metatable, since metatables are tables). You can get a metatable of a table by using the getmetatable function (and yes, you can get a metatable of a metatable, since metatables are tables).
Commonly used metamethods include: __index (invoked when trying to index a nil value) __newindex (invoked when tbl[key] = value and it's nil) __call (invoked when tbl(...)) __add, __sub, __mul, __div (invoked when tbl +, -, *, /) __unm (invoked when -tbl) __lt, __le (invoked when tbl <, <=) and more.
I'll find a link on them right now. |
|
|
| Report Abuse |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 08:37 PM |
| http://www.lua.org/pil/13.html |
|
|
| Report Abuse |
|