lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> I think it is important to separate unified methods in two 
> quite independent parts: the first part is keeping tag 
> methods in a table (what you call "exposing it as tables"); 
> but there is a the second part: to look into this table for 
> "methods" when you use the syntax a:foo().
> (The first part is actually simpler than the current tag 
> system, and we are considering adopting it in the next 
> version of Lua. It is very easy to implement the current 
> system using the new one; and we will do it, to keep compatibility).

When I made the LuaState distribution's method table support, I misnamed
it as "unified methods" when, in fact, it was method tables that hoped
to one day become unified methods.  But the benefits of method tables
and unifying the tag methods are entirely different.

At no cost to the original implementation of Lua, method tables can:

* Make every data type look like an object by attaching a table of
methods.  This is somewhat like C#'s "boxing" concept.
* Remove the need to implement the gettable tag which must be assigned
to a userdata object.
* Save massive amounts of memory by sharing the same method table among
multiple objects.  This is as opposed to the current table mechanism
where every table has to have a copy of the functions.
* To C++ users, this looks more like the v-tables they're accustomed to.

Unified methods, on the other hand, are there for the unification of tag
methods with the method tables.  If method tables exist, then the tag
methods, IMO, make the most sense in the method tables.  The biggest
benefit unified tag methods provide is removal of the complexities of
tag and tag method management.  If you can work with a method table, you
automatically get tag methods.

More than anything else, though, having Lua adopt method tables is very
important, in my opinion.  But Lua should NOT change the : (colon)
function calling operator to remove the self parameter and only call out
of method tables like Edgar did.  I believe it is important to
distinguish between a regular table function call and a method table
function call.  The LuaState distribution does this by introducing the
-> (like the colon but for method tables) and the :: (like a regular .
Period table lookup).