lua-users home
lua-l archive

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

Hi Jose,

Thanks for your replay.
The method you suggested is too complicated for me and I do not wish to use any other external libraries...

Please find how I did it eventually - I guess it has a lot of problems because I'm in to Lua for 2 days now ;)

Any kind of feedback is appreciated!


On Wed, Sep 7, 2011 at 11:13 AM, Jose Luis Hidalgo <> wrote:
Hi Guy,

 I had a similar problem long time ago, but I wanted to be able to
"inherit" from lua C++ classes (just one more step), I finally did
something like that in "Simple Lua Binder" (SLB), it's called Hybrids.
Basically you start by declaring a class which is the C++ interface:

class HClass : public SLB::Hybrid<HClass>

               /* int get() { return LCall<int>("get"); } */

               /* void calc(int a, int b) { return LCall<void, int,
int>("calc"); } */


Now from any script in lua you can give the implementation for HClass:
function HClass:calc(a,b)
       print("Calling virtual method HClass:calc")
       if SLB.type(self) ~= "Unit_002::HClass" then
               error("Invalid instance @ calc")

or create new "types" from HClass:

function HClass.Type1:calc(a,b)
       return a+self:other(b)

and so on, for more details at the end of the mail I leave some links
to the hybrid tests.




On Wed, Sep 7, 2011 at 8:55 AM, Guy J <> wrote:
> Hey there Lua fellows!
> First e-mail I'm sending to the list - I hope this is not a repeated
> question, I searched through the archive and couldn't find what I'm looking
> for.
> So.. I've built a game engine in C++ and I have a GameObject class that
> represents all the objects in my game, now I have some other classes that
> derive from GameObject, such as Robot, Bullet, Player, etc...
> What I'd like to do is to extend the GameObject class in Lua instead of
> making C++ derivatives, to keep the engine as clean and simple as possible.
> The Lua object should have awareness of it's own type, and state. For
> instance, the 4 callbacks that will make the object "tick" would be
> Construct, Destruct, Update, Collide -> these will be implemented in Lua.
> These methods should be able to call getLinearVelocity, getPosition,
> applyForce, etc... that will be implemented in the game engine. All of these
> method should work on the context of the same instance.
> What is the best approach for doing what I described?
> Appreciate your help!
> Thanks,
> Guy

  Jose L. Hidalgo Valiño (PpluX)
  ---- ----

Description: Zip archive