Overloading operators by operator symbol

Daniel Keep daniel.keep.lists at gmail.com
Mon Oct 30 06:03:31 PST 2006



Bill Baxter wrote:
> ..., Lua has very similar, ...

Just pointing out that Lua's special methods are in a completely
different namespace to the "normal" methods, so it isn't a problem.
Special methods are attached to a table's metatable, which exists just
for that purpose.

> local t = {}
> local mt = getmetatable(t) or {}
>
> function mt:index(k)
>     return "foo"
> end
>
> setmetatable(t, mt)
>
> io.print(t.blah) -- prints "foo"

Apologies if any of that is incorrect; very sleepy over here :3

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list