fixed ambiguity caused by adl
[luabind.git] / test / test_implicit_cast.cpp
blobb3085dcd4567e3f8a77f25055f070d68e631c211
1 #include "test.h"
3 namespace
5 LUABIND_ANONYMOUS_FIX int feedback = 0;
7 struct A { virtual ~A() {} };
8 struct B: public A {};
10 struct test_implicit
12 void f(A*) { feedback = 1; }
13 void f(B*) { feedback = 2; }
16 } // anonymous namespace
18 #include <luabind/pointer_holder.hpp>
20 void test_instance_holder(lua_State* L)
22 using namespace luabind;
24 // pointer_holder<A, A*> holder(new B);
26 // void* p = holder.holds(LUABIND_TYPEID(B));
29 bool test_implicit_cast()
31 using namespace luabind;
33 lua_State* L = lua_open();
34 lua_closer c(L);
35 int top = lua_gettop(L);
37 open(L);
39 typedef void (test_implicit::*f1)(A*);
40 typedef void (test_implicit::*f2)(B*);
42 module(L)
44 class_<A>("A")
45 .def(constructor<>()),
47 class_<B, A>("B")
48 .def(constructor<>()),
50 class_<test_implicit>("test")
51 .def(constructor<>())
52 .def("f", (f1) &test_implicit::f)
53 .def("f", (f2) &test_implicit::f)
56 // test_instance_holder(L);
58 if (dostring(L, "a = A()")) return false;
59 if (dostring(L, "b = B()")) return false;
60 if (dostring(L, "t = test()")) return false;
62 if (dostring(L, "t:f(a)")) return false;
63 if (feedback != 1) return false;
65 if (dostring(L, "t:f(b)")) return false;
66 if (feedback != 2) return false;
68 if (top != lua_gettop(L)) return false;
70 return true;