[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:52:40 +1000
What's the advantage of using this method over exposing straight functions?
Or have I got something very wrong?
A static member function can't access the variables within a class, so with
my limited understanding this doesn't seem to help expose the methods of the
I do rather think I am wrong though :).
----- Original Message -----
From: "Gary Makin" <firstname.lastname@example.org>
To: "Multiple recipients of list" <email@example.com>
Sent: Monday, June 17, 2002 5:50 PM
Subject: Re: C++ creation of object, and Lua co-calling
> I think this answers the question you're asking:
> The C++ function you make available to Lua must be a static member
> I really should have mentioned this. In Lua, I call the function using the
> operation, so it sticks a copy of the object on the stack. From that I
> the ID, and that allows me to get at the C++ object.
> On 17/6/02 17:08, "Robert Sadedin" <firstname.lastname@example.org>
> > Hmmm. Interesting, and cool. How do you store a reference to the
> > in a class?
> > I can store a pointer to an object no sweat, but I don't know how to
> > method relating to that object without adding to lua to handle pointers
> > specific class method.
> > ----- Original Message -----
> > From: "Gary Makin" <email@example.com>
> > To: "Multiple recipients of list" <firstname.lastname@example.org>
> > 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
> >> 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
> > and
> >> I wanted to have parallel objects available in Lua. I ended up putting
> >> 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
> >> 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
> > C++
> >> object (I'm using STL, so pointers and iterators aren't always safe to
> >> store).
> >> For each method, or data item, that I want to have accessible from Lua,
> > I've
> >> added a table entry for the C++ routine. Of course, these C++ routines
> > need
> >> different parameters than a C++ only routine would need, so I've tended
> >> end up with two versions of a lot of the routines, with one calling the
> >> other.
> >> I've also added some inheritance, so I'm making a single table that's
> >> parent for all the tables of one class. For example, I've got one
> >> Ruin table that is the parent for all the Ruin tables that represent
> >> Ruins in the game. I've added all the common methods to the parent
> > so
> >> I don't need to have copies of all the functions in all the ruins, or
> > copies
> >> of pointers for C++ functions (as I'm using Lua functions to be called
> > m
> >> Lua whenever possible).
> >> As a caveat, I've only got this working in the last week, so I don't
> > a
> >> fully working game using this, but it seems like the system will hold
> >> Gary Makin
> >> Lead Programmer
> >> Strategic Studies Group
> >> On 17/6/02 6:55, "Robert Sadedin" <email@example.com>
> > wrote:
> >>> For my game scripting, I need to be able to expose methods from
> >>> created in my c++ class to Lua.
> >>> I know there are a number of solutions for providing c++ classes in
> > so
> >>> long as they are created in Lua, but what about when the construction
> > in
> >>> 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
> >>> experts can think of?
> >>> Thanks,
> >>> Rob