.lua tutorials (9)

6 Name: dmpk2k!hinhT6kz2E : 2008-02-15 18:33 ID:Heaven

That's pretty close, except that metatables can be recursed. A metatable is just a normal table being used in a special way.

The problem is with the other data types. Let's say I want to make my own OO system: for this I'd attach metatables to tables. I can attach a unique metatable to a unique table if I want. I can do this with userdata too.

I cannot do that with numbers, threads, strings, or any other data type. While I can attach metatables to them, all instances of each data type must share the same metatable.

So it's possible to build any style of OO system -- that I'm aware of -- with tables and userdata, including varieties of prototype. All the other data types are stuck with a class-based OO, which won't allow you to change behaviour on individual objects.

See here for the gritty details: http://www.lua.org/manual/5.1/manual.html#2.8

This thread has been closed. You cannot post in this thread any longer.