lua-users home
lua-l archive

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

On Tue, 2005-02-01 at 06:10, André de Leiradella wrote:
> > On Jan 29, 2005, at 18:30, André de Leiradella wrote:
> > 
> >> b = new B('me')
> > 
> > This is beyond Evil! It looks like Java! :8^)
> > 
> > What about something more like "b = 'me' )" instead?
> > 
> > Cheers
> It's not a proposal, just a common syntax. I'd like too to have multiple
> constructors in Lua as it is dynamic typed (it get's too confusing
> inside the only constructor to compare all possible combinations of
> arguments to decide how to instantiate the object).

This isn't really needed in a reasonable language,
for example C++. You only need one constructor.
In Ocaml, which has the best OOP system around,
there is only one allowed.

Instead, you just use functions which call that
one constructor.

class complex {
   complex(double x, double y);
   friend cart..
   friend polar..

complex cart(double x, double y);
complex polar(doube r, double theta);

In C++, you can use friends and a private constructor.
In Ocaml you can, as usual, use modules.
In Lua, there's no encapulsation anyhow.

Whichever way, you can use factory functions (plural)
to create objects instead of constructors.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language