Test object identity with shared_ptr_converter.
[luabind.git] / luabind / detail / format_signature.hpp
blob5967d9d6d6c147a2601cc2ba6beca7003f8374e8
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 #ifndef LUABIND_FORMAT_SIGNATURE_081014_HPP
6 # define LUABIND_FORMAT_SIGNATURE_081014_HPP
8 # include <luabind/config.hpp>
9 # include <luabind/lua_include.hpp>
10 # include <luabind/typeid.hpp>
12 # include <boost/mpl/begin_end.hpp>
13 # include <boost/mpl/next.hpp>
14 # include <boost/mpl/size.hpp>
16 namespace luabind {
18 class object;
19 class argument;
20 template <class Base>
21 struct table;
23 } // namespace luabind
25 namespace luabind { namespace detail {
27 LUABIND_API std::string get_class_name(lua_State* L, type_id const& i);
29 template <class T>
30 struct type_to_string
32 static void get(lua_State* L)
34 lua_pushstring(L, get_class_name(L, typeid(T)).c_str());
38 template <class T>
39 struct type_to_string<T*>
41 static void get(lua_State* L)
43 type_to_string<T>::get(L);
44 lua_pushstring(L, "*");
45 lua_concat(L, 2);
49 template <class T>
50 struct type_to_string<T&>
52 static void get(lua_State* L)
54 type_to_string<T>::get(L);
55 lua_pushstring(L, "&");
56 lua_concat(L, 2);
60 template <class T>
61 struct type_to_string<T const>
63 static void get(lua_State* L)
65 type_to_string<T>::get(L);
66 lua_pushstring(L, " const");
67 lua_concat(L, 2);
71 # define LUABIND_TYPE_TO_STRING(x) \
72 template <> \
73 struct type_to_string<x> \
74 { \
75 static void get(lua_State* L) \
76 { \
77 lua_pushstring(L, #x); \
78 } \
81 # define LUABIND_INTEGRAL_TYPE_TO_STRING(x) \
82 LUABIND_TYPE_TO_STRING(x) \
83 LUABIND_TYPE_TO_STRING(unsigned x)
85 LUABIND_INTEGRAL_TYPE_TO_STRING(char)
86 LUABIND_INTEGRAL_TYPE_TO_STRING(short)
87 LUABIND_INTEGRAL_TYPE_TO_STRING(int)
88 LUABIND_INTEGRAL_TYPE_TO_STRING(long)
90 LUABIND_TYPE_TO_STRING(void)
91 LUABIND_TYPE_TO_STRING(bool)
92 LUABIND_TYPE_TO_STRING(std::string)
93 LUABIND_TYPE_TO_STRING(lua_State)
95 LUABIND_TYPE_TO_STRING(luabind::object)
96 LUABIND_TYPE_TO_STRING(luabind::argument)
98 # undef LUABIND_INTEGRAL_TYPE_TO_STRING
99 # undef LUABIND_TYPE_TO_STRING
101 template <class Base>
102 struct type_to_string<table<Base> >
104 static void get(lua_State* L)
106 lua_pushstring(L, "table");
110 template <class End>
111 void format_signature_aux(lua_State*, bool, End, End)
114 template <class Iter, class End>
115 void format_signature_aux(lua_State* L, bool first, Iter, End end)
117 if (!first)
118 lua_pushstring(L, ",");
119 type_to_string<typename Iter::type>::get(L);
120 format_signature_aux(L, false, typename mpl::next<Iter>::type(), end);
123 template <class Signature>
124 void format_signature(lua_State* L, char const* function, Signature)
126 typedef typename mpl::begin<Signature>::type first;
128 type_to_string<typename first::type>::get(L);
130 lua_pushstring(L, " ");
131 lua_pushstring(L, function);
133 lua_pushstring(L, "(");
134 format_signature_aux(
136 , true
137 , typename mpl::next<first>::type()
138 , typename mpl::end<Signature>::type()
140 lua_pushstring(L, ")");
142 lua_concat(L, mpl::size<Signature>() * 2 + 2);
145 }} // namespace luabind::detail
147 #endif // LUABIND_FORMAT_SIGNATURE_081014_HPP