lua-users home
lua-l archive

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


>> Back to the problem: What I would really like to have is a mechanism
>> whereby a metatable can redirect calls to metamethods in a way that
>> they actually appear as undefined when they are not defined in
>> whatever place they are redirected to. Does anyone have an idea how I
>> could achieve this?

WC> All this sounds to me as if you more or less want to mimic the Python class
WC> system.

I don't know anything about python, so I can't comment on wether my
attempt mimicks pythons class system. Basically I wanted something
like the php approach, enough to work with, but not so much to get in
your way. Because of the nature of lua, I got some additional features
"for free" while doing this.

WC> function instance_meta:__add(other)
WC>     local add = self.__add
WC>     if add then return add(self, other) end
WC>     add = other.__radd
WC>     if add then return add(other, self) end
WC>     print "__add not supported"
WC> end

yes, this one looks good. It is not quite what I wanted, but it almost
does the same job. I will give it a try, and see how it works with my
other stuff.


"They that can give up lib-   Gunnar Zötl           Tel. 06071-612079
 erty to obtain a little      Friedhofstraße 55     Fax. 01212-512317564
 temporary safety deserve     64859 Eppertshausen   E-mail
 neither liberty nor safety" - Benjamin Franklin, 1706-1790