lua-users home
lua-l archive

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


On Sunday 30 May 2004 15:26, M vd Honing wrote:
> Is it possible to automaticaly translate a . To : for function calling?
> I know they do something different, but i do not like the use of two
> different chars for what for the end user apears to be the same thing. I
> cannot explain to them why setting a var requires a . and calling a
> function requires a :

Use a scheme along the lines of the following (untested):

Classvar_methods = { ... }
Classvar = setmetatable({}, { __index =
    function(t, k)
        return function(...)
            return Classvar_methods[k](t, unpack(arg))
        end
    end
})

Be aware that this will confuse anyone who does know to use a colon, or simply 
wants to obtain the method function rather than call it, since those forms 
will end up with the subject being passed twice. You may be able to get 
around that, e.g. by checking the length of the argument list and type of the 
second argument, but that definitely lies in ugly hack territory.

-- Jamie Webb