Teach adopt() to hold the adopted pointer in custom pointer type.
[luabind.git] / test / test_collapse_converter.cpp
blob6a5b3a14f335bed8ca16472ddab7f549b7adf166
1 // Copyright Daniel Wallin 2009. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #include "test.hpp"
6 #include <luabind/luabind.hpp>
8 struct X
10 X(int x, int y)
11 : x(x)
12 , y(y)
15 int x;
16 int y;
19 namespace luabind {
21 int combine_score(int s1, int s2)
23 if (s1 < 0 || s2 < 0) return -1;
24 return s1 + s2;
27 template <>
28 struct default_converter<X>
29 : native_converter_base<X>
31 int const consumed_args(...)
33 return 2;
36 int compute_score(lua_State* L, int index)
38 return combine_score(
39 c1.compute_score(L, index), c2.compute_score(L, index + 1));
42 X from(lua_State* L, int index)
44 return X(lua_tonumber(L, index), lua_tonumber(L, index + 1));
47 default_converter<int> c1;
48 default_converter<int> c2;
51 } // namespace luabind
53 int take(X x)
55 return x.x + x.y;
58 void test_main(lua_State* L)
60 using namespace luabind;
62 module(L) [
63 def("take", &take)
66 DOSTRING(L,
67 "assert(take(1,1) == 2)\n"
68 "assert(take(2,3) == 5)\n"