[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question: Lua Constructor Mechanism
- From: Max Ischenko <max@...>
- Date: Tue, 3 Jul 2001 10:18:49 +0300
nelson@helikon.com wrote:
> I was trying to play with Lua's simple constuctor mechanism, by using
> the example used in the document. Namely,
>
> window1 = Window{ x = 200, y = 300, foreground = "blue" }
>
> which is the syntactic sugar for
>
> window1 = Window( { x = 200, y = 300, foreground = "blue" ) } with
> initailization.
>
> However, I received following error message:
> ----------------------------------------------------------------------
> > window1 = Window{ x = 200, y=300, foreground = "blue" }
> error: attempt to call global `Window' (a nil value)
> stack traceback:
> 1: main of string "window1 = Window{ x = 200, y=300,foregroun..."
> at line 1
For this to work you should define function Window which takes a table
as argument:
function Window(t)
...
end
> I expected it should create a instance of "Window" Class (I think in
> C++. :) ) which internally creates table and the elements within. Of
> course, I can explicitly create table as a window object.
> But, I am trying to use Lua to simulate C++ syntax for prototyping
> Therefore, I intend to try this interesting feature.
Lua for prototyping?
IMHO Lua is best for embedding/extending, but not for pure prototyping.
I suggest Ruby/Python instead.
>
> I wonder if there is anything need to be created / initailized before
> constructing a object/instance using lua's constructor mechanism??
>
> Thanks in advance!! :)
> And enjoy using Lua!!
>
> Nelson
>
>
>
--
Best regards, Maxim F. Ischenko.