function_result.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // sol2
  2. // The MIT License (MIT)
  3. // Copyright (c) 2013-2022 Rapptz, ThePhD and contributors
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. // this software and associated documentation files (the "Software"), to deal in
  6. // the Software without restriction, including without limitation the rights to
  7. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. // the Software, and to permit persons to whom the Software is furnished to do so,
  9. // subject to the following conditions:
  10. // The above copyright notice and this permission notice shall be included in all
  11. // copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #ifndef SOL_FUNCTION_RESULT_HPP
  19. #define SOL_FUNCTION_RESULT_HPP
  20. #include <sol/protected_function_result.hpp>
  21. #include <sol/unsafe_function_result.hpp>
  22. #include <cstdint>
  23. namespace sol {
  24. namespace detail {
  25. template <>
  26. struct is_speshul<unsafe_function_result> : std::true_type { };
  27. template <>
  28. struct is_speshul<protected_function_result> : std::true_type { };
  29. template <std::size_t I, typename... Args, typename T>
  30. stack_proxy get(types<Args...>, meta::index_value<0>, meta::index_value<I>, const T& fr) {
  31. return stack_proxy(fr.lua_state(), fr.stack_index() + static_cast<int>(I));
  32. }
  33. template <std::size_t I, std::size_t N, typename Arg, typename... Args, typename T, meta::enable<meta::boolean<(N > 0)>> = meta::enabler>
  34. stack_proxy get(types<Arg, Args...>, meta::index_value<N>, meta::index_value<I>, const T& fr) {
  35. return get(types<Args...>(), meta::index_value<N - 1>(), meta::index_value<I + lua_size<Arg>::value>(), fr);
  36. }
  37. } // namespace detail
  38. template <>
  39. struct tie_size<unsafe_function_result> : std::integral_constant<std::size_t, SIZE_MAX> { };
  40. template <>
  41. struct tie_size<protected_function_result> : std::integral_constant<std::size_t, SIZE_MAX> { };
  42. template <std::size_t I>
  43. stack_proxy get(const unsafe_function_result& fr) {
  44. return stack_proxy(fr.lua_state(), fr.stack_index() + static_cast<int>(I));
  45. }
  46. template <std::size_t I, typename... Args>
  47. stack_proxy get(types<Args...> t, const unsafe_function_result& fr) {
  48. return detail::get(t, meta::index_value<I>(), meta::index_value<0>(), fr);
  49. }
  50. template <std::size_t I>
  51. stack_proxy get(const protected_function_result& fr) {
  52. return stack_proxy(fr.lua_state(), fr.stack_index() + static_cast<int>(I));
  53. }
  54. template <std::size_t I, typename... Args>
  55. stack_proxy get(types<Args...> t, const protected_function_result& fr) {
  56. return detail::get(t, meta::index_value<I>(), meta::index_value<0>(), fr);
  57. }
  58. } // namespace sol
  59. #endif // SOL_FUNCTION_RESULT_HPP