doc tweaks
[luabind.git] / luabind / detail / convert_to_lua.hpp
blob711f8d5b4e8d44495299ab68c478148bf9d8d06d
1 // Copyright (c) 2003 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 #ifndef LUABIND_CONVERT_TO_LUA_HPP_INCLUDED
25 #define LUABIND_CONVERT_TO_LUA_HPP_INCLUDED
27 #include <luabind/config.hpp>
28 #include <luabind/detail/policy.hpp>
29 #include <boost/ref.hpp>
31 namespace luabind { namespace detail
33 template<bool IsReferenceWrapper = false>
34 struct unwrap_ref
36 template<class T>
37 static const T& get(const T& r) { return r; }
39 template<class T>
40 struct apply
42 typedef T type;
46 template<>
47 struct unwrap_ref<true>
49 template<class T>
50 static T& get(const boost::reference_wrapper<T>& r) { return r.get(); }
52 template<class T>
53 struct apply
55 typedef typename T::type& type;
59 template<class T>
60 void convert_to_lua(lua_State* L, const T& v)
62 typedef typename unwrap_ref<boost::is_reference_wrapper<T>::value>::template apply<T>::type value_type;
63 typename default_policy::template generate_converter<value_type, cpp_to_lua>::type converter;
65 converter.apply(L, unwrap_ref<boost::is_reference_wrapper<T>::value>::get(v));
68 template<int Index, class T, class Policies>
69 void convert_to_lua_p(lua_State* L, const T& v, const Policies&)
71 typedef typename unwrap_ref<boost::is_reference_wrapper<T>::value>::template apply<T>::type value_type;
72 typedef typename find_conversion_policy<Index, Policies>::type converter_policy;
73 typename converter_policy::template generate_converter<value_type, cpp_to_lua>::type converter;
75 converter.apply(L, unwrap_ref<boost::is_reference_wrapper<T>::value>::get(v));
79 #endif