*** empty log message ***
[luabind.git] / test / test_implicit_cast.cpp
blob45a74e5236b6e2e9831fccb297d962b660a329c2
1 #include "test.h"
3 namespace
5 int feedback = 0;
7 struct 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 bool test_implicit_cast()
20 using namespace luabind;
22 lua_State* L = lua_open();
23 lua_closer c(L);
24 int top = lua_gettop(L);
26 open(L);
28 class_<A>(L, "A")
29 .def(constructor<>());
31 class_<B, A>(L, "B")
32 .def(constructor<>());
34 typedef void (test_implicit::*f1)(A*);
35 typedef void (test_implicit::*f2)(B*);
37 class_<test_implicit>(L, "test")
38 .def(constructor<>())
39 .def("f", (f1) &test_implicit::f)
40 .def("f", (f2) &test_implicit::f);
42 if (dostring(L, "a = A()")) return false;
43 if (dostring(L, "b = B()")) return false;
44 if (dostring(L, "t = test()")) return false;
46 if (dostring(L, "t:f(a)")) return false;
47 if (feedback != 1) return false;
49 if (dostring(L, "t:f(b)")) return false;
50 if (feedback != 2) return false;
52 if (top != lua_gettop(L)) return false;
54 return true;