July 2018
Beginner
202 pages
5h 42m
English
When you create a new table, Lua does not give it a meta table. That is, by default a table will have a nil value for its meta table. You can assign a meta table to a table using the setmetatable method. This method takes two arguments, both are tables. The first argument is the target table, the second argument is the new meta table.
You can of course set any table to be a meta table of any other table. You can even self-assign a meta table, like the following:
container = { value = 5, __add = function(l, r) return l.value + r.value end}setmetatable(container, container) result = container + containerprint ("result: " .. result)
In this example, the container table has an __add method. Setting the container table to be its own ...
Read now
Unlock full access