Silence uninitialized variable warning.
[luabind.git] / luabind / make_function.hpp
blob20ad71f301c45f2b518dfcabd47bb1d93bac0828
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_MAKE_FUNCTION_081014_HPP
6 # define LUABIND_MAKE_FUNCTION_081014_HPP
8 # include <luabind/config.hpp>
9 # include <luabind/object.hpp>
10 # include <luabind/detail/call.hpp>
11 # include <luabind/detail/compute_score.hpp>
12 # include <luabind/detail/deduce_signature.hpp>
13 # include <luabind/detail/format_signature.hpp>
15 namespace luabind {
17 namespace detail
20 LUABIND_API void handle_exception_aux(lua_State* L);
22 template <class F, class Signature, class Policies>
23 struct function_object_impl : function_object
25 function_object_impl(F f, Policies const& policies)
26 : function_object(&entry_point)
27 , f(f)
28 , policies(policies)
31 int call(lua_State* L, invoke_context& ctx) const
33 return invoke(L, *this, ctx, f, Signature(), policies);
36 void format_signature(lua_State* L, char const* function) const
38 detail::format_signature(L, function, Signature());
41 static int entry_point(lua_State* L)
43 function_object_impl const* impl =
44 *(function_object_impl const**)lua_touserdata(L, lua_upvalueindex(1));
46 invoke_context ctx;
48 int results = 0;
50 try
52 results = invoke(
53 L, *impl, ctx, impl->f, Signature(), impl->policies);
55 catch (...)
57 handle_exception_aux(L);
58 lua_error(L);
61 if (!ctx)
63 ctx.format_error(L, impl);
64 lua_error(L);
67 return results;
70 F f;
71 Policies policies;
74 LUABIND_API object make_function_aux(
75 lua_State*, int
76 , function_object* impl
79 LUABIND_API void add_overload(object const&, char const*, object const&);
81 } // namespace detail
83 template <class F, class Signature, class Policies>
84 object make_function(lua_State* L, F f, Signature, Policies)
86 return detail::make_function_aux(
88 , detail::compute_arity(Signature(), Policies())
89 , new detail::function_object_impl<F, Signature, Policies>(
90 f, Policies()
95 template <class F>
96 object make_function(lua_State* L, F f)
98 return make_function(L, detail::deduce_signature(f), detail::null_type());
101 } // namespace luabind
103 #endif // LUABIND_MAKE_FUNCTION_081014_HPP