[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Modules as classes?
- From: Michal Kolodziejczyk <miko@...>
- Date: Thu, 30 Aug 2007 11:25:13 +0200
Hello,
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?
I would like to have something like this:
--- class/class1.lua ---
require('Object')
local Object=Object
module('class.class1', subclassOf(Object))
function constructor(self) print("I am a class1 ctr") end
--- class/class2.lua ---
local class1=require('class.class1')
module('class.class2', subclassOf(class1))
-- test.lua --
C2=require('class.class2')
obj=C2:new()
-- expected result: "I am a class1 ctr"
Is it possible to implement something like this in pure lua? Where
should I start? Should I redefine module/require, or is there another
way? I could do it if module(name, func1, ...) could call func1 with a
parameter (e.g. parent class) or with "self", but it cannot.
Regards,
miko