added finalizers
[luabind.git] / luabind / out_value.hpp
blob03fb2222f837c859e3de76ca02fe978cda0e8b3d
2 template<int N>
3 struct char_array
5 char storage[N];
6 };
8 template<class T>
9 struct indirect_sizeof
11 template<class U>
12 char_array<sizeof(U)> test(reference_to<U>);
14 template<class U>
15 char_array<sizeof(U)> test(const_reference_to<U>);
17 template<class U>
18 char_array<sizeof(U)> test(pointer_to<U>);
20 template<class U>
21 char_array<sizeof(U)> test(const_pointer_to<U>);
23 template<class U>
24 char_array<sizeof(U)> test(value_to<U>);
26 BOOST_STATIC_CONSTANT(int, value = sizeof(test(LUABIND_DECORATE_TYPE(T))));
29 template<int N>
30 struct out_value_converter
32 template<class T>
33 static T& apply(lua_State* L, reference_to<T>, int index)
35 new (m_storage) T(primitive_param_converter::apply(L, value_to<T>(), index));
36 return *reinterpret_cast<T*>(m_storage);
39 template<class T>
40 static void postcall(lua_State* L, reference_to<T>, int)
42 primitive_result_converter::apply(L, *reinterpret_cast<T*>(m_storage));
45 template<class T>
46 static int match(lua_State* L, reference_to<T>, int index)
48 return primitive_param_converter::match(L, value_to<T>(), index);
51 char m_storage[N];
54 template<class T>
55 struct out_value_policy
57 BOOST_STATIC_CONSTANT(int, size = indirect_sizeof<T>::value);
58 typedef out_value_converter<size> type;
61 template<int N>
62 struct out_value_policy_gen
64 template<class T, class Direction>
65 struct generate_policy
67 typedef typename mpl::apply_if<is_same<Direction, lua_to_cpp>
68 , out_value_policy<T>
69 , error
70 >::type type;