lua-users home
lua-l archive

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

Sorry. I haven't used Lua for this kind of thing before so I'm not sure which details would be of use.

I'll rename the classes for simplicity. I have a 'Person' class which exists entirely in C++. The Person setup function gives each Person lots of base values. I would like to be able to make a new class type, Solider, which is derived from Person. I want Soldier to exist entirely in Lua. Here's the bones of what I'm talking about:

class 'Soldier' ( Person )

function Soldier:__init()


function Soldier:Setup()


function Soldier:Update()


The strange setup used in the program prevents me from doing something as simple as:

function Soldier:Setup()
     self:PersonSetup() -- where all of the things would be set

Instead, I have to make a Person first in C++ and then cast it to a Soldier later with Lua like:
void Person::Setup()
     // set all Person things (there are a lot)
     //call Lua to make a new Soldier (__init)
     //try to fill that blank soldier with the values from this person but retain Soldier's Lua functions --this is the part I can't figure out

In C++, it'd just be a simple downcast like:
Soldier s = (Soldier)thisPerson

but I can't do that with a pure Lua class like Soldier because there is no C++ Soldier class, only a Lua one. I'm wondering how to get the data from the Person base class into the newly created blank Lua Soldier class.

I hope they're the details you're looking for. I could really use any help anyone can offer on this.