lua-users home
lua-l archive

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


>I would like data access to occur when using the '.' syntax and a function
>access to occur when using the ':' syntax .

In principle, this is not possible because userdata:Add() is simply sugar for
userdata.Add(userdata).

As you mention, the opcode for userdata.Add is GETDOTTED while the opcode for
userdata:Add() is PUSHSELF (always followed by a CALL), so the parser knows all
about this, but unfortunately there is no language-level way to make this
distinction.

A similar problem occurs when you try to trap calls such as f() where f
is not defined. You may set a "getglobal" tag method but it is called *before*
the call is attempted.

One possible solution for both problem is to have the "gettable" or "getglobal"
tag method return a table for which a "function" tag method is defined.
--lhf