fixed some problems with the test suite
[luabind.git] / test / test_implicit_cast.cpp
blobf9963c7f0dd5dac4cf2403bf9d9798b1ba6e9035
1 #include "test.hpp"
2 #include <luabind/luabind.hpp>
4 namespace {
6 struct A : counted_type<A>
7 { virtual ~A() {} };
9 struct B : A, counted_type<B>
10 {};
12 struct test_implicit : counted_type<test_implicit>
14 char const* f(A*) { return "f(A*)"; }
15 char const* f(B*) { return "f(B*)"; }
18 struct char_pointer_convertible
19 : counted_type<char_pointer_convertible>
21 operator const char*() const { return "foo!"; }
24 void func(const char_pointer_convertible& f)
28 } // anonymous namespace
30 void test_implicit_cast()
32 COUNTER_GUARD(A);
33 COUNTER_GUARD(B);
34 COUNTER_GUARD(test_implicit);
35 COUNTER_GUARD(char_pointer_convertible);
37 lua_state L;
39 using namespace luabind;
41 typedef char const*(test_implicit::*f1)(A*);
42 typedef char const*(test_implicit::*f2)(B*);
44 module(L)
46 class_<A>("A")
47 .def(constructor<>()),
49 class_<B, A>("B")
50 .def(constructor<>()),
52 class_<test_implicit>("test")
53 .def(constructor<>())
54 .def("f", (f1)&test_implicit::f)
55 .def("f", (f2)&test_implicit::f),
57 class_<char_pointer_convertible>("char_ptr")
58 .def(constructor<>()),
60 def("func", &func)
63 DOSTRING(L, "a = A()");
64 DOSTRING(L, "b = B()");
65 DOSTRING(L, "t = test()");
67 DOSTRING(L, "assert(t:f(a) == 'f(A*)')");
68 DOSTRING(L, "assert(t:f(b) == 'f(B*)')");
70 DOSTRING(L,
71 "a = char_ptr()\n"
72 "func(a)");