[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Matter of class/instance form/function...
- From: "Daniel Collins" <dcplus@...>
- Date: Sun, 16 Sep 2007 17:01:24 +1000
I use a method that is pretty much direct from the blue PiL book, 2nd
edition.
package(..., package.seeall)
function _M:method1(arg1)
-- do something
end
function _M:new(instance)
local instance = instance or {}
setmetatable(instance, self)
self.__index = self
-- additional instance initialisation goes here
return instance
end
This is pretty much your option three. The advantage is that by using
the prototype (or class table) as the metatable for class instances, you
don't require the additional table per instance. It also works well with
inheritance, as described in PiL.
- DC