2 -- Compatible with Lua 5.1 (not 5.0).
3 function class(base,ctor)
4 local c = {} -- a new class instance
5 if not ctor and type(base) == 'function' then
8 elseif type(base) == 'table' then
9 -- our new class is a shallow copy of the base class!
10 for i,v in pairs(base) do
15 -- the class will be the metatable for all its objects,
16 -- and they will look up their methods in it.
19 -- expose a ctor which can be called by <classname>(<args>)
21 mt.__call = function(class_tbl,...)
27 -- make sure that any stuff from the base class is initialized!
28 if base and base.init then
35 c.is_a = function(self,klass)
36 local m = getmetatable(self)
38 if m == klass then return true end