function.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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)
  4. #ifndef LUABIND_FUNCTION2_081014_HPP
  5. # define LUABIND_FUNCTION2_081014_HPP
  6. # include <luabind/make_function.hpp>
  7. # include <luabind/scope.hpp>
  8. # include <luabind/detail/call_function.hpp>
  9. namespace luabind {
  10. namespace detail
  11. {
  12. template <class F, class Policies>
  13. struct function_registration : registration
  14. {
  15. function_registration(char const* name, F f, Policies const& policies)
  16. : name(name)
  17. , f(f)
  18. , policies(policies)
  19. {}
  20. void register_(lua_State* L) const
  21. {
  22. object fn = make_function(L, f, deduce_signature(f), policies);
  23. add_overload(
  24. object(from_stack(L, -1))
  25. , name
  26. , fn
  27. );
  28. }
  29. char const* name;
  30. F f;
  31. Policies policies;
  32. };
  33. LUABIND_API bool is_luabind_function(lua_State* L, int index);
  34. } // namespace detail
  35. template <class F, class Policies>
  36. scope def(char const* name, F f, Policies const& policies)
  37. {
  38. return scope(std::auto_ptr<detail::registration>(
  39. new detail::function_registration<F, Policies>(name, f, policies)));
  40. }
  41. template <class F>
  42. scope def(char const* name, F f)
  43. {
  44. return def(name, f, detail::null_type());
  45. }
  46. } // namespace luabind
  47. #endif // LUABIND_FUNCTION2_081014_HPP