stack_proxy.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_STACK_PROXY_HPP
  19. #define SOL_STACK_PROXY_HPP
  20. #include <sol/stack_proxy_base.hpp>
  21. namespace sol {
  22. struct stack_proxy : public stack_proxy_base {
  23. public:
  24. stack_proxy() : stack_proxy_base() {
  25. }
  26. stack_proxy(lua_State* L, int index) : stack_proxy_base(L, index) {
  27. }
  28. template <typename... Ret, typename... Args>
  29. decltype(auto) call(Args&&... args);
  30. template <typename... Args>
  31. decltype(auto) operator()(Args&&... args) {
  32. return call<>(std::forward<Args>(args)...);
  33. }
  34. };
  35. namespace stack {
  36. template <>
  37. struct unqualified_getter<stack_proxy> {
  38. static stack_proxy get(lua_State* L, int index, record& tracking) {
  39. tracking.use(0);
  40. return stack_proxy(L, index);
  41. }
  42. };
  43. template <>
  44. struct unqualified_pusher<stack_proxy> {
  45. static int push(lua_State*, const stack_proxy& ref) {
  46. return ref.push();
  47. }
  48. };
  49. } // namespace stack
  50. } // namespace sol
  51. #endif // SOL_STACK_PROXY_HPP