SWIG-Lua question on class returning another class

Posted by John Smith on Stack Overflow See other posts from Stack Overflow or by John Smith
Published on 2010-05-19T02:02:00Z Indexed on 2010/05/19 23:30 UTC
Read the original article Hit count: 212

Filed under:
|
|

I am concreting a question I had earlier.

I have two classes in C++ and I use SWIG to wrap them. A method in one class can return a pointer to the other class. How can I get Lua to see it as more than just a userdata?

More concretely:

I have

class fruit
{
     int numberofseeds;
  //some other stuff about fruit constructors etc...
   public:
     getseedcount()
     {
        return numberofseeds;
     }
}

class tree
{
    fruit * apple; 
    public:
      //constructors and whatnot
    fruit * getfruit()
    {
         return apple;
    }

}

I wrap these two class with SWIG so I can access them in Lua

So I can get in Lua the object x=pomona.tree(grannysmith).

My question now is: How can I arrange for things so that when I type y=x:getfruit() I will get a pomona:fruit type object? Where I can write something line y:getseedcount()? At the moment all I get is userdata which not edible.

© Stack Overflow or respective owner

Related posts about swig

Related posts about lua