overloaded comparison operator not getting called

piers august <[email protected]> Thu, 10 Jan 2013 14:00:21 +0000
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
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

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user