[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modules as classes?
- From: PA <petite.abeille@...>
- Date: Thu, 30 Aug 2007 19:00:43 +0200
On Aug 30, 2007, at 11:25, Michal Kolodziejczyk wrote:
I woul like to write some classes (to get some OO and inheritance),
which could also be modules (to get autoload and 'dotted' names
notation). What is the way to accomplish it?
Tomas demonstrated something a while back which elegantly leverage
Lua's built-in module system:
http://lua-users.org/lists/lua-l/2006-03/msg00336.html
Something along these lines:
local function extends( aSuper )
return function( aClass )
setmetatable( aClass, aSuper )
aClass.__index = aClass
aClass.self = aClass
aClass.super = aSuper
return aClass
end
end
local class = module
class( 'Object', extends(), package.seeall )
class( 'MyObject', extends( Object ) )