Teach adopt() to hold the adopted pointer in custom pointer type.
[luabind.git] / test / test_user_defined_converter.cpp
blob643ce4f1a61d980f525406b503003e329046c04e
1 // Copyright Daniel Wallin 2008. 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 value)
11 : value(value)
14 int value;
17 namespace luabind {
19 template <>
20 struct default_converter<X>
21 : native_converter_base<X>
23 int compute_score(lua_State* L, int index)
25 return cv.compute_score(L, index);
28 X from(lua_State* L, int index)
30 return X(lua_tonumber(L, index));
33 void to(lua_State* L, X const& x)
35 lua_pushnumber(L, x.value);
38 default_converter<int> cv;
41 } // namespace luabind
43 int take(X x)
45 return x.value;
48 X get(int value)
50 return X(value);
53 void test_main(lua_State* L)
55 using namespace luabind;
57 module(L) [
58 def("take", &take),
59 def("get", &get)
62 DOSTRING(L,
63 "assert(take(1) == 1)\n"
64 "assert(take(2) == 2)\n"
67 DOSTRING(L,
68 "assert(get(1) == 1)\n"
69 "assert(get(2) == 2)\n"