Remove dead code.
[luabind.git] / luabind / make_function.hpp
blob8435c19d677335e9f75b9b3aabe3e1e1c4f39a5d
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/deduce_signature.hpp>
12 # include <luabind/detail/format_signature.hpp>
14 namespace luabind {
16 namespace detail
18 # ifndef LUABIND_NO_EXCEPTIONS
19 LUABIND_API void handle_exception_aux(lua_State* L);
20 # endif
22 // MSVC complains about member being sensitive to alignment (C4121)
23 // when F is a pointer to member of a class with virtual bases.
24 # ifdef BOOST_MSVC
25 # pragma pack(push)
26 # pragma pack(16)
27 # endif
29 template <class F, class Signature, class Policies>
30 struct function_object_impl : function_object
32 function_object_impl(F f, Policies const& policies)
33 : function_object(&entry_point)
34 , f(f)
35 , policies(policies)
38 int call(lua_State* L, invoke_context& ctx) const
40 return invoke(L, *this, ctx, f, Signature(), policies);
43 void format_signature(lua_State* L, char const* function) const
45 detail::format_signature(L, function, Signature());
48 static int entry_point(lua_State* L)
50 function_object_impl const* impl =
51 *(function_object_impl const**)lua_touserdata(L, lua_upvalueindex(1));
53 invoke_context ctx;
55 int results = 0;
57 # ifndef LUABIND_NO_EXCEPTIONS
58 try
60 results = invoke(
61 L, *impl, ctx, impl->f, Signature(), impl->policies);
63 catch (...)
65 handle_exception_aux(L);
66 lua_error(L);
68 # else
69 results = invoke(L, *impl, ctx, impl->f, Signature(), impl->policies);
70 # endif
72 if (!ctx)
74 ctx.format_error(L, impl);
75 lua_error(L);
78 return results;
81 F f;
82 Policies policies;
85 # ifdef BOOST_MSVC
86 # pragma pack(pop)
87 # endif
89 LUABIND_API object make_function_aux(
90 lua_State* L, function_object* impl
93 LUABIND_API void add_overload(object const&, char const*, object const&);
95 } // namespace detail
97 template <class F, class Signature, class Policies>
98 object make_function(lua_State* L, F f, Signature, Policies)
100 return detail::make_function_aux(
102 , new detail::function_object_impl<F, Signature, Policies>(
103 f, Policies()
108 template <class F>
109 object make_function(lua_State* L, F f)
111 return make_function(L, detail::deduce_signature(f), detail::null_type());
114 } // namespace luabind
116 #endif // LUABIND_MAKE_FUNCTION_081014_HPP