*** empty log message ***
[luabind.git] / test / test_implicit_cast.cpp
blob42e474a863ee2a071ab3cafd62de4ecf6201d9ad
1 #include "test.h"
3 namespace
5 LUABIND_ANONYMOUS_FIX 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 typedef void (test_implicit::*f1)(A*);
29 typedef void (test_implicit::*f2)(B*);
31 module(L)
33 class_<A>("A")
34 .def(constructor<>()),
36 class_<B, A>("B")
37 .def(constructor<>()),
39 class_<test_implicit>("test")
40 .def(constructor<>())
41 .def("f", (f1) &test_implicit::f)
42 .def("f", (f2) &test_implicit::f)
45 if (dostring(L, "a = A()")) return false;
46 if (dostring(L, "b = B()")) return false;
47 if (dostring(L, "t = test()")) return false;
49 if (dostring(L, "t:f(a)")) return false;
50 if (feedback != 1) return false;
52 if (dostring(L, "t:f(b)")) return false;
53 if (feedback != 2) return false;
55 if (top != lua_gettop(L)) return false;
57 return true;