How do metatables differ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How do metatables differ?

kaishaku13
Looking at the documentation for work4, and reading
what I have here. I am confused about how metatables
differ from tag methods. I currently use tag methods
and understand how things work. Its nice and simple.

This is my first Lua implementation, and I am going
all out with userdata/tags for an OO API only, no
regular global functions.

I am wondering if I should make the switch over to
work4 before continuing too much on my project. I
can do so now without too much fuss I think.

So can someone explain to me how metatables actually
differ from tag methods? I'm not seeing it, I see
metatables as tag methods with some changes to the
method names, or additions like "call".
("call" could actually be useful to me, but not too important)


Reply | Threaded
Open this post in threaded view
|

Re: How do metatables differ?

Roberto Ierusalimschy
> So can someone explain to me how metatables actually
> differ from tag methods? I'm not seeing it, I see
> metatables as tag methods with some changes to the
> method names, or additions like "call".

It is not that different. The main difference are about how tag
methods are stored and manipulated. In w4, tag methods are stored
in regular tables, and each table/userdata has a "metatable"
with its tag methods, instead of a tag. After you set the tag methods
for an object, the actual behavior is quite similar to Lua 4.0.

> ("call" could actually be useful to me, but not too important)

"call" is not an adition, it's only a new name for "function".

-- Roberto