[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Method call Performance (Was Re: OOP in daydream...)
- From: "Steve Donovan" <sjdonova@...>
- Date: Wed, 19 Jan 2005 14:37:36 +0200
>>> asko.kauppi@sci.fi 01/19/05 02:26PM >>>
You mean 5x access time for custom function. And that's not including
the logic within.
Yes, it would look like this (assuming that you do put a _base
field in each class):
c.__index = function(t,sym)
t = getmetatable(t)
while t do
local r = t[sym]
if r then return r end
t = t._base
end
end
as opposed to the simple 'c.__index = c', which
is highly optimized.
>"Nested metatables", I presume, is '__index' with a table reference,
am
>I right?
That's it - and for inheritance you give your metatable its own
metatable, and so on ad inf. So if lookup fails in your class, it
automatically looks in the class' base class (read: metatable)
Little tests can give interesting information!
steve d.