Overridden properties are overwritten by base classes

View: New views
1 Messages — Rating Filter:   Alert me  

Overridden properties are overwritten by base classes

by Chris Byrne-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We just encountered a problem where the base classes property getter/setter is called instead of the overridden bindings:

// bind our classes
struct Base {
        std::string GetBase( ) const { return "Base::Get"; }
        void SetBase( const std::string& ) { throw "Base::Set"; }
};
struct Derived : public Base {
        std::string GetDerived( ) const { return "Derived::Get"; }
        void SetDerived( const std::string& ) { throw "Derived::Set"; }
};

// expose them with luabind
{
        using namespace luabind;
       
        module( lua_state ) [
                class_< Base >( "_Base" )
                        .property( "value", &Base::GetBase, &Base::SetBase )
                ,
                class_< Derived, Base >( "_Derived" )
                        .property( "value", &Derived::GetDerived, &Derived::SetDerived )
        ];
}

// bind them as global lua objects
luabind::object obj_globals = luabind::globals( lua_state );

obj_globals[ "base" ] = Base( );
obj_globals[ "derived" ] = Derived( );



-- in lua:

> print( base.value )
Base::Get
> print( derived.value )
Base::Get
-- should be Derived::Get

> base.value = ""
Base::Set
> derived.value = ""
Base::Set
-- should be Derived::Set

========================================================

Problem is due to class_rep::add_base_class being called _after_ the derived properties have been added to m_getters and m_setters. Which is fine except that add_base_class doesn't check if the properties have already been set...

Small diff attached showing how to fix this problem.


Thanks,
 Chris Byrne
 Software Engineer
 Element Labs, Inc.



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

changeset_r3418.diff (1K) Download Attachment