"no RTTI data" when invoking a factory method from Lua

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

"no RTTI data" when invoking a factory method from Lua

Pablo Palmier Campos
Hi to all,

I'm new to Luabind, so excuse me if this is somewhat recurrent. I've
been reading the docs and making my own tests, but I haven't found an
adequate solution for my problem. Currently, I'm using Luabind 0.7
with Lua 5.0.2. The best I can is to provide an example:

Suppose we have the following C++ classes:

class _A {
public:
         virtual void foo() = 0;
};

class _B : public _A {
public:
         void foo() {
                printf("B:foo()");
         }
};

And then we have an "A's" factory:

class AFactory {
public:
                static _A *create(int nId) {
                _A *pRet;

                if (nId == 1)  {
                        pRet = new _B();
                }
                else {
                        pRet = NULL;
                }

                return pRet;
        }
};

We register the former classes in luabind and the function to create A
valid instances:

        class_<_A>("_A"),
        class_<_B, _A>("_B"),
        def("createA", AFactory::create)

In our LUA script, we declare the following function:

function newinstance()
   return createA(1);
end

And we call it from the C++ side:

_A *pA = call_function<_A *>(L, "newinstance");

It builds without problems and then I get the runtime error: "Access
violation - no RTTI data!". Of course, if we modify the code and
AFactory::create instead returns a valid instance of a non abstract A
class which hasn't got any virtual method, everything goes ok.

What am I doing wrong? Any words of advice will be welcome :)

Thanks in advance,

Pablo Palmier


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: "no RTTI data" when invoking a factory method from Lua

Sean Barton
Hi Pablo!

I tried your example and in worked for me.  I did have to enable "Run-Time Type Info" on my compiler first though.  Were you not getting any compiler warnings when you compiled the code?

Anyway, if you're using Visual Studio 2003 then just open your project settings, open the C/C++ tab, and select "Langauge".  Make sure the "Run-Time Type Info" property is set to "Yes(/GR).

I'm positive all other compilers have similar switches to enable run-time type info.

Best,
-seanba


On 4/13/06, Pablo Palmier Campos <[hidden email]> wrote:
Hi to all,

I'm new to Luabind, so excuse me if this is somewhat recurrent. I've
been reading the docs and making my own tests, but I haven't found an
adequate solution for my problem. Currently, I'm using Luabind 0.7
with Lua 5.0.2. The best I can is to provide an example:

Suppose we have the following C++ classes:

class _A {
public:
         virtual void foo() = 0;
};

class _B : public _A {
public:
         void foo() {
                printf("B:foo()");
         }
};

And then we have an "A's" factory:

class AFactory {
public:
                static _A *create(int nId) {
                _A *pRet;

                if (nId == 1)  {
                        pRet = new _B();
                }
                else {
                        pRet = NULL;
                }

                return pRet;
        }
};

We register the former classes in luabind and the function to create A
valid instances:

        class_<_A>("_A"),
        class_<_B, _A>("_B"),
        def("createA", AFactory::create)

In our LUA script, we declare the following function:

function newinstance()
   return createA(1);
end

And we call it from the C++ side:

_A *pA = call_function<_A *>(L, "newinstance");

It builds without problems and then I get the runtime error: "Access
violation - no RTTI data!". Of course, if we modify the code and
AFactory::create instead returns a valid instance of a non abstract A
class which hasn't got any virtual method, everything goes ok.

What am I doing wrong? Any words of advice will be welcome :)

Thanks in advance,

Pablo Palmier


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmdlnk&amp;kid0944&amp;bid$1720&amp;dat1642">http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user