Sign in to follow this  
playmesumch00ns

luabind::object and object_cast

Recommended Posts

Hi, I've successfully bound a large chunk of the Imath library to lua using luabind, but I'm having trouble getting the vectors out of a table. The vector definition is like this:
template<typename T>
class Vec3
{
public:
    T x, y, z;
};

typedef Vec3<float> V3f;

I've written an templated array wrapper and I'm trying to pass a table of Vec3<float> objects to its constructor to initialize it. I've already done this for float and int data types and it works fine. This is the C++ core from TypedArray's constructor binding:
TypedArrayBinding( luabind::object const& obj )
// Initialize the base class with a new TypedArray
:DataBinding( TypedArray<T>::create() )
{
    if ( type( obj ) != LUA_TTABLE )
        throw( std::runtime_error( "TypedArrayBinding constructor expects a table" ) );

    // _ptr is a smart pointer to the actual array object stored in the base class. writeable() returns the std::vector<T> that TypedArray<T> wraps
    std::vector<T>& v = dynamic_pointer_cast<TypedArray<T> >( _ptr )->writeable();
    
    // get a luabind iterator and loop over the table	
    iterator i(obj), end;
    for( ; i != end; ++i )
    {
        // object_cast<float> works fine, but object_cast<V3f> fails
        T t = object_cast<T>(*i);
        v.push_back(  t  );
     }
}

luabind's documentation isn't really any help: it tells me how to detec if object_cast has failed, but doesn't say why that should be, or how I might go about fixing it! Has anyone had any experience of using luabind::object's with data of this type? I'm pretty stuck here. Cheers. p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this