[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Simple classes
- From: Rebel Neurofog <rebelneurofog@...>
- Date: Wed, 1 Jun 2011 14:58:09 +0400
actor = {}
function actor.new ()
local self = {}
-- public:
function self.update ()
print ("Actor::update")
end
return self
end
soldier = {}
function soldier.new ()
local self = actor.new ()
-- private:
local actor_update = self.update
-- public:
function self.update ()
actor_update ()
print ("Soldier::update")
end
return self
end
local soldier1 = soldier.new ()
soldier1.update ()
-------- Jose, is that OO enough?
-------- If not, here's the trick:
actor = {}
local function actor_new ()
local self = {}
-- public:
function self.update ()
print("Actor::update")
end
return self
end
setmetatable (actor, {__call = actor_new})
soldier = {}
local function soldier_new ()
local self = actor ()
-- private:
local actor_update = self.update
-- public:
function self.update ()
actor_update ()
print("Soldier::update")
end
return self
end
setmetatable (soldier, {__call = soldier_new})
local soldier1 = soldier ()
soldier1.update ()