• Advertisement
Sign in to follow this  

luabind::object and object_cast

This topic is 4378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
    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
Sign in to follow this  

  • Advertisement