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.
23 #ifndef LUABIND_NO_ERROR_CHECKING
25 #if !BOOST_PP_IS_ITERATING
27 #ifndef LUABIND_GET_SIGNATURE_HPP_INCLUDED
28 #define LUABIND_GET_SIGNATURE_HPP_INCLUDED
30 #include <boost/config.hpp>
31 #include <boost/preprocessor/repeat.hpp>
32 #include <boost/preprocessor/iteration/iterate.hpp>
33 #include <boost/preprocessor/repetition/enum.hpp>
34 #include <boost/preprocessor/repetition/enum_params.hpp>
35 #include <boost/preprocessor/punctuation/comma_if.hpp>
36 #include <boost/preprocessor/cat.hpp>
38 #include <luabind/config.hpp>
39 #include <luabind/detail/signature_match.hpp>
42 namespace luabind
{ namespace detail
48 static std::string
name(lua_State
* L
)
51 class_registry
* r
= class_registry::get_registry(L
);
53 class_rep
* crep
= r
->find_class(LUABIND_TYPEID(T
));
68 std::string
name_of_type(by_value
<T
>, lua_State
* L
) { return get_class_name
<T
>::name(L
); };
70 std::string
name_of_type(by_reference
<T
>, lua_State
* L
) { return name_of_type(LUABIND_DECORATE_TYPE(T
), L
) + "&"; };
72 std::string
name_of_type(by_pointer
<T
>, lua_State
* L
) { return name_of_type(LUABIND_DECORATE_TYPE(T
), L
) + "*"; };
74 std::string
name_of_type(by_const_reference
<T
>, lua_State
* L
) { return "const " + name_of_type(LUABIND_DECORATE_TYPE(T
), L
) + "&"; };
76 std::string
name_of_type(by_const_pointer
<T
>, lua_State
* L
) { return "const " + name_of_type(LUABIND_DECORATE_TYPE(T
), L
) + "*"; };
78 inline std::string
name_of_type(by_value
<luabind::object
>, lua_State
*) { return "object"; };
79 inline std::string
name_of_type(by_const_reference
<luabind::object
>, lua_State
*) { return "object"; };
80 inline std::string
name_of_type(by_value
<bool>, lua_State
*) { return "boolean"; }
81 inline std::string
name_of_type(by_value
<char>, lua_State
*) { return "number"; }
82 inline std::string
name_of_type(by_value
<short>, lua_State
*) { return "number"; }
83 inline std::string
name_of_type(by_value
<int>, lua_State
*) { return "number"; }
84 inline std::string
name_of_type(by_value
<long>, lua_State
*) { return "number"; }
85 inline std::string
name_of_type(by_value
<unsigned char>, lua_State
*) { return "number"; }
86 inline std::string
name_of_type(by_value
<unsigned short>, lua_State
*) { return "number"; }
87 inline std::string
name_of_type(by_value
<unsigned int>, lua_State
*) { return "number"; }
88 inline std::string
name_of_type(by_value
<unsigned long>, lua_State
*) { return "number"; }
90 inline std::string
name_of_type(by_value
<const bool>, lua_State
*) { return "boolean"; }
91 inline std::string
name_of_type(by_value
<const char>, lua_State
*) { return "number"; }
92 inline std::string
name_of_type(by_value
<const short>, lua_State
*) { return "number"; }
93 inline std::string
name_of_type(by_value
<const int>, lua_State
*) { return "number"; }
94 inline std::string
name_of_type(by_value
<const long>, lua_State
*) { return "number"; }
95 inline std::string
name_of_type(by_value
<const unsigned char>, lua_State
*) { return "number"; }
96 inline std::string
name_of_type(by_value
<const unsigned short>, lua_State
*) { return "number"; }
97 inline std::string
name_of_type(by_value
<const unsigned int>, lua_State
*) { return "number"; }
98 inline std::string
name_of_type(by_value
<const unsigned long>, lua_State
*) { return "number"; }
100 inline std::string
name_of_type(by_value
<std::string
>, lua_State
*) { return "string"; }
101 inline std::string
name_of_type(by_const_pointer
<char>, lua_State
*) { return "string"; }
104 struct type_name_unless_void
106 inline static void apply(std::string
& s
, lua_State
* L
, bool first
)
108 if (!first
) s
+= ", ";
109 s
+= name_of_type(LUABIND_DECORATE_TYPE(T
), L
);
114 struct type_name_unless_void
<null_type
>
116 inline static void apply(std::string
&, lua_State
*, bool) {}
119 #define LUABIND_ADD_LUA_TYPE_NAME(z, n, _) type_name_unless_void<BOOST_PP_CAT(A, BOOST_PP_INC(n))>::apply(s, L, false);
121 #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/get_signature.hpp>, 1))
122 #include BOOST_PP_ITERATE()
125 struct get_member_signature
127 static inline void apply(lua_State
* L
, std::string
& s
)
129 get_member_signature_impl(static_cast<F
>(0), L
, s
);
134 struct get_free_function_signature
136 static inline void apply(lua_State
* L
, std::string
& s
)
138 get_free_function_signature_impl(static_cast<F
>(0), L
, s
);
146 static inline void apply(lua_State
* L
, std::string
& s
)
148 get_signature_impl(static_cast<const Sig
*>(0), L
, s
);
152 template<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY
, class A
)>
153 inline void get_signature_impl(const constructor
<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY
, A
)>*, lua_State
* L
, std::string
& s
)
156 type_name_unless_void
<A0
>::apply(s
, L
, true);
157 BOOST_PP_REPEAT(BOOST_PP_DEC(LUABIND_MAX_ARITY
), LUABIND_ADD_LUA_TYPE_NAME
, _
)
161 #undef LUABIND_ADD_LUA_TYPE_NAME
165 #endif // LUABIND_GET_SIGNATURE_HPP_INCLUDED
167 #elif BOOST_PP_ITERATION_FLAGS() == 1
170 template<class T
, class C
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
171 inline void get_member_signature_impl(T(C::*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)), lua_State
* L
, std::string
& s
)
174 #if BOOST_PP_ITERATION() > 0
175 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
176 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
181 template<class T
, class C
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
182 inline void get_member_signature_impl(T(C::*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)) const, lua_State
* L
, std::string
& s
)
185 #if BOOST_PP_ITERATION() > 0
186 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
187 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
192 template<class T
, class C
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
193 inline void get_member_signature_impl(T(*)(C
* obj
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)), lua_State
* L
, std::string
& s
)
196 #if BOOST_PP_ITERATION() > 0
197 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
198 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
203 template<class T
, class C
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
204 inline void get_member_signature_impl(T(*f
)(const C
* obj
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)), lua_State
* L
, std::string
& s
)
208 #if BOOST_PP_ITERATION() > 0
209 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
210 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
216 template<class T
, class C
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
217 inline void get_member_signature_impl(T(*f
)(C
& obj
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)), lua_State
* L
, std::string
& s
)
220 #if BOOST_PP_ITERATION() > 0
221 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
222 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
227 template<class T
, class C
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
228 inline void get_member_signature_impl(T(*f
)(const C
& obj
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)), lua_State
* L
, std::string
& s
)
231 #if BOOST_PP_ITERATION() > 0
232 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
233 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
239 template<class T
BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A
)>
240 inline void get_free_function_signature_impl(T(*f
)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A
)), lua_State
* L
, std::string
& s
)
243 #if BOOST_PP_ITERATION() > 0
244 s
+= name_of_type(LUABIND_DECORATE_TYPE(A0
), L
);
245 BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME
, _
)
252 #endif // LUABIND_NO_ERROR_CHECKING