[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: C++ creation of object, and Lua co-calling
- From: "Robert Sadedin" <serenity@...>
- Date: Mon, 17 Jun 2002 17:08:42 +1000
Hmmm. Interesting, and cool. How do you store a reference to the methods
in a class?
I can store a pointer to an object no sweat, but I don't know how to call a
method relating to that object without adding to lua to handle pointers to a
specific class method.
----- Original Message -----
From: "Gary Makin" <firstname.lastname@example.org>
To: "Multiple recipients of list" <email@example.com>
Sent: Monday, June 17, 2002 1:33 PM
Subject: Re: C++ creation of object, and Lua co-calling
> I think the solution depends on just what you want to do. For my project,
> I've decided to forego using tolua, and to do it all manually.
> I've got a bunch of different C++ classes, and objects of those classes,
> I wanted to have parallel objects available in Lua. I ended up putting a
> routine in each class to create the Lua object for each C++ object.
> The code creates a new Lua table, and gets a reference to it (telling Lua
> not to garbage collect the table). The reference is stored in the C++
> object, and I use that whenever C++ needs to access Lua.
> In the Lua table I've added a read-only ID entry that I use to find the
> object (I'm using STL, so pointers and iterators aren't always safe to
> For each method, or data item, that I want to have accessible from Lua,
> added a table entry for the C++ routine. Of course, these C++ routines
> different parameters than a C++ only routine would need, so I've tended to
> end up with two versions of a lot of the routines, with one calling the
> I've also added some inheritance, so I'm making a single table that's the
> parent for all the tables of one class. For example, I've got one master
> Ruin table that is the parent for all the Ruin tables that represent real
> Ruins in the game. I've added all the common methods to the parent Ruin,
> I don't need to have copies of all the functions in all the ruins, or
> of pointers for C++ functions (as I'm using Lua functions to be called fro
> Lua whenever possible).
> As a caveat, I've only got this working in the last week, so I don't have
> fully working game using this, but it seems like the system will hold up.
> Gary Makin
> Lead Programmer
> Strategic Studies Group
> On 17/6/02 6:55, "Robert Sadedin" <firstname.lastname@example.org>
> > For my game scripting, I need to be able to expose methods from objects
> > created in my c++ class to Lua.
> > I know there are a number of solutions for providing c++ classes in lua
> > long as they are created in Lua, but what about when the construction is
> > the host application?
> > Essentially, I need method sharing with the creation process being
> > consumated by the c++ app.
> > What is the simplest, and least ambitious method for doing this that you
> > experts can think of?
> > Thanks,
> > Rob