lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I use this style:

local MyClass = {}
local MyCalssMT = {__index = MyClass}

function MyClass.new()
    local self = {} -- or call the base class constructor
    setmetatable(self, MyClassMT)

    return self
end

...
other methods
...

return MyClass

This way I don't pollute' the names:

local MyClass = require("MyClass")
local obj = MyClass.new()
....

On Wed, Jul 22, 2009 at 4:33 PM, Petite Abeille<petite_abeille@mac.com> wrote:
>
> On Jul 22, 2009, at 9:14 PM, Wesley Smith wrote:
>
>> After reading module v. dofile discussion I was curious how people
>> handle OO constructs as Lua modules.
>
> A while back, this is what I used:
>
> local LUObject = require( "LUObject" )
> local super = LUObject
> local self = super()
>
> For example, a List object:
>
> http://dev.alt.textdrive.com/browser/lu/LUList.lua
>
> Some usage examples:
>
> http://dev.alt.textdrive.com/browser/lu/Example.lua
>
> Root object:
>
> http://dev.alt.textdrive.com/browser/lu/LUObject.lua
>
> But, after reflexion, I moved away from OO in Lua. Not worth the bother :))
>
> Cheers,
>
> PA.
>
>



-- 
http://oproj.tuxfamily.org