Question

I'm trying to register two class that inherit from the same class using LuaBridge, but failed.

How can I register three classes below?

    class A
    {
        public:
            int x;
    };
    class B1 : public A
    {
        public:
            int y;
    };
    class B2 : public A
    {
        public:
            int z;
    };

I can just register A and B1 like this

getGlobalNamespace(L)
    .beginClass<A>("A")
        .addConstructor()
    .endClass()
    .deriveClass<B1, A>("B1")
        .addConstructor<void(*)(void)>()
    .endClass()

And

getGlobalNamespace(L)
    .beginClass<A>("A")
        .addConstructor()
    .endClass()
    .deriveClass<B1, A>("B1")
        .addConstructor()
    .endClass()
    .deriveClass<B2, A>("B2")
        .addConstructor<void(*)(void)>()
    .endClass()

is turn out to register B2 as if it inherits from B1.

Any help is greatly appreciated.

Était-ce utile?

La solution

getGlobalNamespace(L)
    .beginClass<A>("A")
        .addConstructor()
    .endClass()
    .deriveClass<B1, A>("B1")
        .addConstructor()
    .endClass()
    .deriveClass<B2, A>("B2")
        .addConstructor<void(*)(void)>()
    .endClass()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top