[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 16:56:58 +0200
Am 17.07.03 14:52 schröbte Steve Elkins:
On Wed, 16 Jul 2003 17:22:36 -0500
RLake@oxfam.org.pe wrote:
I think, the following should work...
function Class( members, parentclass )
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
if parentclass then
local pmt = {
__metatable = parentclass,
__index = parentclass
}
setmetatable( members, pmt )
end
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