1 // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <luabind/luabind.hpp>
28 struct A
: counted_type
<A
>
31 struct B
: A
, counted_type
<B
>
34 struct test_implicit
: counted_type
<test_implicit
>
36 char const* f(A
*) { return "f(A*)"; }
37 char const* f(B
*) { return "f(B*)"; }
40 struct char_pointer_convertable
41 : counted_type
<char_pointer_convertable
>
43 operator const char*() const { return "foo!"; }
46 void func(const char_pointer_convertable
& f
)
50 void not_convertable(boost::shared_ptr
<A
>)
55 } // anonymous namespace
57 void test_implicit_cast()
61 COUNTER_GUARD(test_implicit
);
62 COUNTER_GUARD(char_pointer_convertable
);
66 using namespace luabind
;
68 typedef char const*(test_implicit::*f1
)(A
*);
69 typedef char const*(test_implicit::*f2
)(B
*);
74 .def(constructor
<>()),
77 .def(constructor
<>()),
79 class_
<test_implicit
>("test")
81 .def("f", (f1
)&test_implicit::f
)
82 .def("f", (f2
)&test_implicit::f
),
84 class_
<char_pointer_convertable
>("char_ptr")
85 .def(constructor
<>()),
88 def("no_convert", ¬_convertable
)
91 DOSTRING(L
, "a = A()");
92 DOSTRING(L
, "b = B()");
93 DOSTRING(L
, "t = test()");
95 DOSTRING(L
, "assert(t:f(a) == 'f(A*)')");
96 DOSTRING(L
, "assert(t:f(b) == 'f(B*)')");
105 "no match for function call 'no_convert' with the parameters (A)\n"
107 "no_convert(custom)\n");