lua-users home
lua-l archive

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


"If you know how to export your object's functionality to Lua then you
know how to do it whether the object already exists or not.  The only
difference is that, rather than allocating the object's memory via
lua_newuserdata, you will allocate space for a pointer to the object
and store the pointer in the userdata."

I just reread this statement, could you elaborate on that a little?
All the examples I can find both in the book and on the wiki deal with
creating new instances of a class in lua, not handling existing
instances of a class from C++.

Thanks,
Ryan

On Tue, 6 Jul 2004 10:29:00 -0700, William Roper <lacutis@gmail.com> wrote:
> Ok, since there seems to be some confusion, Ill start over.
> 
> I have created a Singleton Object Factory in C++. I ask it to create
> me a new instance of a class and it provides me with a pointer to my
> new instance.
> 
> I already know in lua I can create the binding functions to allow lua
> to create instances of my class, but I don't *want* lua to create the
> instances. I want my application to create the instances, and handle
> their deletion.
> 
> I want to pass to lua a "pointer" to the instance I created and be
> able to store it in a table, along with other instances.
> 
> I then want to be able to call a lua script that iterates over the
> table, calling scripts on each instance of the class that has been
> created and registered.
> 
> When i am done with the object, I will remove the "pointer" from the
> table and call a c++ function from lua to clean up the instance.
> 
> I hope thats more understandable, I'm not exactly sure what parts I
> didn't explain well enough before.
> 
> About the light user data, yeah, I read over those and it doesn't seem
> like it will work, since you can't use metatables to create methods on
> them like full userdata.
> 
> Thanks,
> Ryan
> 
> 
> 
> On Tue, 06 Jul 2004 17:59:44 +0100, Daniel Silverstone
> <dsilvers@digital-scurf.org> wrote:
> > Peter Bradshaw wrote:
> > > (I've only been a lua user for about a month, so I may be about to get
> > > rudely slapped for inaccuracy).
> > >
> > > Light userdata sounds like exactly what you want. You just push a
> > > pointer into lua and that's what you get back.
> > >
> > > Setting the metatable from C and then checking it seems to be the way
> > > to ensure type safety.
> >
> > Erm, Light userdatas can't have metatables.
> >
> > D.
> >
> > --
> > Daniel Silverstone                         http://www.digital-scurf.org/
> > PGP mail accepted and encouraged.            Key Id: 2BC8 4016 2068 7895
> >
>