g++ 4.5 and luabind downcasting bug

Nigel Atkinson <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <1305798468.4314.11.camel@ephebe>
I think I've found a regression in luabind 0.9 between using g++ 4.4.5
and 4.5.2 (installed with Ubuntu 11.04).

The 4.4.5 version works as I expect.

When using the later version, the down-casting seems to only work for
the last derived class bound.

I've attached a program that shows the problem and the output I get from
compiling it with each.

Nigel

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
g++-4.4.5.txt (text/plain, 102 B)
---------
p.a 	45
p.b 	78
p.x 	nil
p.y 	nil
p.z 	nil
---------
p.a 	nil
p.b 	nil
p.x 	1
p.y 	2
p.z 	3
g++-4.5.2.txt (text/plain, 104 B)
---------
p.a 	nil
p.b 	nil
p.x 	nil
p.y 	nil
p.z 	nil
---------
p.a 	nil
p.b 	nil
p.x 	1
p.y 	2
p.z 	3
main.cpp (text/x-c++src, 1.4 KB)
#include <iostream>
#include <luabind/luabind.hpp>
#include <lua.hpp>

using std::cout;
using std::endl;
using namespace luabind;

struct base
{
    virtual ~base() {}
};

struct drived : public base
{
    int a, b;
};

struct another : public base
{
    short x, y, z;
};

void call( lua_State* L, base* ptr )
{
    object myprint = luabind::globals(L)["myprint"];

    myprint( ptr );
}

int main( int argc, char *argv[] )
{
    lua_State* L = luaL_newstate();

    open(L);

    luaL_openlibs(L);

    module(L)
    [
        class_<base>( "base" ),
        class_<drived, base>( "drived" )
            .def_readwrite( "a", &drived::a )
            .def_readwrite( "b", &drived::b ),
        class_<another, base>( "another" )
            .def_readwrite( "x", &another::x )
            .def_readwrite( "y", &another::y )
            .def_readwrite( "z", &another::z )
    ];

    luaL_dostring( L,
            "function myprint( p )   "
            "  print( '---------' )  "
            "  print( 'p.a ', p.a )  "
            "  print( 'p.b ', p.b )  "
            "  print( 'p.x ', p.x )  "
            "  print( 'p.y ', p.y )  "
            "  print( 'p.z ', p.z )  "
            "end                     " );

    drived d;
    d.a = 45;
    d.b = 78;
    another a;
    a.x = 1;
    a.y = 2;
    a.z = 3;

    call( L, &d );
    call( L, &a );

    lua_close(L);

    return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.