[luabind-cvs] luabind/luabind/luabind object.hpp,1.36,1.36.2.1
Brought to you by:
arvidn,
daniel_wallin
From: Arvid N. <ar...@us...> - 2005-12-30 16:57:45
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23283/luabind/luabind Modified Files: Tag: luabind_rc_0_7 object.hpp Log Message: now allows comparison of uninitialized objects Index: object.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v retrieving revision 1.36 retrieving revision 1.36.2.1 diff -u -d -r1.36 -r1.36.2.1 --- object.hpp 4 Dec 2005 13:56:15 -0000 1.36 +++ object.hpp 30 Dec 2005 16:57:37 -0000 1.36.2.1 @@ -91,24 +91,46 @@ namespace adl { + template<class T, class U> + int binary_interpreter(lua_State*& L, T const& lhs, U const& rhs + , boost::mpl::true_, boost::mpl::true_) + { + L = value_wrapper_traits<T>::interpreter(lhs); + lua_State* L2 = value_wrapper_traits<U>::interpreter(rhs); - template<class T, class U, class V> - lua_State* binary_interpreter(T const& x, U const&, boost::mpl::true_, V) + // you are comparing objects with different interpreters + // that's not allowed. + assert(L == L2 || L == 0 || L2 == 0); + + // if the two objects we compare have different interpreters + // then they + + if (L != L2) return -1; + if (L == 0) return 1; + return 0; + } + + template<class T, class U> + int binary_interpreter(lua_State*& L, T const& x, U const& + , boost::mpl::true_, boost::mpl::false_) { - return value_wrapper_traits<T>::interpreter(x); + L = value_wrapper_traits<T>::interpreter(x); + return 0; } template<class T, class U> - lua_State* binary_interpreter(T const&, U const& x, boost::mpl::false_, boost::mpl::true_) + int binary_interpreter(lua_State*& L, T const&, U const& x, boost::mpl::false_, boost::mpl::true_) { - return value_wrapper_traits<U>::interpreter(x); + L = value_wrapper_traits<U>::interpreter(x); + return 0; } template<class T, class U> - lua_State* binary_interpreter(T const& x, U const& y) + int binary_interpreter(lua_State*& L, T const& x, U const& y) { return binary_interpreter( - x + L + , x , y , is_value_wrapper<T>() , is_value_wrapper<U>() @@ -119,7 +141,14 @@ template<class LHS, class RHS> \ bool operator op(LHS const& lhs, RHS const& rhs) \ { \ - lua_State* L = binary_interpreter(lhs, rhs); \ + lua_State* L = 0; \ + switch (binary_interpreter(L, lhs, rhs)) \ + { \ + case 1: \ + return true; \ + case -1: \ + return false; \ + } \ \ assert(L); \ \ @@ -130,9 +159,9 @@ \ return fn(L, -1, -2) != 0; \ } - - LUABIND_BINARY_OP_DEF(==, lua_equal) - LUABIND_BINARY_OP_DEF(<, lua_lessthan) + +LUABIND_BINARY_OP_DEF(==, lua_equal) +LUABIND_BINARY_OP_DEF(<, lua_lessthan) #undef LUABIND_BINARY_OP_DEF |