[luabind] overloaded comparison operator not getting called
Brought to you by:
arvidn,
daniel_wallin
From: piers a. <pie...@ho...> - 2013-01-10 14:00:28
|
Hi, I can't see why the comparison operator for the MyInt type below isn't being called - can anyone help? I'm sure I've overlooked something obvious. In lua, a comparison on a MyInt and an int type always returns false and the non member comparison operator is never called. The above comparison works fine in C++. Code snippets and details below. class MyInt { public: MyInt(int value):value_(value){} int value()const{return value_;} private: const int value_; }; bool operator==(const MyInt& myInt,int i) { std::cout<<"here"<<std::endl; return myInt.value()==i; } luabind::module(L) [ luabind::class_<MyInt>("MyInt") .def(luabind::constructor<int>()) .def(luabind::self==int()) .def(luabind::const_self==int()) ]; Lua > myInt=MyInt(2013) year=2013 b=(myInt==year) print(b) false C++ MyInt myInt(2013); std::cout<<"MyInt test="<<(myInt==2013)<<std::endl; std::cout<<"MyInt test="<<(myInt==2012)<<std::endl; here MyInt test=1 here MyInt test=0 BOOST_LIB_VERSION=1_48 LUA_VERSION_NUM=501 LUABIND_VERSION=900 G++ VERSION=4.4.6 20110731 (Red Hat 4.4.6-3) Many thanks Piers |