Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

What is a metatable?

Asked by
bloxxyz 274 Moderation Voter
10 years ago

Can someone break it down for me? The wiki is confusing for me and I don't understand it's purpose and what it does. Can anyone help? Thank you!

2 answers

Log in to vote
1
Answered by
acecateer 130
10 years ago

Go here, I found it very useful for better understanding metatables.

0
Could be a comment.. RepeatLua 90 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

To explain metatables to a beginner, I would say it's a table within a table that manages the table.

local t = {"pizza", "pie"}
local mt = {__index = function(t, i, v)
    return "ice"
end}
setmetatable(t, mt)

Basically what this code will return "ice" if you try to index a nil value inside table "t".

Answer this question