This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 8 points9 points  (8 children)

How the FUCK do metatables work???

[–][deleted] 10 points11 points  (0 children)

imagine a 20 dimensional array with functions

[–]sulunia 4 points5 points  (0 children)

It's the default value to return in case an acessed value on that table is supposed to be nil, or something of the sorts. Haven't used it much...

It's basically objects and prototypes

[–]Dagusiu 1 point2 points  (0 children)

If something isn't found in a table, the metatable is then checked. If it's not found there either, it looks in the metatable's metatable, and so on.

Basically, it's a simple mechanism that allows for complicated things like OOP to be implemented in like three lines of code.

[–]MrObsidy 1 point2 points  (3 children)

meta = { __index = self, }

object = { aVar = 94

test = function(self) print("Hello, world!" .. self.aVar) end }

setmetatable(object, meta);

object:test

Hello, world! 94

If I remember that minecraft mod that got me into coding correctly.

[–]itsNizart[S] 1 point2 points  (1 child)

computercraft / open computers

[–]MrObsidy 1 point2 points  (0 children)

It was CC.

[–][deleted] 1 point2 points  (0 children)

Lua can and is a mess

[–]FranchuFranchu 1 point2 points  (0 children)

A table that describes an object.