lua-users home
lua-l archive

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


Hi,

Petite Abeille wrote:

On Feb 28, 2008, at 9:18 AM, Hakki Dogusan wrote:

Can't comment on swig, but I'm using your style. In addition, I'm writing my lua code as modules too (learned this style from Petite Abeille's code):

Oh, my... :P


:)

I'm going to write ~70K line with this style.. Now, you know who'll call you if something goes wrong ;)


Another advantage of using module() *without* package.seeall, is that it forces you to declare/account for any external dependencies of a module. Cut down on typo quiet a bit.



My reasoning of liking this style is as follows (excerpt from a message sent to wxLua's list by me):

----------------------------------------------------------------------
Similar to x.cpp & x.h usage, I now have x.lua for a X class; clean
seperation/interface for public and private parts. Using __call method
as constructor made my modules very similar to cpp classes:

class X : public wxPanel {
public:
   X(wxWindow* parent);
   DoSomething() { DoPrivateThing(); }
private:
   DoPrivateThing();
}

Became;

module"X"
local function DoPrivateThing(t) end
function __call(self, parent)
   local o=wx.wxPanel(parent)
   o.DoSomething=function(t) DoPrivateThing(t) end
   return o
end
setmetatable(_M, _M)

Now both cpp and lua code looks similar:
cpp: o = X(p); o.DoSomething(); o.SetSize(..)
lua: o = X(p); o:DoSomething(); o:SetSize(..)
----------------------------------------------------------------------



Cheers,

PA.



--
Regards,
Hakki Dogusan