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
{ namespace adl
30 } // namespace luabind
32 namespace luabind
{ namespace detail
{
34 LUABIND_API
std::string
get_class_name(lua_State
* L
, type_id
const& i
);
39 static void get(lua_State
* L
)
41 lua_pushstring(L
, get_class_name(L
, typeid(T
)).c_str());
46 struct type_to_string
<T
*>
48 static void get(lua_State
* L
)
50 type_to_string
<T
>::get(L
);
51 lua_pushstring(L
, "*");
57 struct type_to_string
<T
&>
59 static void get(lua_State
* L
)
61 type_to_string
<T
>::get(L
);
62 lua_pushstring(L
, "&");
68 struct type_to_string
<T
const>
70 static void get(lua_State
* L
)
72 type_to_string
<T
>::get(L
);
73 lua_pushstring(L
, " const");
78 # define LUABIND_TYPE_TO_STRING(x) \
80 struct type_to_string<x> \
82 static void get(lua_State* L) \
84 lua_pushstring(L, #x); \
88 # define LUABIND_INTEGRAL_TYPE_TO_STRING(x) \
89 LUABIND_TYPE_TO_STRING(x) \
90 LUABIND_TYPE_TO_STRING(unsigned x)
92 LUABIND_INTEGRAL_TYPE_TO_STRING(char)
93 LUABIND_INTEGRAL_TYPE_TO_STRING(short)
94 LUABIND_INTEGRAL_TYPE_TO_STRING(int)
95 LUABIND_INTEGRAL_TYPE_TO_STRING(long)
97 LUABIND_TYPE_TO_STRING(void)
98 LUABIND_TYPE_TO_STRING(bool)
99 LUABIND_TYPE_TO_STRING(std::string
)
100 LUABIND_TYPE_TO_STRING(lua_State
)
102 LUABIND_TYPE_TO_STRING(luabind::object
)
103 LUABIND_TYPE_TO_STRING(luabind::argument
)
105 # undef LUABIND_INTEGRAL_TYPE_TO_STRING
106 # undef LUABIND_TYPE_TO_STRING
108 template <class Base
>
109 struct type_to_string
<table
<Base
> >
111 static void get(lua_State
* L
)
113 lua_pushstring(L
, "table");
118 void format_signature_aux(lua_State
*, bool, End
, End
)
121 template <class Iter
, class End
>
122 void format_signature_aux(lua_State
* L
, bool first
, Iter
, End end
)
125 lua_pushstring(L
, ",");
126 type_to_string
<typename
Iter::type
>::get(L
);
127 format_signature_aux(L
, false, typename
mpl::next
<Iter
>::type(), end
);
130 template <class Signature
>
131 void format_signature(lua_State
* L
, char const* function
, Signature
)
133 typedef typename
mpl::begin
<Signature
>::type first
;
135 type_to_string
<typename
first::type
>::get(L
);
137 lua_pushstring(L
, " ");
138 lua_pushstring(L
, function
);
140 lua_pushstring(L
, "(");
141 format_signature_aux(
144 , typename
mpl::next
<first
>::type()
145 , typename
mpl::end
<Signature
>::type()
147 lua_pushstring(L
, ")");
149 lua_concat(L
, static_cast<int>(mpl::size
<Signature
>()) * 2 + 2);
152 }} // namespace luabind::detail
154 #endif // LUABIND_FORMAT_SIGNATURE_081014_HPP