lua-users home
lua-l archive

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


I think some sort of implementation of a 'new' tagmethod for userdata 
would be pretty darn useful. Maybe it's possible already...

I don't know if it is currently possible to create userdata or tables 
of a specific tag type now, (ie. userdata), but I think it would be 
beneficial to have such a thing officially.

Something that might allow 'new' userdata creation, which would 
trigger that tag method, matching 'gc' on the other end of the 
lifespan.

Should such a thing be relatively easy to do? I have no clue...

I'd be willing to learn the lua code and patch it myself if it is 
relatively easy/possible to do SOMETHING like this...

The end result is simple to allow better API/C defined instantiation 
of objects, instead of a regular global function like newWindow
(200,200) you might have...

new Window(200,200)

The options currently possible in lua :

... Make a global userdata which creates all your 'classes', maybe 
its called Object with a method Create, so you have Object.Create
(Window,200,200)... This isn't perfect syntax imho though.

... A better way I think would be to make globals for each 'class', 
so you would call Window.Create(200,200), but this means you have to 
create a global 'static/abstract' for each 'class' you have, and that 
seems like it would not be efficient.

So this all makes me think that a built in 'new' tag method, with 
some syntax sugar could be of some help... Again I am willing for 
this to be merely a 3rd party patch, but first want to know if I 
should even spend my time attempting it.

What does everyone think?