Strange cast_failed exceptions on Linux

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Strange cast_failed exceptions on Linux

Martin de Lasa-2
I have been using luabind-0.8.1 to wrap a number of C++ class for some
time. These classes are used both in straight lua, as well as in
situations where lua is used for configuration, with values read back
into C++. This setup has worked great on osx and windows (32-bit).

Recently, I have been testing the same code on linux (ubuntu 10.04-64
bit, gcc 4.4.3) and have been unable to access the wrapped classes
from C++. Spefically, any time I try to cast a luabind::object back to
a wrapped class, I get a cast_failed exception.

In an effort to diagnose the problem, I have generated the following
toy example which, to the best of my knowledge, should work fine.  The
full example is attached.

The idea here is to wrap a simple vec3 class. The class is compiled
into a shared lib. This lib is then wrapped using luabind so vec3 is
available in lua. However, attempting to access the code from C++
causes a cast_failed exception.
(see output below).

I have tried testing the code with different versions of gcc,
different version of luabind 0.8.1 and 0.9.0, both static and dynamic
versions of luabind and the exception persists. Though I am proficient
at C++, I have limited experience with template metaprogramming and
have not attempted to step through the code to figure out what is
going on "under the hood".

Any ideas with what could be causing this type of issue?




#include <cassert>
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include "vec3.h"

int main()
  lua_State * L = luaL_newstate();

  int r = luaL_loadfile( L, "init.lua" );
  assert( !r );

  r = lua_pcall( L, 0, 0, 0 );
  assert( !r );

  r = luaL_dostring( L,
                     "--call wrappers from lua\n"
                     "v = vec3(3,4,5);\n"
                     "print( 'From Lua ...' )\n"
                     "print( v );\n\n"
  assert( !r );

  luabind::object obj = luabind::globals(L)["v"];
  if ( obj )
    // This cast always fails on linux
    Vec3 v = luabind::object_cast<Vec3>(obj);
    v._x = 1.;
    v._y = 2.;
    v._z = 3;
    std::cout << "From C++ ... \n" << v << std::endl;
  return 0;

</ code>

laptop:~$ export LUA_INC_PATH=/usr/include/lua5.1/
laptop:~$ export BOOST_INC_PATH=/usr/include
laptop:~$ export LUABIND_INC_PATH=/usr/include
laptop:~$ export LUA_LIB_PATH=/usr/lib
laptop:~$ export BOOST_LIB_PATH=/usr/lib
laptop:~$ export LUABIND_LIB_PATH=/usr/lib
laptop:~$ scons

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
laptop:~/luabind$ lua test.lua
[                1                 2                 3 ]
laptop:~/luabind$ ./call
>From Lua ...
[                3                 4                 5 ]
terminate called after throwing an instance of 'luabind::cast_failed'
  what():  unable to make cast


Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
luabind-user mailing list
[hidden email] (3K) Download Attachment