[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: inheritance example
- From: Philipp Janda <siffiejoe@...>
- Date: Thu, 17 Jul 2003 17:45:30 +0200
Am 17.07.03 16:56 schröbte Philipp Janda:
I think, the following should work...
Or this for multiple inheritance (untested!)...
function Class( members, ... )
members = members or {}
local mt = {
__metatable = members;
__index = members;
}
local function new(_, init)
return setmetatable(init or {}, mt)
end
local function copy(obj, ...)
local newobj = obj:new(unpack(arg))
for n,v in pairs(obj) do newobj[n] = v end
return newobj
end
members.new = members.new or new
members.copy = members.copy or copy
local pmt = {
__index = function( _, key )
for i=1,arg.n do
local parentmethod = arg[i][key]
if parentmethod then
return parentmethod
end
end
end
}
setmetatable( members, pmt )
return mt
end
...how can it be extended so that classes can have parents. If it's
already there, I don't see it.
Thanks,
Steve
Philipp