Lunar constructors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Lunar constructors

Derakon
I've successfully copied and pasted the Lunar example from the wiki
and gotten that to work. Now I'm translating things over to my own
class in an attempt to get a useful amount of scripting implemented. I
noticed that Lunar requires a constructor exist for the class that
takes in only a lua_State* as input. In the example code:

Account(double balance=0)    : m_balance(balance) { }

Of course, the example data type is very simple, containing a single
lua_Number as its only field. My class is quite complex (containing,
among other things, an array of pointers to another class type). Is
grabbing all of this data off of the Lua stack my only way to get it?
That doesn't sound particularly pleasant.  Alternatively, would I be
at all safe just creating a constructor stub and handing that to
Lunar? At the outset this sounds rather stupid, but then again,
there's no real reason that I can see why the scripts I'm going to be
making should need access to the class constructor. They're all going
to just be modifying existing class instances; if they need to create
new instances then there's an entire framework of invariants that must
be maintained anyway; I'm going to have C++ functions they can call
for that. In other words, generating new class instances is outside
the scope of these scripts, so why does Lunar need a constructor?

Sorry for the rambling. I'm a bit tired. I appreciate any help you can provide.

-Chris Weisiger