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