Game Development Reference
In-Depth Information
Metatables
A metatable in Lua is a table primitive that allows custom functions to override common
operations such as addition, subtraction, assignment, and so on. The sandbox uses metat-
ables extensively in order to provide common functionality to the userdata that C++ man-
ages.
To retrieve a metatable within Lua, use the getmetatable function on any object:
metatable getmetatable(object);
To set a metatable within Lua, use the setmetatable function that passes both the ob-
ject to set and the metatable:
nil setmetatable(object, metatable);
Tip
As the sandbox heavily uses metatables for userdata, you can always use getmetatable
on the userdata to see which operations a specific userdata type supports.
Search WWH ::




Custom Search