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
9 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
9 years ago

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

0
Could be a comment.. RepeatLua 90 — 8y
Ad
Log in to vote
0
Answered by 8 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