OpenMiner  0.0.1a
Voxel game engine
sol.hpp
Go to the documentation of this file.
1 // The MIT License (MIT)
2 
3 // Copyright (c) 2013-2018 Rapptz, ThePhD and contributors
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal in
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 // the Software, and to permit persons to whom the Software is furnished to do so,
10 // subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 // This file was generated with a script.
23 // Generated 2018-11-28 08:50:22.534324 UTC
24 // This header was generated with sol v2.20.6 (revision 9b782ff)
25 // https://github.com/ThePhD/sol2
26 
27 #ifndef SOL_SINGLE_INCLUDE_HPP
28 #define SOL_SINGLE_INCLUDE_HPP
29 
30 // beginning of sol.hpp
31 
32 #ifndef SOL_HPP
33 #define SOL_HPP
34 
35 #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER)
36 #define SOL_INSIDE_UNREAL 1
37 #endif // Unreal Engine 4 bullshit
38 
39 #if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL
40 #ifdef check
41 #define SOL_INSIDE_UNREAL_REMOVED_CHECK 1
42 #undef check
43 #endif
44 #endif // Unreal Engine 4 Bullshit
45 
46 #if defined(__GNUC__)
47 #pragma GCC diagnostic push
48 #pragma GCC diagnostic ignored "-Wshadow"
49 #pragma GCC diagnostic ignored "-Wconversion"
50 #if __GNUC__ > 6
51 #pragma GCC diagnostic ignored "-Wnoexcept-type"
52 #endif
53 #elif defined(__clang__)
54 #elif defined _MSC_VER
55 #pragma warning( push )
56 #pragma warning( disable : 4324 ) // structure was padded due to alignment specifier
57 #pragma warning( disable : 4503 ) // decorated name horse shit
58 #pragma warning( disable : 4702 ) // unreachable code
59 #pragma warning( disable: 4127 ) // 'conditional expression is constant' yeah that's the point your old compilers don't have `if constexpr` you jerk
60 #pragma warning( disable: 4505 ) // some other nonsense warning
61 #endif // clang++ vs. g++ vs. VC++
62 
63 // beginning of sol/forward.hpp
64 
65 // beginning of sol/feature_test.hpp
66 
67 #if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L))))
68 #ifndef SOL_CXX17_FEATURES
69 #define SOL_CXX17_FEATURES 1
70 #endif // C++17 features macro
71 #endif // C++17 features check
72 
73 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
74 #if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201403L))))
75 #ifndef SOL_NOEXCEPT_FUNCTION_TYPE
76 #define SOL_NOEXCEPT_FUNCTION_TYPE 1
77 #endif // noexcept is part of a function's type
78 #endif // compiler-specific checks
79 #if defined(__clang__) && defined(__APPLE__)
80 #if defined(__has_include)
81 #if __has_include(<variant>)
82 #define SOL_STD_VARIANT 1
83 #endif // has include nonsense
84 #endif // __has_include
85 #else
86 #define SOL_STD_VARIANT 1
87 #endif // Clang screws up variant
88 #endif // C++17 only
89 
90 // beginning of sol/config.hpp
91 
92 #ifdef _MSC_VER
93  #if defined(_DEBUG) && !defined(NDEBUG)
94 
95  #ifndef SOL_IN_DEBUG_DETECTED
96  #define SOL_IN_DEBUG_DETECTED 1
97  #endif
98 
99  #endif // VC++ Debug macros
100 
101  #ifndef _CPPUNWIND
102  #ifndef SOL_NO_EXCEPTIONS
103  #define SOL_NO_EXCEPTIONS 1
104  #endif
105  #endif // Automatic Exceptions
106 
107  #ifndef _CPPRTTI
108  #ifndef SOL_NO_RTTI
109  #define SOL_NO_RTTI 1
110  #endif
111  #endif // Automatic RTTI
112 #elif defined(__GNUC__) || defined(__clang__)
113 
114  #if !defined(NDEBUG) && !defined(__OPTIMIZE__)
115 
116  #ifndef SOL_IN_DEBUG_DETECTED
117  #define SOL_IN_DEBUG_DETECTED 1
118  #endif
119 
120  #endif // Not Debug && g++ optimizer flag
121 
122  #ifndef __EXCEPTIONS
123  #ifndef SOL_NO_EXCEPTIONS
124  #define SOL_NO_EXCEPTIONS 1
125  #endif
126  #endif // No Exceptions
127 
128  #ifndef __GXX_RTTI
129  #ifndef SOL_NO_RTII
130  #define SOL_NO_RTTI 1
131  #endif
132  #endif // No RTTI
133 
134 #endif // vc++ || clang++/g++
135 
136 #if defined(SOL_CHECK_ARGUMENTS) && SOL_CHECK_ARGUMENTS
137 
138  // Checks low-level getter function
139  // (and thusly, affects nearly entire framework)
140  #if !defined(SOL_SAFE_GETTER)
141  #define SOL_SAFE_GETTER 1
142  #endif
143 
144  // Checks access on usertype functions
145  // local my_obj = my_type.new()
146  // my_obj.my_member_function()
147  // -- bad syntax and crash
148  #if !defined(SOL_SAFE_USERTYPE)
149  #define SOL_SAFE_USERTYPE 1
150  #endif
151 
152  // Checks sol::reference derived boundaries
153  // sol::function ref(L, 1);
154  // sol::userdata sref(L, 2);
155  #if !defined(SOL_SAFE_REFERENCES)
156  #define SOL_SAFE_REFERENCES 1
157  #endif
158 
159  // Changes all typedefs of sol::function to point to the
160  // protected_function version, instead of unsafe_function
161  #if !defined(SOL_SAFE_FUNCTION)
162  #define SOL_SAFE_FUNCTION 1
163  #endif
164 
165  // Checks function parameters and
166  // returns upon call into/from Lua
167  // local a = 1
168  // local b = "woof"
169  // my_c_function(a, b)
170  #if !defined(SOL_SAFE_FUNCTION_CALLS)
171  #define SOL_SAFE_FUNCTION_CALLS 1
172  #endif
173 
174  // Checks conversions
175  // int v = lua["bark"];
176  // int v2 = my_sol_function();
177  #if !defined(SOL_SAFE_PROXIES)
178  #define SOL_SAFE_PROXIES 1
179  #endif
180 
181  // Check overflowing number conversions
182  // for things like 64 bit integers that don't fit in a typical lua_Number
183  // for Lua 5.1 and 5.2
184  #if !defined(SOL_SAFE_NUMERICS)
185  #define SOL_SAFE_NUMERICS 1
186  #endif
187 
188  // Turn off Number Precision Checks
189  // if this is defined, we do not do range
190  // checks on integers / unsigned integers that might
191  // be bigger than what Lua can represent
192  #if !defined(SOL_NO_CHECK_NUMBER_PRECISION)
193  // off by default
194  #define SOL_NO_CHECK_NUMBER_PRECISION 0
195  #endif
196 
197 #endif // Turn on Safety for all if top-level macro is defined
198 
199 #if defined(SOL_IN_DEBUG_DETECTED) && SOL_IN_DEBUG_DETECTED
200 
201  #if !defined(SOL_SAFE_REFERENCES)
202  // Ensure that references are forcefully type-checked upon construction
203  #define SOL_SAFE_REFERENCES 1
204  #endif
205 
206  // Safe usertypes checks for errors such as
207  // obj = my_type.new()
208  // obj.f() -- note the '.' instead of ':'
209  // usertypes should be safe no matter what
210  #if !defined(SOL_SAFE_USERTYPE)
211  #define SOL_SAFE_USERTYPE 1
212  #endif
213 
214  #if !defined(SOL_SAFE_FUNCTION_CALLS)
215  // Function calls from Lua should be automatically safe in debug mode
216  #define SOL_SAFE_FUNCTION_CALLS 1
217  #endif
218 
219  // Print any exceptions / errors that occur
220  // in debug mode to the default error stream / console
221  #if !defined(SOL_PRINT_ERRORS)
222  #define SOL_PRINT_ERRORS 1
223  #endif
224 
225 #endif // DEBUG: Turn on all debug safety features for VC++ / g++ / clang++ and similar
226 
227 #if !defined(SOL_PRINT_ERRORS)
228 #define SOL_PRINT_ERRORS 0
229 #endif
230 
231 #if !defined(SOL_DEFAULT_PASS_ON_ERROR)
232 #define SOL_DEFAULT_PASS_ON_ERROR 0
233 #endif
234 
235 #if !defined(SOL_ENABLE_INTEROP)
236 #define SOL_ENABLE_INTEROP 0
237 #endif
238 
239 #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
240 #if !defined(SOL_NO_NIL)
241 #define SOL_NO_NIL 1
242 #endif
243 #endif // avoiding nil defines / keywords
244 
245 #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
246 #ifndef SOL_UNORDERED_MAP_COMPATIBLE_HASH
247 #define SOL_UNORDERED_MAP_COMPATIBLE_HASH 1
248 #endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH
249 #endif
250 
251 #ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE
252 #define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024
253 #endif // Optimized conversion routines using a KB or so off the stack
254 
255 // end of sol/config.hpp
256 
257 // beginning of sol/config_setup.hpp
258 
259 // end of sol/config_setup.hpp
260 
261 // end of sol/feature_test.hpp
262 
263 namespace sol {
264 
265  template <bool b>
269  class stack_reference;
270 
271  struct proxy_base_tag;
272  template <typename Super>
273  struct proxy_base;
274  template <typename Table, typename Key>
275  struct proxy;
276 
277  template <typename T>
278  class usertype;
279  template <typename T>
281  template <bool, typename T>
283  template <bool b>
285  template <bool b>
287  template <bool b>
289  template <typename T>
297  template <typename base_t>
302  template <typename T, bool>
304  template <typename T, bool, typename H>
318 #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION
319  using function = protected_function;
322 #else
323  using function = unsafe_function;
326 #endif
329 
330  struct unsafe_function_result;
333 #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION
335 #else
337 #endif
338 
339  template <typename base_t>
341  template <typename base_t>
343  template <typename base_t>
345  template <typename base_t>
347  template <typename base_t>
349 
350  using object = basic_object<reference>;
364 
365  struct stack_proxy_base;
366  struct stack_proxy;
367  struct variadic_args;
368  struct variadic_results;
369  struct stack_count;
370  struct this_state;
371  struct this_main_state;
372  struct this_environment;
373 
374  template <typename T>
375  struct as_table_t;
376  template <typename T>
378  template <typename T>
379  struct nested;
380  template <typename T>
381  struct light;
382  template <typename T>
383  struct user;
384  template <typename T>
385  struct as_args_t;
386  template <typename T>
387  struct protect_t;
388  template <typename F, typename... Filters>
390 
391  template <typename T>
393  template <typename T>
395 } // namespace sol
396 
397 // end of sol/forward.hpp
398 
399 // beginning of sol/state.hpp
400 
401 // beginning of sol/state_view.hpp
402 
403 // beginning of sol/error.hpp
404 
405 #include <stdexcept>
406 #include <string>
407 
408 namespace sol {
409  namespace detail {
410  struct direct_error_tag {};
412  } // namespace detail
413 
414  class error : public std::runtime_error {
415  private:
416  // Because VC++ is upsetting, most of the time!
418 
419  public:
420  error(const std::string& str)
421  : error(detail::direct_error, "lua: error: " + str) {
422  }
424  : error(detail::direct_error, "lua: error: " + std::move(str)) {
425  }
427  : std::runtime_error(""), w(str) {
428  }
430  : std::runtime_error(""), w(std::move(str)) {
431  }
432 
433  error(const error& e) = default;
434  error(error&& e) = default;
435  error& operator=(const error& e) = default;
436  error& operator=(error&& e) = default;
437 
438  virtual const char* what() const noexcept override {
439  return w.c_str();
440  }
441  };
442 
443 } // namespace sol
444 
445 // end of sol/error.hpp
446 
447 // beginning of sol/table.hpp
448 
449 // beginning of sol/table_core.hpp
450 
451 // beginning of sol/proxy.hpp
452 
453 // beginning of sol/traits.hpp
454 
455 // beginning of sol/tuple.hpp
456 
457 #include <tuple>
458 #include <cstddef>
459 
460 namespace sol {
461  namespace detail {
462  using swallow = std::initializer_list<int>;
463  } // namespace detail
464 
465  template <typename... Args>
466  struct types {
467  typedef std::make_index_sequence<sizeof...(Args)> indices;
468  static constexpr std::size_t size() {
469  return sizeof...(Args);
470  }
471  };
472  namespace meta {
473  namespace detail {
474  template <typename... Args>
475  struct tuple_types_ { typedef types<Args...> type; };
476 
477  template <typename... Args>
478  struct tuple_types_<std::tuple<Args...>> { typedef types<Args...> type; };
479  } // namespace detail
480 
481  template <typename T>
482  using unqualified = std::remove_cv<std::remove_reference_t<T>>;
483 
484  template <typename T>
486 
487  template <typename... Args>
488  using tuple_types = typename detail::tuple_types_<Args...>::type;
489 
490  template <typename Arg>
492 
493  template <typename Arg>
495 
496  template <typename... Args>
497  struct pop_front_type<types<Args...>> {
498  typedef void front_type;
499  typedef types<Args...> type;
500  };
501 
502  template <typename Arg, typename... Args>
503  struct pop_front_type<types<Arg, Args...>> {
504  typedef Arg front_type;
505  typedef types<Args...> type;
506  };
507 
508  template <std::size_t N, typename Tuple>
509  using tuple_element = std::tuple_element<N, std::remove_reference_t<Tuple>>;
510 
511  template <std::size_t N, typename Tuple>
512  using tuple_element_t = std::tuple_element_t<N, std::remove_reference_t<Tuple>>;
513 
514  template <std::size_t N, typename Tuple>
516 
517  template <std::size_t N, typename Tuple>
519 
520  } // namespace meta
521 } // namespace sol
522 
523 // end of sol/tuple.hpp
524 
525 // beginning of sol/bind_traits.hpp
526 
527 namespace sol {
528 namespace meta {
529  namespace meta_detail {
530 
531  template <class F>
533  struct nat {};
534  template <class G>
535  static auto test(int) -> decltype(&G::operator(), void());
536  template <class>
537  static auto test(...) -> nat;
538 
539  using type = std::is_void<decltype(test<F>(0))>;
540  };
541  } // namespace meta_detail
542 
543  template <class F>
545 
546  namespace meta_detail {
547 
548  template <std::size_t I, typename T>
550 
551  template <std::size_t I>
552  struct void_tuple_element<I, std::tuple<>> { typedef void type; };
553 
554  template <std::size_t I, typename T>
556 
557  template <bool it_is_noexcept, bool has_c_variadic, typename T, typename R, typename... Args>
558  struct basic_traits {
559  private:
560  typedef std::conditional_t<std::is_void<T>::value, int, T>& first_type;
561 
562  public:
563  static const bool is_noexcept = it_is_noexcept;
564  static const bool is_member_function = std::is_void<T>::value;
565  static const bool has_c_var_arg = has_c_variadic;
566  static const std::size_t arity = sizeof...(Args);
567  static const std::size_t free_arity = sizeof...(Args) + static_cast<std::size_t>(!std::is_void<T>::value);
568  typedef types<Args...> args_list;
569  typedef std::tuple<Args...> args_tuple;
570  typedef T object_type;
571  typedef R return_type;
573  typedef R(function_type)(Args...);
574  typedef std::conditional_t<std::is_void<T>::value, args_list, types<first_type, Args...>> free_args_list;
575  typedef std::conditional_t<std::is_void<T>::value, R(Args...), R(first_type, Args...)> free_function_type;
576  typedef std::conditional_t<std::is_void<T>::value, R (*)(Args...), R (*)(first_type, Args...)> free_function_pointer_type;
577  typedef std::remove_pointer_t<free_function_pointer_type> signature_type;
578  template <std::size_t i>
580  };
581 
582  template <typename Signature, bool b = has_deducible_signature<Signature>::value>
583  struct fx_traits : basic_traits<false, false, void, void> {};
584 
585  // Free Functions
586  template <typename R, typename... Args>
587  struct fx_traits<R(Args...), false> : basic_traits<false, false, void, R, Args...> {
588  typedef R (*function_pointer_type)(Args...);
589  };
590 
591  template <typename R, typename... Args>
592  struct fx_traits<R (*)(Args...), false> : basic_traits<false, false, void, R, Args...> {
593  typedef R (*function_pointer_type)(Args...);
594  };
595 
596  template <typename R, typename... Args>
597  struct fx_traits<R(Args..., ...), false> : basic_traits<false, true, void, R, Args...> {
598  typedef R (*function_pointer_type)(Args..., ...);
599  };
600 
601  template <typename R, typename... Args>
602  struct fx_traits<R (*)(Args..., ...), false> : basic_traits<false, true, void, R, Args...> {
603  typedef R (*function_pointer_type)(Args..., ...);
604  };
605 
606  // Member Functions
607  /* C-Style Variadics */
608  template <typename T, typename R, typename... Args>
609  struct fx_traits<R (T::*)(Args...), false> : basic_traits<false, false, T, R, Args...> {
610  typedef R (T::*function_pointer_type)(Args...);
611  };
612 
613  template <typename T, typename R, typename... Args>
614  struct fx_traits<R (T::*)(Args..., ...), false> : basic_traits<false, true, T, R, Args...> {
615  typedef R (T::*function_pointer_type)(Args..., ...);
616  };
617 
618  /* Const Volatile */
619  template <typename T, typename R, typename... Args>
620  struct fx_traits<R (T::*)(Args...) const, false> : basic_traits<false, false, T, R, Args...> {
621  typedef R (T::*function_pointer_type)(Args...) const;
622  };
623 
624  template <typename T, typename R, typename... Args>
625  struct fx_traits<R (T::*)(Args..., ...) const, false> : basic_traits<false, true, T, R, Args...> {
626  typedef R (T::*function_pointer_type)(Args..., ...) const;
627  };
628 
629  template <typename T, typename R, typename... Args>
630  struct fx_traits<R (T::*)(Args...) const volatile, false> : basic_traits<false, false, T, R, Args...> {
631  typedef R (T::*function_pointer_type)(Args...) const volatile;
632  };
633 
634  template <typename T, typename R, typename... Args>
635  struct fx_traits<R (T::*)(Args..., ...) const volatile, false> : basic_traits<false, true, T, R, Args...> {
636  typedef R (T::*function_pointer_type)(Args..., ...) const volatile;
637  };
638 
639  /* Member Function Qualifiers */
640  template <typename T, typename R, typename... Args>
641  struct fx_traits<R (T::*)(Args...)&, false> : basic_traits<false, false, T, R, Args...> {
642  typedef R (T::*function_pointer_type)(Args...) &;
643  };
644 
645  template <typename T, typename R, typename... Args>
646  struct fx_traits<R (T::*)(Args..., ...)&, false> : basic_traits<false, true, T, R, Args...> {
647  typedef R (T::*function_pointer_type)(Args..., ...) &;
648  };
649 
650  template <typename T, typename R, typename... Args>
651  struct fx_traits<R (T::*)(Args...) const&, false> : basic_traits<false, false, T, R, Args...> {
652  typedef R (T::*function_pointer_type)(Args...) const&;
653  };
654 
655  template <typename T, typename R, typename... Args>
656  struct fx_traits<R (T::*)(Args..., ...) const&, false> : basic_traits<false, true, T, R, Args...> {
657  typedef R (T::*function_pointer_type)(Args..., ...) const&;
658  };
659 
660  template <typename T, typename R, typename... Args>
661  struct fx_traits<R (T::*)(Args...) const volatile&, false> : basic_traits<false, false, T, R, Args...> {
662  typedef R (T::*function_pointer_type)(Args...) const volatile&;
663  };
664 
665  template <typename T, typename R, typename... Args>
666  struct fx_traits<R (T::*)(Args..., ...) const volatile&, false> : basic_traits<false, true, T, R, Args...> {
667  typedef R (T::*function_pointer_type)(Args..., ...) const volatile&;
668  };
669 
670  template <typename T, typename R, typename... Args>
671  struct fx_traits<R (T::*)(Args...)&&, false> : basic_traits<false, false, T, R, Args...> {
672  typedef R (T::*function_pointer_type)(Args...) &&;
673  };
674 
675  template <typename T, typename R, typename... Args>
676  struct fx_traits<R (T::*)(Args..., ...)&&, false> : basic_traits<false, true, T, R, Args...> {
677  typedef R (T::*function_pointer_type)(Args..., ...) &&;
678  };
679 
680  template <typename T, typename R, typename... Args>
681  struct fx_traits<R (T::*)(Args...) const&&, false> : basic_traits<false, false, T, R, Args...> {
682  typedef R (T::*function_pointer_type)(Args...) const&&;
683  };
684 
685  template <typename T, typename R, typename... Args>
686  struct fx_traits<R (T::*)(Args..., ...) const&&, false> : basic_traits<false, true, T, R, Args...> {
687  typedef R (T::*function_pointer_type)(Args..., ...) const&&;
688  };
689 
690  template <typename T, typename R, typename... Args>
691  struct fx_traits<R (T::*)(Args...) const volatile&&, false> : basic_traits<false, false, T, R, Args...> {
692  typedef R (T::*function_pointer_type)(Args...) const volatile&&;
693  };
694 
695  template <typename T, typename R, typename... Args>
696  struct fx_traits<R (T::*)(Args..., ...) const volatile&&, false> : basic_traits<false, true, T, R, Args...> {
697  typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&;
698  };
699 
700 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
701 
702  template <typename R, typename... Args>
703  struct fx_traits<R(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
704  typedef R (*function_pointer_type)(Args...) noexcept;
705  };
706 
707  template <typename R, typename... Args>
708  struct fx_traits<R (*)(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
709  typedef R (*function_pointer_type)(Args...) noexcept;
710  };
711 
712  template <typename R, typename... Args>
713  struct fx_traits<R(Args..., ...) noexcept, false> : basic_traits<true, true, void, R, Args...> {
714  typedef R (*function_pointer_type)(Args..., ...) noexcept;
715  };
716 
717  template <typename R, typename... Args>
718  struct fx_traits<R (*)(Args..., ...) noexcept, false> : basic_traits<true, true, void, R, Args...> {
719  typedef R (*function_pointer_type)(Args..., ...) noexcept;
720  };
721 
722  template <typename T, typename R, typename... Args>
723  struct fx_traits<R (T::*)(Args...) noexcept, false> : basic_traits<true, false, T, R, Args...> {
724  typedef R (T::*function_pointer_type)(Args...) noexcept;
725  };
726 
727  template <typename T, typename R, typename... Args>
728  struct fx_traits<R (T::*)(Args..., ...) noexcept, false> : basic_traits<true, true, T, R, Args...> {
729  typedef R (T::*function_pointer_type)(Args..., ...) noexcept;
730  };
731 
732  /* Const Volatile */
733  template <typename T, typename R, typename... Args>
734  struct fx_traits<R (T::*)(Args...) const noexcept, false> : basic_traits<true, false, T, R, Args...> {
735  typedef R (T::*function_pointer_type)(Args...) const noexcept;
736  };
737 
738  template <typename T, typename R, typename... Args>
739  struct fx_traits<R (T::*)(Args..., ...) const noexcept, false> : basic_traits<true, true, T, R, Args...> {
740  typedef R (T::*function_pointer_type)(Args..., ...) const noexcept;
741  };
742 
743  template <typename T, typename R, typename... Args>
744  struct fx_traits<R (T::*)(Args...) const volatile noexcept, false> : basic_traits<true, false, T, R, Args...> {
745  typedef R (T::*function_pointer_type)(Args...) const volatile noexcept;
746  };
747 
748  template <typename T, typename R, typename... Args>
749  struct fx_traits<R (T::*)(Args..., ...) const volatile noexcept, false> : basic_traits<true, true, T, R, Args...> {
750  typedef R (T::*function_pointer_type)(Args..., ...) const volatile noexcept;
751  };
752 
753  template <typename T, typename R, typename... Args>
754  struct fx_traits<R (T::*)(Args...) & noexcept, false> : basic_traits<true, false, T, R, Args...> {
755  typedef R (T::*function_pointer_type)(Args...) & noexcept;
756  };
757 
758  template <typename T, typename R, typename... Args>
759  struct fx_traits<R (T::*)(Args..., ...) & noexcept, false> : basic_traits<true, true, T, R, Args...> {
760  typedef R (T::*function_pointer_type)(Args..., ...) & noexcept;
761  };
762 
763  template <typename T, typename R, typename... Args>
764  struct fx_traits<R (T::*)(Args...) const& noexcept, false> : basic_traits<true, false, T, R, Args...> {
765  typedef R (T::*function_pointer_type)(Args...) const& noexcept;
766  };
767 
768  template <typename T, typename R, typename... Args>
769  struct fx_traits<R (T::*)(Args..., ...) const& noexcept, false> : basic_traits<true, true, T, R, Args...> {
770  typedef R (T::*function_pointer_type)(Args..., ...) const& noexcept;
771  };
772 
773  template <typename T, typename R, typename... Args>
774  struct fx_traits<R (T::*)(Args...) const volatile& noexcept, false> : basic_traits<true, false, T, R, Args...> {
775  typedef R (T::*function_pointer_type)(Args...) const volatile& noexcept;
776  };
777 
778  template <typename T, typename R, typename... Args>
779  struct fx_traits<R (T::*)(Args..., ...) const volatile& noexcept, false> : basic_traits<true, true, T, R, Args...> {
780  typedef R (T::*function_pointer_type)(Args..., ...) const volatile& noexcept;
781  };
782 
783  template <typename T, typename R, typename... Args>
784  struct fx_traits<R (T::*)(Args...) && noexcept, false> : basic_traits<true, false, T, R, Args...> {
785  typedef R (T::*function_pointer_type)(Args...) && noexcept;
786  };
787 
788  template <typename T, typename R, typename... Args>
789  struct fx_traits<R (T::*)(Args..., ...) && noexcept, false> : basic_traits<true, true, T, R, Args...> {
790  typedef R (T::*function_pointer_type)(Args..., ...) && noexcept;
791  };
792 
793  template <typename T, typename R, typename... Args>
794  struct fx_traits<R (T::*)(Args...) const&& noexcept, false> : basic_traits<true, false, T, R, Args...> {
795  typedef R (T::*function_pointer_type)(Args...) const&& noexcept;
796  };
797 
798  template <typename T, typename R, typename... Args>
799  struct fx_traits<R (T::*)(Args..., ...) const&& noexcept, false> : basic_traits<true, true, T, R, Args...> {
800  typedef R (T::*function_pointer_type)(Args..., ...) const&& noexcept;
801  };
802 
803  template <typename T, typename R, typename... Args>
804  struct fx_traits<R (T::*)(Args...) const volatile&& noexcept, false> : basic_traits<true, false, T, R, Args...> {
805  typedef R (T::*function_pointer_type)(Args...) const volatile&& noexcept;
806  };
807 
808  template <typename T, typename R, typename... Args>
809  struct fx_traits<R (T::*)(Args..., ...) const volatile&& noexcept, false> : basic_traits<true, true, T, R, Args...> {
810  typedef R (T::*function_pointer_type)(Args..., ...) const volatile&& noexcept;
811  };
812 
813 #endif // noexcept is part of a function's type
814 
815 #if defined(_MSC_VER) && defined(_M_IX86)
816  template <typename R, typename... Args>
817  struct fx_traits<R __stdcall(Args...), false> : basic_traits<false, false, void, R, Args...> {
818  typedef R(__stdcall* function_pointer_type)(Args...);
819  };
820 
821  template <typename R, typename... Args>
822  struct fx_traits<R(__stdcall*)(Args...), false> : basic_traits<false, false, void, R, Args...> {
823  typedef R(__stdcall* function_pointer_type)(Args...);
824  };
825 
826  template <typename T, typename R, typename... Args>
827  struct fx_traits<R (__stdcall T::*)(Args...), false> : basic_traits<false, false, T, R, Args...> {
828  typedef R (__stdcall T::*function_pointer_type)(Args...);
829  };
830 
831  /* Const Volatile */
832  template <typename T, typename R, typename... Args>
833  struct fx_traits<R (__stdcall T::*)(Args...) const, false> : basic_traits<false, false, T, R, Args...> {
834  typedef R (__stdcall T::*function_pointer_type)(Args...) const;
835  };
836 
837  template <typename T, typename R, typename... Args>
838  struct fx_traits<R (__stdcall T::*)(Args...) const volatile, false> : basic_traits<false, false, T, R, Args...> {
839  typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile;
840  };
841 
842  /* Member Function Qualifiers */
843  template <typename T, typename R, typename... Args>
844  struct fx_traits<R (__stdcall T::*)(Args...)&, false> : basic_traits<false, false, T, R, Args...> {
845  typedef R (__stdcall T::*function_pointer_type)(Args...) &;
846  };
847 
848  template <typename T, typename R, typename... Args>
849  struct fx_traits<R (__stdcall T::*)(Args...) const&, false> : basic_traits<false, false, T, R, Args...> {
850  typedef R (__stdcall T::*function_pointer_type)(Args...) const&;
851  };
852 
853  template <typename T, typename R, typename... Args>
854  struct fx_traits<R (__stdcall T::*)(Args...) const volatile&, false> : basic_traits<false, false, T, R, Args...> {
855  typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&;
856  };
857 
858  template <typename T, typename R, typename... Args>
859  struct fx_traits<R (__stdcall T::*)(Args...)&&, false> : basic_traits<false, false, T, R, Args...> {
860  typedef R (__stdcall T::*function_pointer_type)(Args...) &&;
861  };
862 
863  template <typename T, typename R, typename... Args>
864  struct fx_traits<R (__stdcall T::*)(Args...) const&&, false> : basic_traits<false, false, T, R, Args...> {
865  typedef R (__stdcall T::*function_pointer_type)(Args...) const&&;
866  };
867 
868  template <typename T, typename R, typename... Args>
869  struct fx_traits<R (__stdcall T::*)(Args...) const volatile&&, false> : basic_traits<false, false, T, R, Args...> {
870  typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&;
871  };
872 
873 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
874 
875  template <typename R, typename... Args>
876  struct fx_traits<R __stdcall(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
877  typedef R(__stdcall* function_pointer_type)(Args...) noexcept;
878  };
879 
880  template <typename R, typename... Args>
881  struct fx_traits<R (__stdcall *)(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
882  typedef R(__stdcall* function_pointer_type)(Args...) noexcept;
883  };
884 
885  /* __stdcall cannot be applied to functions with varargs*/
886  /*template <typename R, typename... Args>
887  struct fx_traits<__stdcall R(Args..., ...) noexcept, false> : basic_traits<true, true, void, R, Args...> {
888  typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept;
889  };
890 
891  template <typename R, typename... Args>
892  struct fx_traits<R (__stdcall *)(Args..., ...) noexcept, false> : basic_traits<true, true, void, R, Args...> {
893  typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept;
894  };*/
895 
896  template <typename T, typename R, typename... Args>
897  struct fx_traits<R (__stdcall T::*)(Args...) noexcept, false> : basic_traits<true, false, T, R, Args...> {
898  typedef R (__stdcall T::*function_pointer_type)(Args...) noexcept;
899  };
900 
901  /* __stdcall does not work with varargs */
902  /*template <typename T, typename R, typename... Args>
903  struct fx_traits<R (__stdcall T::*)(Args..., ...) noexcept, false> : basic_traits<true, true, T, R, Args...> {
904  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) noexcept;
905  };*/
906 
907  /* Const Volatile */
908  template <typename T, typename R, typename... Args>
909  struct fx_traits<R (__stdcall T::*)(Args...) const noexcept, false> : basic_traits<true, false, T, R, Args...> {
910  typedef R (__stdcall T::*function_pointer_type)(Args...) const noexcept;
911  };
912 
913  /* __stdcall does not work with varargs */
914  /*template <typename T, typename R, typename... Args>
915  struct fx_traits<R (__stdcall T::*)(Args..., ...) const noexcept, false> : basic_traits<true, true, T, R, Args...> {
916  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const noexcept;
917  };*/
918 
919  template <typename T, typename R, typename... Args>
920  struct fx_traits<R (__stdcall T::*)(Args...) const volatile noexcept, false> : basic_traits<true, false, T, R, Args...> {
921  typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile noexcept;
922  };
923 
924  /* __stdcall does not work with varargs */
925  /*template <typename T, typename R, typename... Args>
926  struct fx_traits<R (__stdcall T::*)(Args..., ...) const volatile noexcept, false> : basic_traits<true, true, T, R, Args...> {
927  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile noexcept;
928  };*/
929 
930  template <typename T, typename R, typename... Args>
931  struct fx_traits<R (__stdcall T::*)(Args...) & noexcept, false> : basic_traits<true, false, T, R, Args...> {
932  typedef R (__stdcall T::*function_pointer_type)(Args...) & noexcept;
933  };
934 
935  /* __stdcall does not work with varargs */
936  /*template <typename T, typename R, typename... Args>
937  struct fx_traits<R (__stdcall T::*)(Args..., ...) & noexcept, false> : basic_traits<true, true, T, R, Args...> {
938  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) & noexcept;
939  };*/
940 
941  template <typename T, typename R, typename... Args>
942  struct fx_traits<R (__stdcall T::*)(Args...) const& noexcept, false> : basic_traits<true, false, T, R, Args...> {
943  typedef R (__stdcall T::*function_pointer_type)(Args...) const& noexcept;
944  };
945 
946  /* __stdcall does not work with varargs */
947  /*template <typename T, typename R, typename... Args>
948  struct fx_traits<R (__stdcall T::*)(Args..., ...) const& noexcept, false> : basic_traits<true, true, T, R, Args...> {
949  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const& noexcept;
950  };*/
951 
952  template <typename T, typename R, typename... Args>
953  struct fx_traits<R (__stdcall T::*)(Args...) const volatile& noexcept, false> : basic_traits<true, false, T, R, Args...> {
954  typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile& noexcept;
955  };
956 
957  /* __stdcall does not work with varargs */
958  /*template <typename T, typename R, typename... Args>
959  struct fx_traits<R (__stdcall T::*)(Args..., ...) const volatile& noexcept, false> : basic_traits<true, true, T, R, Args...> {
960  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile& noexcept;
961  };*/
962 
963  template <typename T, typename R, typename... Args>
964  struct fx_traits<R (__stdcall T::*)(Args...) && noexcept, false> : basic_traits<true, false, T, R, Args...> {
965  typedef R (__stdcall T::*function_pointer_type)(Args...) && noexcept;
966  };
967 
968  /* __stdcall does not work with varargs */
969  /*template <typename T, typename R, typename... Args>
970  struct fx_traits<R (__stdcall T::*)(Args..., ...) && noexcept, false> : basic_traits<true, true, T, R, Args...> {
971  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) && noexcept;
972  };*/
973 
974  template <typename T, typename R, typename... Args>
975  struct fx_traits<R (__stdcall T::*)(Args...) const&& noexcept, false> : basic_traits<true, false, T, R, Args...> {
976  typedef R (__stdcall T::*function_pointer_type)(Args...) const&& noexcept;
977  };
978 
979  /* __stdcall does not work with varargs */
980  /*template <typename T, typename R, typename... Args>
981  struct fx_traits<R (__stdcall T::*)(Args..., ...) const&& noexcept, false> : basic_traits<true, true, T, R, Args...> {
982  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const&& noexcept;
983  };*/
984 
985  template <typename T, typename R, typename... Args>
986  struct fx_traits<R (__stdcall T::*)(Args...) const volatile&& noexcept, false> : basic_traits<true, false, T, R, Args...> {
987  typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&& noexcept;
988  };
989 
990  /* __stdcall does not work with varargs */
991  /*template <typename T, typename R, typename... Args>
992  struct fx_traits<R (__stdcall T::*)(Args..., ...) const volatile&& noexcept, false> : basic_traits<true, true, T, R, Args...> {
993  typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile&& noexcept;
994  };*/
995 #endif // noexcept is part of a function's type
996 #endif // __stdcall x86 VC++ bug
997 
998  template <typename Signature>
999  struct fx_traits<Signature, true> : fx_traits<typename fx_traits<decltype(&Signature::operator())>::function_type, false> {};
1000 
1001  template <typename Signature, bool b = std::is_member_object_pointer<Signature>::value>
1002  struct callable_traits : fx_traits<std::decay_t<Signature>> {
1003  };
1004 
1005  template <typename R, typename T>
1006  struct callable_traits<R(T::*), true> {
1007  typedef std::conditional_t<std::is_array<R>::value, std::add_lvalue_reference_t<T>, R> return_type;
1008  typedef return_type Arg;
1009  typedef T object_type;
1010  using signature_type = R(T::*);
1011  static const bool is_noexcept = false;
1012  static const bool is_member_function = false;
1013  static const std::size_t arity = 1;
1014  static const std::size_t free_arity = 2;
1015  typedef std::tuple<Arg> args_tuple;
1019  typedef return_type(function_type)(T&, return_type);
1020  typedef return_type(*function_pointer_type)(T&, Arg);
1021  typedef return_type(*free_function_pointer_type)(T&, Arg);
1022  template <std::size_t i>
1024  };
1025 
1026  } // namespace meta_detail
1027 
1028  template <typename Signature>
1030 
1031  template <typename Signature>
1033 
1034  template <typename Signature>
1036 
1037  template <typename Signature>
1039 }
1040 } // namespace sol::meta
1041 
1042 // end of sol/bind_traits.hpp
1043 
1044 // beginning of sol/string_view.hpp
1045 
1046 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
1047 #include <string_view>
1048 #endif // C++17 features
1049 #include <functional>
1050 #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
1051 #include <boost/functional/hash.hpp>
1052 #endif
1053 
1054 namespace sol {
1055 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
1056  template <typename C, typename T = std::char_traits<C>>
1057  using basic_string_view = std::basic_string_view<C, T>;
1058  typedef std::string_view string_view;
1062  typedef std::hash<std::string_view> string_view_hash;
1063 #else
1064  template <typename Char, typename Traits = std::char_traits<Char>>
1065  struct basic_string_view {
1066  std::size_t s;
1067  const Char* p;
1068 
1070  : basic_string_view(r.data(), r.size()) {
1071  }
1072  basic_string_view(const Char* ptr)
1073  : basic_string_view(ptr, Traits::length(ptr)) {
1074  }
1075  basic_string_view(const Char* ptr, std::size_t sz)
1076  : s(sz), p(ptr) {
1077  }
1078 
1079  static int compare(const Char* lhs_p, std::size_t lhs_sz, const Char* rhs_p, std::size_t rhs_sz) {
1080  int result = Traits::compare(lhs_p, rhs_p, lhs_sz < rhs_sz ? lhs_sz : rhs_sz);
1081  if (result != 0)
1082  return result;
1083  if (lhs_sz < rhs_sz)
1084  return -1;
1085  if (lhs_sz > rhs_sz)
1086  return 1;
1087  return 0;
1088  }
1089 
1090  const Char* begin() const {
1091  return p;
1092  }
1093 
1094  const Char* end() const {
1095  return p + s;
1096  }
1097 
1098  const Char* cbegin() const {
1099  return p;
1100  }
1101 
1102  const Char* cend() const {
1103  return p + s;
1104  }
1105 
1106  const Char* data() const {
1107  return p;
1108  }
1109 
1110  std::size_t size() const {
1111  return s;
1112  }
1113 
1114  std::size_t length() const {
1115  return size();
1116  }
1117 
1118  operator std::basic_string<Char, Traits>() const {
1119  return std::basic_string<Char, Traits>(data(), size());
1120  }
1121 
1122  bool operator==(const basic_string_view& r) const {
1123  return compare(p, s, r.data(), r.size()) == 0;
1124  }
1125 
1126  bool operator==(const Char* r) const {
1127  return compare(r, Traits::length(r), p, s) == 0;
1128  }
1129 
1130  bool operator==(const std::basic_string<Char, Traits>& r) const {
1131  return compare(r.data(), r.size(), p, s) == 0;
1132  }
1133 
1134  bool operator!=(const basic_string_view& r) const {
1135  return !(*this == r);
1136  }
1137 
1138  bool operator!=(const char* r) const {
1139  return !(*this == r);
1140  }
1141 
1142  bool operator!=(const std::basic_string<Char, Traits>& r) const {
1143  return !(*this == r);
1144  }
1145  };
1146 
1147  template <typename Ch, typename Tr = std::char_traits<Ch>>
1150  typedef std::size_t result_type;
1151 
1152  template <typename Al>
1153  result_type operator()(const std::basic_string<Ch, Tr, Al>& r) const {
1154  return (*this)(argument_type(r.c_str(), r.size()));
1155  }
1156 
1157  result_type operator()(const argument_type& r) const {
1158 #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
1159  return boost::hash_range(r.begin(), r.end());
1160 #else
1161  // Modified, from libstdc++
1162  // An implementation attempt at Fowler No Voll, 1a.
1163  // Supposedly, used in MSVC,
1164  // GCC (libstdc++) uses MurmurHash of some sort for 64-bit though...?
1165  // But, well. Can't win them all, right?
1166  // This should normally only apply when NOT using boost,
1167  // so this should almost never be tapped into...
1168  std::size_t hash = 0;
1169  const unsigned char* cptr = reinterpret_cast<const unsigned char*>(r.data());
1170  for (std::size_t sz = r.size(); sz != 0; --sz) {
1171  hash ^= static_cast<size_t>(*cptr++);
1172  hash *= static_cast<size_t>(1099511628211ULL);
1173  }
1174  return hash;
1175 #endif
1176  }
1177  };
1178 } // namespace sol
1179 
1180 namespace std {
1181  template <typename Ch, typename Tr>
1182  struct hash< ::sol::basic_string_view<Ch, Tr> > : ::sol::basic_string_view_hash<Ch, Tr> {};
1183 } // namespace std
1184 
1185 namespace sol {
1190  using string_view_hash = std::hash<string_view>;
1191 #endif // C++17 Support
1192 } // namespace sol
1193 
1194 // end of sol/string_view.hpp
1195 
1196 #include <type_traits>
1197 #include <cstdint>
1198 #include <memory>
1199 #include <array>
1200 #include <iterator>
1201 #include <iosfwd>
1202 
1203 namespace sol {
1204  template <std::size_t I>
1205  using index_value = std::integral_constant<std::size_t, I>;
1206 
1207  namespace meta {
1208  typedef std::array<char, 1> sfinae_yes_t;
1209  typedef std::array<char, 2> sfinae_no_t;
1210 
1211  template <typename T>
1212  struct identity { typedef T type; };
1213 
1214  template <typename T>
1215  using identity_t = typename identity<T>::type;
1216 
1217  template <typename... Args>
1218  struct is_tuple : std::false_type {};
1219 
1220  template <typename... Args>
1221  struct is_tuple<std::tuple<Args...>> : std::true_type {};
1222 
1223  template <typename T>
1224  struct is_builtin_type : std::integral_constant<bool, std::is_arithmetic<T>::value || std::is_pointer<T>::value || std::is_array<T>::value> {};
1225 
1226  template <typename T>
1227  struct unwrapped {
1228  typedef T type;
1229  };
1230 
1231  template <typename T>
1232  struct unwrapped<std::reference_wrapper<T>> {
1233  typedef T type;
1234  };
1235 
1236  template <typename T>
1238 
1239  template <typename T>
1240  struct unwrap_unqualified : unwrapped<unqualified_t<T>> {};
1241 
1242  template <typename T>
1244 
1245  template <typename T>
1247 
1248  template <typename R, typename T>
1249  struct remove_member_pointer<R T::*> {
1250  typedef R type;
1251  };
1252 
1253  template <typename R, typename T>
1254  struct remove_member_pointer<R T::*const> {
1255  typedef R type;
1256  };
1257 
1258  template <typename T>
1260 
1261  namespace meta_detail {
1262  template <typename T, template <typename...> class Templ>
1263  struct is_specialization_of : std::false_type {};
1264  template <typename... T, template <typename...> class Templ>
1265  struct is_specialization_of<Templ<T...>, Templ> : std::true_type {};
1266  }
1267 
1268  template <typename T, template <typename...> class Templ>
1270 
1271  template <class T, class...>
1272  struct all_same : std::true_type {};
1273 
1274  template <class T, class U, class... Args>
1275  struct all_same<T, U, Args...> : std::integral_constant<bool, std::is_same<T, U>::value && all_same<T, Args...>::value> {};
1276 
1277  template <class T, class...>
1278  struct any_same : std::false_type {};
1279 
1280  template <class T, class U, class... Args>
1281  struct any_same<T, U, Args...> : std::integral_constant<bool, std::is_same<T, U>::value || any_same<T, Args...>::value> {};
1282 
1283  template <bool B>
1284  using boolean = std::integral_constant<bool, B>;
1285 
1286  template <typename T>
1287  using invoke_t = typename T::type;
1288 
1289  template <typename T>
1291 
1292  template <typename T>
1294 
1295  template <typename Condition, typename Then, typename Else>
1296  using condition = std::conditional_t<Condition::value, Then, Else>;
1297 
1298  template <typename... Args>
1299  struct all : boolean<true> {};
1300 
1301  template <typename T, typename... Args>
1302  struct all<T, Args...> : condition<T, all<Args...>, boolean<false>> {};
1303 
1304  template <typename... Args>
1305  struct any : boolean<false> {};
1306 
1307  template <typename T, typename... Args>
1308  struct any<T, Args...> : condition<T, boolean<true>, any<Args...>> {};
1309 
1310  enum class enable_t {
1311  _
1312  };
1313 
1314  constexpr const auto enabler = enable_t::_;
1315 
1316  template <bool value, typename T = void>
1317  using disable_if_t = std::enable_if_t<!value, T>;
1318 
1319  template <typename... Args>
1320  using enable = std::enable_if_t<all<Args...>::value, enable_t>;
1321 
1322  template <typename... Args>
1323  using disable = std::enable_if_t<neg<all<Args...>>::value, enable_t>;
1324 
1325  template <typename... Args>
1326  using enable_any = std::enable_if_t<any<Args...>::value, enable_t>;
1327 
1328  template <typename... Args>
1329  using disable_any = std::enable_if_t<neg<any<Args...>>::value, enable_t>;
1330 
1331  template <typename V, typename... Vs>
1332  struct find_in_pack_v : boolean<false> {};
1333 
1334  template <typename V, typename Vs1, typename... Vs>
1335  struct find_in_pack_v<V, Vs1, Vs...> : any<boolean<(V::value == Vs1::value)>, find_in_pack_v<V, Vs...>> {};
1336 
1337  namespace meta_detail {
1338  template <std::size_t I, typename T, typename... Args>
1339  struct index_in_pack : std::integral_constant<std::size_t, SIZE_MAX> {};
1340 
1341  template <std::size_t I, typename T, typename T1, typename... Args>
1342  struct index_in_pack<I, T, T1, Args...> : std::conditional_t<std::is_same<T, T1>::value, std::integral_constant<std::ptrdiff_t, I>, index_in_pack<I + 1, T, Args...>> {};
1343  } // namespace meta_detail
1344 
1345  template <typename T, typename... Args>
1346  struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> {};
1347 
1348  template <typename T, typename List>
1349  struct index_in : meta_detail::index_in_pack<0, T, List> {};
1350 
1351  template <typename T, typename... Args>
1352  struct index_in<T, types<Args...>> : meta_detail::index_in_pack<0, T, Args...> {};
1353 
1354  template <std::size_t I, typename... Args>
1355  struct at_in_pack {};
1356 
1357  template <std::size_t I, typename... Args>
1358  using at_in_pack_t = typename at_in_pack<I, Args...>::type;
1359 
1360  template <std::size_t I, typename Arg, typename... Args>
1361  struct at_in_pack<I, Arg, Args...> : std::conditional<I == 0, Arg, at_in_pack_t<I - 1, Args...>> {};
1362 
1363  template <typename Arg, typename... Args>
1364  struct at_in_pack<0, Arg, Args...> { typedef Arg type; };
1365 
1366  namespace meta_detail {
1367  template <std::size_t Limit, std::size_t I, template <typename...> class Pred, typename... Ts>
1368  struct count_for_pack : std::integral_constant<std::size_t, 0> {};
1369  template <std::size_t Limit, std::size_t I, template <typename...> class Pred, typename T, typename... Ts>
1370  struct count_for_pack<Limit, I, Pred, T, Ts...> : std::conditional_t < sizeof...(Ts)
1371  == 0
1372  || Limit<2,
1373  std::integral_constant<std::size_t, I + static_cast<std::size_t>(Limit != 0 && Pred<T>::value)>,
1374  count_for_pack<Limit - 1, I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>> {};
1375  template <std::size_t I, template <typename...> class Pred, typename... Ts>
1376  struct count_2_for_pack : std::integral_constant<std::size_t, 0> {};
1377  template <std::size_t I, template <typename...> class Pred, typename T, typename U, typename... Ts>
1378  struct count_2_for_pack<I, Pred, T, U, Ts...> : std::conditional_t<sizeof...(Ts) == 0,
1379  std::integral_constant<std::size_t, I + static_cast<std::size_t>(Pred<T>::value)>,
1380  count_2_for_pack<I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>> {};
1381  } // namespace meta_detail
1382 
1383  template <template <typename...> class Pred, typename... Ts>
1384  struct count_for_pack : meta_detail::count_for_pack<sizeof...(Ts), 0, Pred, Ts...> {};
1385 
1386  template <template <typename...> class Pred, typename List>
1387  struct count_for;
1388 
1389  template <template <typename...> class Pred, typename... Args>
1390  struct count_for<Pred, types<Args...>> : count_for_pack<Pred, Args...> {};
1391 
1392  template <std::size_t Limit, template <typename...> class Pred, typename... Ts>
1393  struct count_for_to_pack : meta_detail::count_for_pack<Limit, 0, Pred, Ts...> {};
1394 
1395  template <template <typename...> class Pred, typename... Ts>
1396  struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> {};
1397 
1398  template <typename... Args>
1399  struct return_type {
1400  typedef std::tuple<Args...> type;
1401  };
1402 
1403  template <typename T>
1404  struct return_type<T> {
1405  typedef T type;
1406  };
1407 
1408  template <>
1409  struct return_type<> {
1410  typedef void type;
1411  };
1412 
1413  template <typename... Args>
1414  using return_type_t = typename return_type<Args...>::type;
1415 
1416  namespace meta_detail {
1417  template <typename>
1418  struct always_true : std::true_type {};
1419  struct is_invokable_tester {
1420  template <typename Fun, typename... Args>
1421  static always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> test(int);
1422  template <typename...>
1423  static std::false_type test(...);
1424  };
1425  } // namespace meta_detail
1426 
1427  template <typename T>
1428  struct is_invokable;
1429  template <typename Fun, typename... Args>
1430  struct is_invokable<Fun(Args...)> : decltype(meta_detail::is_invokable_tester::test<Fun, Args...>(0)) {};
1431 
1432  namespace meta_detail {
1433 
1434  template <typename T, typename = void>
1435  struct is_callable : std::is_function<std::remove_pointer_t<T>> {};
1436 
1437  template <typename T>
1438  struct is_callable<T, std::enable_if_t<std::is_final<unqualified_t<T>>::value
1439  && std::is_class<unqualified_t<T>>::value
1440  && std::is_same<decltype(void(&T::operator())), void>::value>> {
1441 
1442  };
1443 
1444  template <typename T>
1445  struct is_callable<T, std::enable_if_t<!std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value && std::is_destructible<unqualified_t<T>>::value>> {
1446  using yes = char;
1447  using no = struct { char s[2]; };
1448 
1449  struct F {
1450  void operator()();
1451  };
1452  struct Derived : T, F {};
1453  template <typename U, U>
1454  struct Check;
1455 
1456  template <typename V>
1457  static no test(Check<void (F::*)(), &V::operator()>*);
1458 
1459  template <typename>
1460  static yes test(...);
1461 
1462  static const bool value = sizeof(test<Derived>(0)) == sizeof(yes);
1463  };
1464 
1465  template <typename T>
1466  struct is_callable<T, std::enable_if_t<!std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value && !std::is_destructible<unqualified_t<T>>::value>> {
1467  using yes = char;
1468  using no = struct { char s[2]; };
1469 
1470  struct F {
1471  void operator()();
1472  };
1473  struct Derived : T, F {
1474  ~Derived() = delete;
1475  };
1476  template <typename U, U>
1477  struct Check;
1478 
1479  template <typename V>
1480  static no test(Check<void (F::*)(), &V::operator()>*);
1481 
1482  template <typename>
1483  static yes test(...);
1484 
1485  static const bool value = sizeof(test<Derived>(0)) == sizeof(yes);
1486  };
1487 
1488  struct has_begin_end_impl {
1489  template <typename T, typename U = unqualified_t<T>,
1490  typename B = decltype(std::declval<U&>().begin()),
1491  typename E = decltype(std::declval<U&>().end())>
1492  static std::true_type test(int);
1493 
1494  template <typename...>
1495  static std::false_type test(...);
1496  };
1497 
1498  struct has_key_type_impl {
1499  template <typename T, typename U = unqualified_t<T>,
1500  typename V = typename U::key_type>
1501  static std::true_type test(int);
1502 
1503  template <typename...>
1504  static std::false_type test(...);
1505  };
1506 
1507  struct has_mapped_type_impl {
1508  template <typename T, typename U = unqualified_t<T>,
1509  typename V = typename U::mapped_type>
1510  static std::true_type test(int);
1511 
1512  template <typename...>
1513  static std::false_type test(...);
1514  };
1515 
1516  struct has_value_type_impl {
1517  template <typename T, typename U = unqualified_t<T>,
1518  typename V = typename U::value_type>
1519  static std::true_type test(int);
1520 
1521  template <typename...>
1522  static std::false_type test(...);
1523  };
1524 
1525  struct has_iterator_impl {
1526  template <typename T, typename U = unqualified_t<T>,
1527  typename V = typename U::iterator>
1528  static std::true_type test(int);
1529 
1530  template <typename...>
1531  static std::false_type test(...);
1532  };
1533 
1534  struct has_key_value_pair_impl {
1535  template <typename T, typename U = unqualified_t<T>,
1536  typename V = typename U::value_type,
1537  typename F = decltype(std::declval<V&>().first),
1538  typename S = decltype(std::declval<V&>().second)>
1539  static std::true_type test(int);
1540 
1541  template <typename...>
1542  static std::false_type test(...);
1543  };
1544 
1545  template <typename T>
1546  struct has_push_back_test {
1547  private:
1548  template <typename C>
1549  static sfinae_yes_t test(decltype(std::declval<C>().push_back(std::declval<std::add_rvalue_reference_t<typename C::value_type>>())) *);
1550  template <typename C>
1551  static sfinae_no_t test(...);
1552 
1553  public:
1554  static const bool value = sizeof(test<T>(0)) == sizeof(sfinae_yes_t);
1555  };
1556 
1557  template <typename T>
1558  struct has_insert_test {
1559  private:
1560  template <typename C>
1561  static sfinae_yes_t test(decltype(std::declval<C>().insert(std::declval<std::add_rvalue_reference_t<typename C::const_iterator>>(), std::declval<std::add_rvalue_reference_t<typename C::value_type>>()))*);
1562  template <typename C>
1563  static sfinae_no_t test(...);
1564 
1565  public:
1566  static const bool value = sizeof(test<T>(0)) == sizeof(sfinae_yes_t);
1567  };
1568 
1569  template <typename T>
1570  struct has_insert_after_test {
1571  private:
1572  template <typename C>
1573  static sfinae_yes_t test(decltype(std::declval<C>().insert_after(std::declval<std::add_rvalue_reference_t<typename C::const_iterator>>(), std::declval<std::add_rvalue_reference_t<typename C::value_type>>()))*);
1574  template <typename C>
1575  static sfinae_no_t test(...);
1576 
1577  public:
1578  static const bool value = sizeof(test<T>(0)) == sizeof(sfinae_yes_t);
1579  };
1580 
1581  template <typename T>
1582  struct has_size_test {
1583  private:
1584  typedef std::array<char, 1> sfinae_yes_t;
1585  typedef std::array<char, 2> sfinae_no_t;
1586 
1587  template <typename C>
1588  static sfinae_yes_t test(decltype(std::declval<C>().size())*);
1589  template <typename C>
1590  static sfinae_no_t test(...);
1591 
1592  public:
1593  static const bool value = sizeof(test<T>(0)) == sizeof(sfinae_yes_t);
1594  };
1595 
1596  template <typename T>
1597  struct has_max_size_test {
1598  private:
1599  typedef std::array<char, 1> sfinae_yes_t;
1600  typedef std::array<char, 2> sfinae_no_t;
1601 
1602  template <typename C>
1603  static sfinae_yes_t test(decltype(std::declval<C>().max_size())*);
1604  template <typename C>
1605  static sfinae_no_t test(...);
1606 
1607  public:
1608  static const bool value = sizeof(test<T>(0)) == sizeof(sfinae_yes_t);
1609  };
1610 
1611  template <typename T>
1612  struct has_to_string_test {
1613  private:
1614  typedef std::array<char, 1> sfinae_yes_t;
1615  typedef std::array<char, 2> sfinae_no_t;
1616 
1617  template <typename C>
1618  static sfinae_yes_t test(decltype(std::declval<C>().to_string())*);
1619  template <typename C>
1620  static sfinae_no_t test(...);
1621 
1622  public:
1623  static const bool value = sizeof(test<T>(0)) == sizeof(sfinae_yes_t);
1624  };
1625 #if defined(_MSC_VER) && _MSC_VER <= 1910
1626  template <typename T, typename U, typename = decltype(std::declval<T&>() < std::declval<U&>())>
1627  std::true_type supports_op_less_test(std::reference_wrapper<T>, std::reference_wrapper<U>);
1628  std::false_type supports_op_less_test(...);
1629  template <typename T, typename U, typename = decltype(std::declval<T&>() == std::declval<U&>())>
1630  std::true_type supports_op_equal_test(std::reference_wrapper<T>, std::reference_wrapper<U>);
1631  std::false_type supports_op_equal_test(...);
1632  template <typename T, typename U, typename = decltype(std::declval<T&>() <= std::declval<U&>())>
1633  std::true_type supports_op_less_equal_test(std::reference_wrapper<T>, std::reference_wrapper<U>);
1634  std::false_type supports_op_less_equal_test(...);
1635  template <typename T, typename OS, typename = decltype(std::declval<OS&>() << std::declval<T&>())>
1636  std::true_type supports_ostream_op(std::reference_wrapper<T>, std::reference_wrapper<OS>);
1637  std::false_type supports_ostream_op(...);
1638  template <typename T, typename = decltype(to_string(std::declval<T&>()))>
1639  std::true_type supports_adl_to_string(std::reference_wrapper<T>);
1640  std::false_type supports_adl_to_string(...);
1641 #else
1642  template <typename T, typename U, typename = decltype(std::declval<T&>() < std::declval<U&>())>
1643  std::true_type supports_op_less_test(const T&, const U&);
1644  std::false_type supports_op_less_test(...);
1645  template <typename T, typename U, typename = decltype(std::declval<T&>() == std::declval<U&>())>
1646  std::true_type supports_op_equal_test(const T&, const U&);
1647  std::false_type supports_op_equal_test(...);
1648  template <typename T, typename U, typename = decltype(std::declval<T&>() <= std::declval<U&>())>
1649  std::true_type supports_op_less_equal_test(const T&, const U&);
1650  std::false_type supports_op_less_equal_test(...);
1651  template <typename T, typename OS, typename = decltype(std::declval<OS&>() << std::declval<T&>())>
1652  std::true_type supports_ostream_op(const T&, const OS&);
1653  std::false_type supports_ostream_op(...);
1654  template <typename T, typename = decltype(to_string(std::declval<T&>()))>
1655  std::true_type supports_adl_to_string(const T&);
1656  std::false_type supports_adl_to_string(...);
1657 #endif
1658 
1659  template <typename T, bool b>
1660  struct is_matched_lookup_impl : std::false_type {};
1661  template <typename T>
1662  struct is_matched_lookup_impl<T, true> : std::is_same<typename T::key_type, typename T::value_type> {};
1663  } // namespace meta_detail
1664 
1665 #if defined(_MSC_VER) && _MSC_VER <= 1910
1666  template <typename T, typename U = T>
1667  using supports_op_less = decltype(meta_detail::supports_op_less_test(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
1668  template <typename T, typename U = T>
1669  using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
1670  template <typename T, typename U = T>
1671  using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
1672  template <typename T, typename U = std::ostream>
1673  using supports_ostream_op = decltype(meta_detail::supports_ostream_op(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
1674  template <typename T>
1675  using supports_adl_to_string = decltype(meta_detail::supports_adl_to_string(std::ref(std::declval<T&>())));
1676 #else
1677  template <typename T, typename U = T>
1678  using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval<T&>(), std::declval<U&>()));
1679  template <typename T, typename U = T>
1680  using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval<T&>(), std::declval<U&>()));
1681  template <typename T, typename U = T>
1682  using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval<T&>(), std::declval<U&>()));
1683  template <typename T, typename U = std::ostream>
1684  using supports_ostream_op = decltype(meta_detail::supports_ostream_op(std::declval<T&>(), std::declval<U&>()));
1685  template <typename T>
1686  using supports_adl_to_string = decltype(meta_detail::supports_adl_to_string(std::declval<T&>()));
1687 #endif
1688  template <typename T>
1689  using supports_to_string_member = meta::boolean<meta_detail::has_to_string_test<T>::value>;
1690 
1691  template <typename T>
1692  struct is_callable : boolean<meta_detail::is_callable<T>::value> {};
1693 
1694  template <typename T>
1695  struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test<T>(0)) {};
1696 
1697  template <typename T>
1698  struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test<T>(0)) {};
1699 
1700  template <typename T>
1701  struct has_key_type : decltype(meta_detail::has_key_type_impl::test<T>(0)) {};
1702 
1703  template <typename T>
1704  struct has_mapped_type : decltype(meta_detail::has_mapped_type_impl::test<T>(0)) {};
1705 
1706  template <typename T>
1707  struct has_iterator : decltype(meta_detail::has_iterator_impl::test<T>(0)) {};
1708 
1709  template <typename T>
1710  struct has_value_type : decltype(meta_detail::has_value_type_impl::test<T>(0)) {};
1711 
1712  template <typename T>
1713  using has_push_back = meta::boolean<meta_detail::has_push_back_test<T>::value>;
1714 
1715  template <typename T>
1716  using has_max_size = meta::boolean<meta_detail::has_max_size_test<T>::value>;
1717 
1718  template <typename T>
1719  using has_insert = meta::boolean<meta_detail::has_insert_test<T>::value>;
1720 
1721  template <typename T>
1722  using has_insert_after = meta::boolean<meta_detail::has_insert_after_test<T>::value>;
1723 
1724  template <typename T>
1725  using has_size = meta::boolean<meta_detail::has_size_test<T>::value || meta_detail::has_size_test<const T>::value>;
1726 
1727  template <typename T>
1728  struct is_associative : meta::all<has_key_type<T>, has_key_value_pair<T>, has_mapped_type<T>> {};
1729 
1730  template <typename T>
1731  struct is_lookup : meta::all<has_key_type<T>, has_value_type<T>> {};
1732 
1733  template <typename T>
1734  struct is_matched_lookup : meta_detail::is_matched_lookup_impl<T, is_lookup<T>::value> {};
1735 
1736  template <typename T>
1737  using is_string_like = any<
1738  is_specialization_of<meta::unqualified_t<T>, std::basic_string>,
1739 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
1740  is_specialization_of<meta::unqualified_t<T>, std::basic_string_view>,
1741 #else
1742  is_specialization_of<meta::unqualified_t<T>, basic_string_view>,
1743 #endif
1744  meta::all<std::is_array<unqualified_t<T>>, meta::any_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char, char16_t, char32_t, wchar_t>>
1745  >;
1746 
1747  template <typename T>
1748  using is_string_constructible = any<
1749  meta::all<std::is_array<unqualified_t<T>>, std::is_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char>>,
1750  std::is_same<unqualified_t<T>, const char*>,
1751  std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>>
1752 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
1753  , std::is_same<unqualified_t<T>, std::string_view>
1754 #endif
1755  >;
1756 
1757  template <typename T>
1758  struct is_pair : std::false_type {};
1759 
1760  template <typename T1, typename T2>
1761  struct is_pair<std::pair<T1, T2>> : std::true_type {};
1762 
1763  template <typename T>
1764  using is_c_str = any<
1765  std::is_same<std::decay_t<unqualified_t<T>>, const char*>,
1766  std::is_same<std::decay_t<unqualified_t<T>>, char*>,
1767  std::is_same<unqualified_t<T>, std::string>>;
1768 
1769  template <typename T>
1770  struct is_move_only : all<
1771  neg<std::is_reference<T>>,
1772  neg<std::is_copy_constructible<unqualified_t<T>>>,
1773  std::is_move_constructible<unqualified_t<T>>> {};
1774 
1775  template <typename T>
1776  using is_not_move_only = neg<is_move_only<T>>;
1777 
1778  namespace meta_detail {
1779  template <typename T, meta::disable<meta::is_specialization_of<meta::unqualified_t<T>, std::tuple>> = meta::enabler>
1780  decltype(auto) force_tuple(T&& x) {
1781  return std::tuple<std::decay_t<T>>(std::forward<T>(x));
1782  }
1783 
1784  template <typename T, meta::enable<meta::is_specialization_of<meta::unqualified_t<T>, std::tuple>> = meta::enabler>
1785  decltype(auto) force_tuple(T&& x) {
1786  return std::forward<T>(x);
1787  }
1788  } // namespace meta_detail
1789 
1790  template <typename... X>
1791  decltype(auto) tuplefy(X&&... x) {
1792  return std::tuple_cat(meta_detail::force_tuple(std::forward<X>(x))...);
1793  }
1794 
1795  template <typename T, typename = void>
1796  struct iterator_tag {
1797  using type = std::input_iterator_tag;
1798  };
1799 
1800  template <typename T>
1801  struct iterator_tag<T, std::conditional_t<false, typename T::iterator_category, void>> {
1802  using type = typename T::iterator_category;
1803  };
1804 
1805  } // namespace meta
1806 
1807  namespace detail {
1808  template <typename T>
1809  struct is_pointer_like : std::is_pointer<T> {};
1810  template <typename T, typename D>
1811  struct is_pointer_like<std::unique_ptr<T, D>> : std::true_type {};
1812  template <typename T>
1813  struct is_pointer_like<std::shared_ptr<T>> : std::true_type {};
1814 
1815  template <std::size_t I, typename Tuple>
1816  decltype(auto) forward_get(Tuple&& tuple) {
1817  return std::forward<meta::tuple_element_t<I, Tuple>>(std::get<I>(tuple));
1818  }
1819 
1820  template <std::size_t... I, typename Tuple>
1821  auto forward_tuple_impl(std::index_sequence<I...>, Tuple&& tuple) -> decltype(std::tuple<decltype(forward_get<I>(tuple))...>(forward_get<I>(tuple)...)) {
1822  return std::tuple<decltype(forward_get<I>(tuple))...>(std::move(std::get<I>(tuple))...);
1823  }
1824 
1825  template <typename Tuple>
1826  auto forward_tuple(Tuple&& tuple) {
1827  auto x = forward_tuple_impl(std::make_index_sequence<std::tuple_size<meta::unqualified_t<Tuple>>::value>(), std::forward<Tuple>(tuple));
1828  return x;
1829  }
1830 
1831  template <typename T>
1832  auto unwrap(T&& item) -> decltype(std::forward<T>(item)) {
1833  return std::forward<T>(item);
1834  }
1835 
1836  template <typename T>
1837  T& unwrap(std::reference_wrapper<T> arg) {
1838  return arg.get();
1839  }
1840 
1841  template <typename T, meta::enable<meta::neg<is_pointer_like<meta::unqualified_t<T>>>> = meta::enabler>
1842  auto deref(T&& item) -> decltype(std::forward<T>(item)) {
1843  return std::forward<T>(item);
1844  }
1845 
1846  template <typename T, meta::enable<is_pointer_like<meta::unqualified_t<T>>> = meta::enabler>
1847  inline auto deref(T&& item) -> decltype(*std::forward<T>(item)) {
1848  return *std::forward<T>(item);
1849  }
1850 
1851  template <typename T, meta::disable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
1852  auto deref_non_pointer(T&& item) -> decltype(std::forward<T>(item)) {
1853  return std::forward<T>(item);
1854  }
1855 
1856  template <typename T, meta::enable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
1857  inline auto deref_non_pointer(T&& item) -> decltype(*std::forward<T>(item)) {
1858  return *std::forward<T>(item);
1859  }
1860 
1861  template <typename T>
1862  inline T* ptr(T& val) {
1863  return std::addressof(val);
1864  }
1865 
1866  template <typename T>
1867  inline T* ptr(std::reference_wrapper<T> val) {
1868  return std::addressof(val.get());
1869  }
1870 
1871  template <typename T>
1872  inline T* ptr(T* val) {
1873  return val;
1874  }
1875  } // namespace detail
1876 } // namespace sol
1877 
1878 // end of sol/traits.hpp
1879 
1880 // beginning of sol/function.hpp
1881 
1882 // beginning of sol/stack.hpp
1883 
1884 // beginning of sol/trampoline.hpp
1885 
1886 // beginning of sol/types.hpp
1887 
1888 // beginning of sol/optional.hpp
1889 
1890 // beginning of sol/compatibility.hpp
1891 
1892 // beginning of sol/compatibility/version.hpp
1893 
1894 #if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA
1895 #include <lua.h>
1896 #include <lualib.h>
1897 #include <lauxlib.h>
1898 #if defined(SOL_USING_CXX_LUAJIT) && SOL_USING_CXX_LUAJIT
1899 #include <luajit.h>
1900 #endif // C++ LuaJIT ... whatever that means
1901 #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)) && (!defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) || !(SOL_EXCEPTIONS_ALWAYS_UNSAFE))
1902 #define SOL_EXCEPTIONS_SAFE_PROPAGATION 1
1903 #endif // Exceptions can be propagated safely using C++-compiled Lua
1904 #else
1905 #include <lua.hpp>
1906 #endif // C++ Mangling for Lua
1907 
1908 #ifdef LUAJIT_VERSION
1909 #ifndef SOL_LUAJIT
1910 #define SOL_LUAJIT 1
1911 #ifndef SOL_LUAJIT_VERSION
1912 #define SOL_LUAJIT_VERSION LUAJIT_VERSION_NUM
1913 #endif // SOL_LUAJIT_VERSION definition, if not present
1914 #endif // sol luajit
1915 #endif // luajit
1916 
1917 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502
1918 #define SOL_LUA_VERSION LUA_VERSION_NUM
1919 #elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
1920 #define SOL_LUA_VERSION LUA_VERSION_NUM
1921 #elif !defined(LUA_VERSION_NUM) || !(LUA_VERSION_NUM)
1922 #define SOL_LUA_VERSION 500
1923 #else
1924 #define SOL_LUA_VERSION 502
1925 #endif // Lua Version 502, 501 || luajit, 500
1926 
1927 // end of sol/compatibility/version.hpp
1928 
1929 #if !defined(SOL_NO_COMPAT) || !(SOL_NO_COMPAT)
1930 
1931 #if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA
1932 #ifndef COMPAT53_LUA_CPP
1933 #define COMPAT53_LUA_CPP 1
1934 #endif // Build Lua Compat layer as C++
1935 #endif
1936 #ifndef COMPAT53_INCLUDE_SOURCE
1937 #define COMPAT53_INCLUDE_SOURCE 1
1938 #endif // Build Compat Layer Inline
1939 // beginning of sol/compatibility/compat-5.3.h
1940 
1941 #ifndef KEPLER_PROJECT_COMPAT53_H_
1942 #define KEPLER_PROJECT_COMPAT53_H_
1943 
1944 #include <stddef.h>
1945 #include <limits.h>
1946 #include <string.h>
1947 #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP)
1948 extern "C" {
1949 #endif
1950 #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP)
1951 }
1952 #endif
1953 
1954 #ifndef COMPAT53_PREFIX
1955 /* we chose this name because many other lua bindings / libs have
1956 * their own compatibility layer, and that use the compat53 declaration
1957 * frequently, causing all kinds of linker / compiler issues
1958 */
1959 # define COMPAT53_PREFIX kp_compat53
1960 #endif // COMPAT53_PREFIX
1961 
1962 #ifndef COMPAT53_API
1963 # if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE
1964 # if defined(__GNUC__) || defined(__clang__)
1965 # define COMPAT53_API __attribute__((__unused__)) static
1966 # else
1967 # define COMPAT53_API static
1968 # endif /* Clang/GCC */
1969 # else /* COMPAT53_INCLUDE_SOURCE */
1970 /* we are not including source, so everything is extern */
1971 # define COMPAT53_API extern
1972 # endif /* COMPAT53_INCLUDE_SOURCE */
1973 #endif /* COMPAT53_PREFIX */
1974 
1975 #define COMPAT53_CONCAT_HELPER(a, b) a##b
1976 #define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b)
1977 
1978 /* declarations for Lua 5.1 */
1979 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
1980 
1981 /* XXX not implemented:
1982 * lua_arith (new operators)
1983 * lua_upvalueid
1984 * lua_upvaluejoin
1985 * lua_version
1986 * lua_yieldk
1987 */
1988 
1989 #ifndef LUA_OK
1990 # define LUA_OK 0
1991 #endif
1992 #ifndef LUA_OPADD
1993 # define LUA_OPADD 0
1994 #endif
1995 #ifndef LUA_OPSUB
1996 # define LUA_OPSUB 1
1997 #endif
1998 #ifndef LUA_OPMUL
1999 # define LUA_OPMUL 2
2000 #endif
2001 #ifndef LUA_OPDIV
2002 # define LUA_OPDIV 3
2003 #endif
2004 #ifndef LUA_OPMOD
2005 # define LUA_OPMOD 4
2006 #endif
2007 #ifndef LUA_OPPOW
2008 # define LUA_OPPOW 5
2009 #endif
2010 #ifndef LUA_OPUNM
2011 # define LUA_OPUNM 6
2012 #endif
2013 #ifndef LUA_OPEQ
2014 # define LUA_OPEQ 0
2015 #endif
2016 #ifndef LUA_OPLT
2017 # define LUA_OPLT 1
2018 #endif
2019 #ifndef LUA_OPLE
2020 # define LUA_OPLE 2
2021 #endif
2022 
2023 /* LuaJIT/Lua 5.1 does not have the updated
2024 * error codes for thread status/function returns (but some patched versions do)
2025 * define it only if it's not found
2026 */
2027 #if !defined(LUA_ERRGCMM)
2028 /* Use + 2 because in some versions of Lua (Lua 5.1)
2029 * LUA_ERRFILE is defined as (LUA_ERRERR+1)
2030 * so we need to avoid it (LuaJIT might have something at this
2031 * integer value too)
2032 */
2033 # define LUA_ERRGCMM (LUA_ERRERR + 2)
2034 #endif /* LUA_ERRGCMM define */
2035 
2036 typedef size_t lua_Unsigned;
2037 
2038 typedef struct luaL_Buffer_53 {
2039  luaL_Buffer b; /* make incorrect code crash! */
2040  char *ptr;
2041  size_t nelems;
2042  size_t capacity;
2043  lua_State *L2;
2044 } luaL_Buffer_53;
2045 #define luaL_Buffer luaL_Buffer_53
2046 
2047 /* In PUC-Rio 5.1, userdata is a simple FILE*
2048 * In LuaJIT, it's a struct where the first member is a FILE*
2049 * We can't support the `closef` member
2050 */
2051 typedef struct luaL_Stream {
2052  FILE *f;
2053 } luaL_Stream;
2054 
2055 #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex)
2056 COMPAT53_API int lua_absindex(lua_State *L, int i);
2057 
2058 #define lua_arith COMPAT53_CONCAT(COMPAT53_PREFIX, _arith)
2059 COMPAT53_API void lua_arith(lua_State *L, int op);
2060 
2061 #define lua_compare COMPAT53_CONCAT(COMPAT53_PREFIX, _compare)
2062 COMPAT53_API int lua_compare(lua_State *L, int idx1, int idx2, int op);
2063 
2064 #define lua_copy COMPAT53_CONCAT(COMPAT53_PREFIX, _copy)
2065 COMPAT53_API void lua_copy(lua_State *L, int from, int to);
2066 
2067 #define lua_getuservalue(L, i) \
2068  (lua_getfenv((L), (i)), lua_type((L), -1))
2069 #define lua_setuservalue(L, i) \
2070  (luaL_checktype((L), -1, LUA_TTABLE), lua_setfenv((L), (i)))
2071 
2072 #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len)
2073 COMPAT53_API void lua_len(lua_State *L, int i);
2074 
2075 #define lua_pushstring(L, s) \
2076  (lua_pushstring((L), (s)), lua_tostring((L), -1))
2077 
2078 #define lua_pushlstring(L, s, len) \
2079  ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1))
2080 
2081 #ifndef luaL_newlibtable
2082 # define luaL_newlibtable(L, l) \
2083  (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1))
2084 #endif
2085 #ifndef luaL_newlib
2086 # define luaL_newlib(L, l) \
2087  (luaL_newlibtable((L), (l)), luaL_register((L), NULL, (l)))
2088 #endif
2089 
2090 #define lua_pushglobaltable(L) \
2091  lua_pushvalue((L), LUA_GLOBALSINDEX)
2092 
2093 #define lua_rawgetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawgetp)
2094 COMPAT53_API int lua_rawgetp(lua_State *L, int i, const void *p);
2095 
2096 #define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp)
2097 COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p);
2098 
2099 #define lua_rawlen(L, i) lua_objlen((L), (i))
2100 
2101 #define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL)
2102 
2103 #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx)
2104 COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum);
2105 
2106 #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion)
2107 COMPAT53_API void luaL_checkversion(lua_State *L);
2108 
2109 #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53)
2110 COMPAT53_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode);
2111 
2112 #define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex)
2113 COMPAT53_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode);
2114 
2115 #define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx)
2116 COMPAT53_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode);
2117 
2118 #define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53)
2119 COMPAT53_API void luaL_checkstack(lua_State *L, int sp, const char *msg);
2120 
2121 #define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable)
2122 COMPAT53_API int luaL_getsubtable(lua_State* L, int i, const char *name);
2123 
2124 #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len)
2125 COMPAT53_API lua_Integer luaL_len(lua_State *L, int i);
2126 
2127 #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs)
2128 COMPAT53_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
2129 
2130 #define luaL_setmetatable COMPAT53_CONCAT(COMPAT53_PREFIX, L_setmetatable)
2131 COMPAT53_API void luaL_setmetatable(lua_State *L, const char *tname);
2132 
2133 #define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata)
2134 COMPAT53_API void *luaL_testudata(lua_State *L, int i, const char *tname);
2135 
2136 #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback)
2137 COMPAT53_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level);
2138 
2139 #define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult)
2140 COMPAT53_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
2141 
2142 #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult)
2143 COMPAT53_API int luaL_execresult(lua_State *L, int stat);
2144 
2145 #define lua_callk(L, na, nr, ctx, cont) \
2146  ((void)(ctx), (void)(cont), lua_call((L), (na), (nr)))
2147 #define lua_pcallk(L, na, nr, err, ctx, cont) \
2148  ((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err)))
2149 
2150 #define lua_resume(L, from, nargs) \
2151  ((void)(from), lua_resume((L), (nargs)))
2152 
2153 #define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53)
2154 COMPAT53_API void luaL_buffinit(lua_State *L, luaL_Buffer_53 *B);
2155 
2156 #define luaL_prepbuffsize COMPAT53_CONCAT(COMPAT53_PREFIX, _prepbufsize_53)
2157 COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s);
2158 
2159 #define luaL_addlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _addlstring_53)
2160 COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l);
2161 
2162 #define luaL_addvalue COMPAT53_CONCAT(COMPAT53_PREFIX, _addvalue_53)
2163 COMPAT53_API void luaL_addvalue(luaL_Buffer_53 *B);
2164 
2165 #define luaL_pushresult COMPAT53_CONCAT(COMPAT53_PREFIX, _pushresult_53)
2166 COMPAT53_API void luaL_pushresult(luaL_Buffer_53 *B);
2167 
2168 #undef luaL_buffinitsize
2169 #define luaL_buffinitsize(L, B, s) \
2170  (luaL_buffinit((L), (B)), luaL_prepbuffsize((B), (s)))
2171 
2172 #undef luaL_prepbuffer
2173 #define luaL_prepbuffer(B) \
2174  luaL_prepbuffsize((B), LUAL_BUFFERSIZE)
2175 
2176 #undef luaL_addchar
2177 #define luaL_addchar(B, c) \
2178  ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize((B), 1)), \
2179  ((B)->ptr[(B)->nelems++] = (c)))
2180 
2181 #undef luaL_addsize
2182 #define luaL_addsize(B, s) \
2183  ((B)->nelems += (s))
2184 
2185 #undef luaL_addstring
2186 #define luaL_addstring(B, s) \
2187  luaL_addlstring((B), (s), strlen((s)))
2188 
2189 #undef luaL_pushresultsize
2190 #define luaL_pushresultsize(B, s) \
2191  (luaL_addsize((B), (s)), luaL_pushresult((B)))
2192 
2193 #if defined(LUA_COMPAT_APIINTCASTS)
2194 #define lua_pushunsigned(L, n) \
2195  lua_pushinteger((L), (lua_Integer)(n))
2196 #define lua_tounsignedx(L, i, is) \
2197  ((lua_Unsigned)lua_tointegerx((L), (i), (is)))
2198 #define lua_tounsigned(L, i) \
2199  lua_tounsignedx((L), (i), NULL)
2200 #define luaL_checkunsigned(L, a) \
2201  ((lua_Unsigned)luaL_checkinteger((L), (a)))
2202 #define luaL_optunsigned(L, a, d) \
2203  ((lua_Unsigned)luaL_optinteger((L), (a), (lua_Integer)(d)))
2204 #endif
2205 
2206 #endif /* Lua 5.1 only */
2207 
2208 /* declarations for Lua 5.1 and 5.2 */
2209 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502
2210 
2211 typedef int lua_KContext;
2212 
2213 typedef int(*lua_KFunction)(lua_State *L, int status, lua_KContext ctx);
2214 
2215 #define lua_dump(L, w, d, s) \
2216  ((void)(s), lua_dump((L), (w), (d)))
2217 
2218 #define lua_getfield(L, i, k) \
2219  (lua_getfield((L), (i), (k)), lua_type((L), -1))
2220 
2221 #define lua_gettable(L, i) \
2222  (lua_gettable((L), (i)), lua_type((L), -1))
2223 
2224 #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti)
2225 COMPAT53_API int lua_geti(lua_State *L, int index, lua_Integer i);
2226 
2227 #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger)
2228 COMPAT53_API int lua_isinteger(lua_State *L, int index);
2229 
2230 #define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53)
2231 COMPAT53_API lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum);
2232 
2233 #define lua_numbertointeger(n, p) \
2234  ((*(p) = (lua_Integer)(n)), 1)
2235 
2236 #define lua_rawget(L, i) \
2237  (lua_rawget((L), (i)), lua_type((L), -1))
2238 
2239 #define lua_rawgeti(L, i, n) \
2240  (lua_rawgeti((L), (i), (n)), lua_type((L), -1))
2241 
2242 #define lua_rotate COMPAT53_CONCAT(COMPAT53_PREFIX, _rotate)
2243 COMPAT53_API void lua_rotate(lua_State *L, int idx, int n);
2244 
2245 #define lua_seti COMPAT53_CONCAT(COMPAT53_PREFIX, _seti)
2246 COMPAT53_API void lua_seti(lua_State *L, int index, lua_Integer i);
2247 
2248 #define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber)
2249 COMPAT53_API size_t lua_stringtonumber(lua_State *L, const char *s);
2250 
2251 #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring)
2252 COMPAT53_API const char *luaL_tolstring(lua_State *L, int idx, size_t *len);
2253 
2254 #define luaL_getmetafield(L, o, e) \
2255  (luaL_getmetafield((L), (o), (e)) ? lua_type((L), -1) : LUA_TNIL)
2256 
2257 #define luaL_newmetatable(L, tn) \
2258  (luaL_newmetatable((L), (tn)) ? (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : 0)
2259 
2260 #define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53)
2261 COMPAT53_API void luaL_requiref(lua_State *L, const char *modname,
2262  lua_CFunction openf, int glb);
2263 
2264 #endif /* Lua 5.1 and Lua 5.2 */
2265 
2266 /* declarations for Lua 5.2 */
2267 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 502
2268 
2269 /* XXX not implemented:
2270 * lua_isyieldable
2271 * lua_getextraspace
2272 * lua_arith (new operators)
2273 * lua_pushfstring (new formats)
2274 */
2275 
2276 #define lua_getglobal(L, n) \
2277  (lua_getglobal((L), (n)), lua_type((L), -1))
2278 
2279 #define lua_getuservalue(L, i) \
2280  (lua_getuservalue((L), (i)), lua_type((L), -1))
2281 
2282 #define lua_pushlstring(L, s, len) \
2283  (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len)))
2284 
2285 #define lua_rawgetp(L, i, p) \
2286  (lua_rawgetp((L), (i), (p)), lua_type((L), -1))
2287 
2288 #define LUA_KFUNCTION(_name) \
2289  static int (_name)(lua_State *L, int status, lua_KContext ctx); \
2290  static int (_name ## _52)(lua_State *L) { \
2291  lua_KContext ctx; \
2292  int status = lua_getctx(L, &ctx); \
2293  return (_name)(L, status, ctx); \
2294  } \
2295  static int (_name)(lua_State *L, int status, lua_KContext ctx)
2296 
2297 #define lua_pcallk(L, na, nr, err, ctx, cont) \
2298  lua_pcallk((L), (na), (nr), (err), (ctx), cont ## _52)
2299 
2300 #define lua_callk(L, na, nr, ctx, cont) \
2301  lua_callk((L), (na), (nr), (ctx), cont ## _52)
2302 
2303 #define lua_yieldk(L, nr, ctx, cont) \
2304  lua_yieldk((L), (nr), (ctx), cont ## _52)
2305 
2306 #ifdef lua_call
2307 # undef lua_call
2308 # define lua_call(L, na, nr) \
2309  (lua_callk)((L), (na), (nr), 0, NULL)
2310 #endif
2311 
2312 #ifdef lua_pcall
2313 # undef lua_pcall
2314 # define lua_pcall(L, na, nr, err) \
2315  (lua_pcallk)((L), (na), (nr), (err), 0, NULL)
2316 #endif
2317 
2318 #ifdef lua_yield
2319 # undef lua_yield
2320 # define lua_yield(L, nr) \
2321  (lua_yieldk)((L), (nr), 0, NULL)
2322 #endif
2323 
2324 #endif /* Lua 5.2 only */
2325 
2326 /* other Lua versions */
2327 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 504
2328 
2329 # error "unsupported Lua version (i.e. not Lua 5.1, 5.2, or 5.3)"
2330 
2331 #endif /* other Lua versions except 5.1, 5.2, and 5.3 */
2332 
2333 /* helper macro for defining continuation functions (for every version
2334 * *except* Lua 5.2) */
2335 #ifndef LUA_KFUNCTION
2336 #define LUA_KFUNCTION(_name) \
2337  static int (_name)(lua_State *L, int status, lua_KContext ctx)
2338 #endif
2339 
2340 #if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE == 1
2341 // beginning of sol/compatibility/compat-5.3.c
2342 
2343 #include <stdlib.h>
2344 #include <ctype.h>
2345 #include <errno.h>
2346 #include <stdio.h>
2347 
2348 /* don't compile it again if it already is included via compat53.h */
2349 #ifndef KEPLER_PROJECT_COMPAT53_C_
2350 #define KEPLER_PROJECT_COMPAT53_C_
2351 
2352 /* definitions for Lua 5.1 only */
2353 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
2354 
2355 #ifndef COMPAT53_FOPEN_NO_LOCK
2356 # if defined(_MSC_VER)
2357 # define COMPAT53_FOPEN_NO_LOCK 1
2358 # else /* otherwise */
2359 # define COMPAT53_FOPEN_NO_LOCK 0
2360 # endif /* VC++ only so far */
2361 #endif /* No-lock fopen_s usage if possible */
2362 
2363 #if defined(_MSC_VER) && COMPAT53_FOPEN_NO_LOCK
2364 # include <share.h>
2365 #endif /* VC++ _fsopen for share-allowed file read */
2366 
2367 #ifndef COMPAT53_HAVE_STRERROR_R
2368 # if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) || \
2369  (!defined (__MINGW32__) && defined(__GNUC__) && (__GNUC__ < 6))
2370 # define COMPAT53_HAVE_STRERROR_R 1
2371 # else /* none of the defines matched: define to 0 */
2372 # define COMPAT53_HAVE_STRERROR_R 0
2373 # endif /* have strerror_r of some form */
2374 #endif /* strerror_r */
2375 
2376 #ifndef COMPAT53_HAVE_STRERROR_S
2377 # if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
2378  (defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__)
2379 # define COMPAT53_HAVE_STRERROR_S 1
2380 # else /* not VC++ or C11 */
2381 # define COMPAT53_HAVE_STRERROR_S 0
2382 # endif /* strerror_s from VC++ or C11 */
2383 #endif /* strerror_s */
2384 
2385 #ifndef COMPAT53_LUA_FILE_BUFFER_SIZE
2386 # define COMPAT53_LUA_FILE_BUFFER_SIZE 4096
2387 #endif /* Lua File Buffer Size */
2388 
2389 static char* compat53_strerror(int en, char* buff, size_t sz) {
2390 #if COMPAT53_HAVE_STRERROR_R
2391  /* use strerror_r here, because it's available on these specific platforms */
2392  if (sz > 0) {
2393  buff[0] = '\0';
2394  /* we don't care whether the GNU version or the XSI version is used: */
2395  if (strerror_r(en, buff, sz)) {
2396  /* Yes, we really DO want to ignore the return value!
2397  * GCC makes that extra hard, not even a (void) cast will do. */
2398  }
2399  if (buff[0] == '\0') {
2400  /* Buffer is unchanged, so we probably have called GNU strerror_r which
2401  * returned a static constant string. Chances are that strerror will
2402  * return the same static constant string and therefore be thread-safe. */
2403  return strerror(en);
2404  }
2405  }
2406  return buff; /* sz is 0 *or* strerror_r wrote into the buffer */
2407 #elif COMPAT53_HAVE_STRERROR_S
2408  /* for MSVC and other C11 implementations, use strerror_s since it's
2409  * provided by default by the libraries */
2410  strerror_s(buff, sz, en);
2411  return buff;
2412 #else
2413  /* fallback, but strerror is not guaranteed to be threadsafe due to modifying
2414  * errno itself and some impls not locking a static buffer for it ... but most
2415  * known systems have threadsafe errno: this might only change if the locale
2416  * is changed out from under someone while this function is being called */
2417  (void)buff;
2418  (void)sz;
2419  return strerror(en);
2420 #endif
2421 }
2422 
2423 COMPAT53_API int lua_absindex(lua_State *L, int i) {
2424  if (i < 0 && i > LUA_REGISTRYINDEX)
2425  i += lua_gettop(L) + 1;
2426  return i;
2427 }
2428 
2429 static void compat53_call_lua(lua_State *L, char const code[], size_t len,
2430  int nargs, int nret) {
2431  lua_rawgetp(L, LUA_REGISTRYINDEX, (void*)code);
2432  if (lua_type(L, -1) != LUA_TFUNCTION) {
2433  lua_pop(L, 1);
2434  if (luaL_loadbuffer(L, code, len, "=none"))
2435  lua_error(L);
2436  lua_pushvalue(L, -1);
2437  lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code);
2438  }
2439  lua_insert(L, -nargs - 1);
2440  lua_call(L, nargs, nret);
2441 }
2442 
2443 static const char compat53_arith_code[] =
2444 "local op,a,b=...\n"
2445 "if op==0 then return a+b\n"
2446 "elseif op==1 then return a-b\n"
2447 "elseif op==2 then return a*b\n"
2448 "elseif op==3 then return a/b\n"
2449 "elseif op==4 then return a%b\n"
2450 "elseif op==5 then return a^b\n"
2451 "elseif op==6 then return -a\n"
2452 "end\n";
2453 
2454 COMPAT53_API void lua_arith(lua_State *L, int op) {
2455  if (op < LUA_OPADD || op > LUA_OPUNM)
2456  luaL_error(L, "invalid 'op' argument for lua_arith");
2457  luaL_checkstack(L, 5, "not enough stack slots");
2458  if (op == LUA_OPUNM)
2459  lua_pushvalue(L, -1);
2460  lua_pushnumber(L, op);
2461  lua_insert(L, -3);
2462  compat53_call_lua(L, compat53_arith_code,
2463  sizeof(compat53_arith_code) - 1, 3, 1);
2464 }
2465 
2466 static const char compat53_compare_code[] =
2467 "local a,b=...\n"
2468 "return a<=b\n";
2469 
2470 COMPAT53_API int lua_compare(lua_State *L, int idx1, int idx2, int op) {
2471  int result = 0;
2472  switch (op) {
2473  case LUA_OPEQ:
2474  return lua_equal(L, idx1, idx2);
2475  case LUA_OPLT:
2476  return lua_lessthan(L, idx1, idx2);
2477  case LUA_OPLE:
2478  luaL_checkstack(L, 5, "not enough stack slots");
2479  idx1 = lua_absindex(L, idx1);
2480  idx2 = lua_absindex(L, idx2);
2481  lua_pushvalue(L, idx1);
2482  lua_pushvalue(L, idx2);
2483  compat53_call_lua(L, compat53_compare_code,
2484  sizeof(compat53_compare_code) - 1, 2, 1);
2485  result = lua_toboolean(L, -1);
2486  lua_pop(L, 1);
2487  return result;
2488  default:
2489  luaL_error(L, "invalid 'op' argument for lua_compare");
2490  }
2491  return 0;
2492 }
2493 
2494 COMPAT53_API void lua_copy(lua_State *L, int from, int to) {
2495  int abs_to = lua_absindex(L, to);
2496  luaL_checkstack(L, 1, "not enough stack slots");
2497  lua_pushvalue(L, from);
2498  lua_replace(L, abs_to);
2499 }
2500 
2501 COMPAT53_API void lua_len(lua_State *L, int i) {
2502  switch (lua_type(L, i)) {
2503  case LUA_TSTRING:
2504  lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
2505  break;
2506  case LUA_TTABLE:
2507  if (!luaL_callmeta(L, i, "__len"))
2508  lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
2509  break;
2510  case LUA_TUSERDATA:
2511  if (luaL_callmeta(L, i, "__len"))
2512  break;
2513  /* FALLTHROUGH */
2514  default:
2515  luaL_error(L, "attempt to get length of a %s value",
2516  lua_typename(L, lua_type(L, i)));
2517  }
2518 }
2519 
2520 COMPAT53_API int lua_rawgetp(lua_State *L, int i, const void *p) {
2521  int abs_i = lua_absindex(L, i);
2522  lua_pushlightuserdata(L, (void*)p);
2523  lua_rawget(L, abs_i);
2524  return lua_type(L, -1);
2525 }
2526 
2527 COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p) {
2528  int abs_i = lua_absindex(L, i);
2529  luaL_checkstack(L, 1, "not enough stack slots");
2530  lua_pushlightuserdata(L, (void*)p);
2531  lua_insert(L, -2);
2532  lua_rawset(L, abs_i);
2533 }
2534 
2535 COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) {
2536  lua_Number n = lua_tonumber(L, i);
2537  if (isnum != NULL) {
2538  *isnum = (n != 0 || lua_isnumber(L, i));
2539  }
2540  return n;
2541 }
2542 
2543 COMPAT53_API void luaL_checkversion(lua_State *L) {
2544  (void)L;
2545 }
2546 
2547 COMPAT53_API void luaL_checkstack(lua_State *L, int sp, const char *msg) {
2548  if (!lua_checkstack(L, sp + LUA_MINSTACK)) {
2549  if (msg != NULL)
2550  luaL_error(L, "stack overflow (%s)", msg);
2551  else {
2552  lua_pushliteral(L, "stack overflow");
2553  lua_error(L);
2554  }
2555  }
2556 }
2557 
2558 COMPAT53_API int luaL_getsubtable(lua_State *L, int i, const char *name) {
2559  int abs_i = lua_absindex(L, i);
2560  luaL_checkstack(L, 3, "not enough stack slots");
2561  lua_pushstring(L, name);
2562  lua_gettable(L, abs_i);
2563  if (lua_istable(L, -1))
2564  return 1;
2565  lua_pop(L, 1);
2566  lua_newtable(L);
2567  lua_pushstring(L, name);
2568  lua_pushvalue(L, -2);
2569  lua_settable(L, abs_i);
2570  return 0;
2571 }
2572 
2573 COMPAT53_API lua_Integer luaL_len(lua_State *L, int i) {
2574  lua_Integer res = 0;
2575  int isnum = 0;
2576  luaL_checkstack(L, 1, "not enough stack slots");
2577  lua_len(L, i);
2578  res = lua_tointegerx(L, -1, &isnum);
2579  lua_pop(L, 1);
2580  if (!isnum)
2581  luaL_error(L, "object length is not an integer");
2582  return res;
2583 }
2584 
2585 COMPAT53_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
2586  luaL_checkstack(L, nup + 1, "too many upvalues");
2587  for (; l->name != NULL; l++) { /* fill the table with given functions */
2588  int i;
2589  lua_pushstring(L, l->name);
2590  for (i = 0; i < nup; i++) /* copy upvalues to the top */
2591  lua_pushvalue(L, -(nup + 1));
2592  lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
2593  lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */
2594  }
2595  lua_pop(L, nup); /* remove upvalues */
2596 }
2597 
2598 COMPAT53_API void luaL_setmetatable(lua_State *L, const char *tname) {
2599  luaL_checkstack(L, 1, "not enough stack slots");
2600  luaL_getmetatable(L, tname);
2601  lua_setmetatable(L, -2);
2602 }
2603 
2604 COMPAT53_API void *luaL_testudata(lua_State *L, int i, const char *tname) {
2605  void *p = lua_touserdata(L, i);
2606  luaL_checkstack(L, 2, "not enough stack slots");
2607  if (p == NULL || !lua_getmetatable(L, i))
2608  return NULL;
2609  else {
2610  int res = 0;
2611  luaL_getmetatable(L, tname);
2612  res = lua_rawequal(L, -1, -2);
2613  lua_pop(L, 2);
2614  if (!res)
2615  p = NULL;
2616  }
2617  return p;
2618 }
2619 
2620 static int compat53_countlevels(lua_State *L) {
2621  lua_Debug ar;
2622  int li = 1, le = 1;
2623  /* find an upper bound */
2624  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
2625  /* do a binary search */
2626  while (li < le) {
2627  int m = (li + le) / 2;
2628  if (lua_getstack(L, m, &ar)) li = m + 1;
2629  else le = m;
2630  }
2631  return le - 1;
2632 }
2633 
2634 static int compat53_findfield(lua_State *L, int objidx, int level) {
2635  if (level == 0 || !lua_istable(L, -1))
2636  return 0; /* not found */
2637  lua_pushnil(L); /* start 'next' loop */
2638  while (lua_next(L, -2)) { /* for each pair in table */
2639  if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
2640  if (lua_rawequal(L, objidx, -1)) { /* found object? */
2641  lua_pop(L, 1); /* remove value (but keep name) */
2642  return 1;
2643  }
2644  else if (compat53_findfield(L, objidx, level - 1)) { /* try recursively */
2645  lua_remove(L, -2); /* remove table (but keep name) */
2646  lua_pushliteral(L, ".");
2647  lua_insert(L, -2); /* place '.' between the two names */
2648  lua_concat(L, 3);
2649  return 1;
2650  }
2651  }
2652  lua_pop(L, 1); /* remove value */
2653  }
2654  return 0; /* not found */
2655 }
2656 
2657 static int compat53_pushglobalfuncname(lua_State *L, lua_Debug *ar) {
2658  int top = lua_gettop(L);
2659  lua_getinfo(L, "f", ar); /* push function */
2660  lua_pushvalue(L, LUA_GLOBALSINDEX);
2661  if (compat53_findfield(L, top + 1, 2)) {
2662  lua_copy(L, -1, top + 1); /* move name to proper place */
2663  lua_pop(L, 2); /* remove pushed values */
2664  return 1;
2665  }
2666  else {
2667  lua_settop(L, top); /* remove function and global table */
2668  return 0;
2669  }
2670 }
2671 
2672 static void compat53_pushfuncname(lua_State *L, lua_Debug *ar) {
2673  if (*ar->namewhat != '\0') /* is there a name? */
2674  lua_pushfstring(L, "function " LUA_QS, ar->name);
2675  else if (*ar->what == 'm') /* main? */
2676  lua_pushliteral(L, "main chunk");
2677  else if (*ar->what == 'C') {
2678  if (compat53_pushglobalfuncname(L, ar)) {
2679  lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
2680  lua_remove(L, -2); /* remove name */
2681  }
2682  else
2683  lua_pushliteral(L, "?");
2684  }
2685  else
2686  lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
2687 }
2688 
2689 #define COMPAT53_LEVELS1 12 /* size of the first part of the stack */
2690 #define COMPAT53_LEVELS2 10 /* size of the second part of the stack */
2691 
2692 COMPAT53_API void luaL_traceback(lua_State *L, lua_State *L1,
2693  const char *msg, int level) {
2694  lua_Debug ar;
2695  int top = lua_gettop(L);
2696  int numlevels = compat53_countlevels(L1);
2697  int mark = (numlevels > COMPAT53_LEVELS1 + COMPAT53_LEVELS2) ? COMPAT53_LEVELS1 : 0;
2698  if (msg) lua_pushfstring(L, "%s\n", msg);
2699  lua_pushliteral(L, "stack traceback:");
2700  while (lua_getstack(L1, level++, &ar)) {
2701  if (level == mark) { /* too many levels? */
2702  lua_pushliteral(L, "\n\t..."); /* add a '...' */
2703  level = numlevels - COMPAT53_LEVELS2; /* and skip to last ones */
2704  }
2705  else {
2706  lua_getinfo(L1, "Slnt", &ar);
2707  lua_pushfstring(L, "\n\t%s:", ar.short_src);
2708  if (ar.currentline > 0)
2709  lua_pushfstring(L, "%d:", ar.currentline);
2710  lua_pushliteral(L, " in ");
2711  compat53_pushfuncname(L, &ar);
2712  lua_concat(L, lua_gettop(L) - top);
2713  }
2714  }
2715  lua_concat(L, lua_gettop(L) - top);
2716 }
2717 
2718 COMPAT53_API int luaL_fileresult(lua_State *L, int stat, const char *fname) {
2719  const char *serr = NULL;
2720  int en = errno; /* calls to Lua API may change this value */
2721  char buf[512] = { 0 };
2722  if (stat) {
2723  lua_pushboolean(L, 1);
2724  return 1;
2725  }
2726  else {
2727  lua_pushnil(L);
2728  serr = compat53_strerror(en, buf, sizeof(buf));
2729  if (fname)
2730  lua_pushfstring(L, "%s: %s", fname, serr);
2731  else
2732  lua_pushstring(L, serr);
2733  lua_pushnumber(L, (lua_Number)en);
2734  return 3;
2735  }
2736 }
2737 
2738 static int compat53_checkmode(lua_State *L, const char *mode, const char *modename, int err) {
2739  if (mode && strchr(mode, modename[0]) == NULL) {
2740  lua_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", modename, mode);
2741  return err;
2742  }
2743  return LUA_OK;
2744 }
2745 
2746 typedef struct {
2747  lua_Reader reader;
2748  void *ud;
2749  int has_peeked_data;
2750  const char *peeked_data;
2751  size_t peeked_data_size;
2752 } compat53_reader_data;
2753 
2754 static const char *compat53_reader(lua_State *L, void *ud, size_t *size) {
2755  compat53_reader_data *data = (compat53_reader_data *)ud;
2756  if (data->has_peeked_data) {
2757  data->has_peeked_data = 0;
2758  *size = data->peeked_data_size;
2759  return data->peeked_data;
2760  }
2761  else
2762  return data->reader(L, data->ud, size);
2763 }
2764 
2765 COMPAT53_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) {
2766  int status = LUA_OK;
2767  compat53_reader_data compat53_data = { reader, data, 1, 0, 0 };
2768  compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size));
2769  if (compat53_data.peeked_data && compat53_data.peeked_data_size &&
2770  compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */
2771  status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX);
2772  else
2773  status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX);
2774  if (status != LUA_OK)
2775  return status;
2776  /* we need to call the original 5.1 version of lua_load! */
2777 #undef lua_load
2778  return lua_load(L, compat53_reader, &compat53_data, source);
2779 #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53)
2780 }
2781 
2782 typedef struct {
2783  int n; /* number of pre-read characters */
2784  FILE *f; /* file being read */
2785  char buff[COMPAT53_LUA_FILE_BUFFER_SIZE]; /* area for reading file */
2786 } compat53_LoadF;
2787 
2788 static const char *compat53_getF(lua_State *L, void *ud, size_t *size) {
2789  compat53_LoadF *lf = (compat53_LoadF *)ud;
2790  (void)L; /* not used */
2791  if (lf->n > 0) { /* are there pre-read characters to be read? */
2792  *size = lf->n; /* return them (chars already in buffer) */
2793  lf->n = 0; /* no more pre-read characters */
2794  }
2795  else { /* read a block from file */
2796  /* 'fread' can return > 0 *and* set the EOF flag. If next call to
2797  'compat53_getF' called 'fread', it might still wait for user input.
2798  The next check avoids this problem. */
2799  if (feof(lf->f)) return NULL;
2800  *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
2801  }
2802  return lf->buff;
2803 }
2804 
2805 static int compat53_errfile(lua_State *L, const char *what, int fnameindex) {
2806  char buf[512] = { 0 };
2807  const char *serr = compat53_strerror(errno, buf, sizeof(buf));
2808  const char *filename = lua_tostring(L, fnameindex) + 1;
2809  lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
2810  lua_remove(L, fnameindex);
2811  return LUA_ERRFILE;
2812 }
2813 
2814 static int compat53_skipBOM(compat53_LoadF *lf) {
2815  const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
2816  int c;
2817  lf->n = 0;
2818  do {
2819  c = getc(lf->f);
2820  if (c == EOF || c != *(const unsigned char *)p++) return c;
2821  lf->buff[lf->n++] = (char)c; /* to be read by the parser */
2822  } while (*p != '\0');
2823  lf->n = 0; /* prefix matched; discard it */
2824  return getc(lf->f); /* return next character */
2825 }
2826 
2827 /*
2828 ** reads the first character of file 'f' and skips an optional BOM mark
2829 ** in its beginning plus its first line if it starts with '#'. Returns
2830 ** true if it skipped the first line. In any case, '*cp' has the
2831 ** first "valid" character of the file (after the optional BOM and
2832 ** a first-line comment).
2833 */
2834 static int compat53_skipcomment(compat53_LoadF *lf, int *cp) {
2835  int c = *cp = compat53_skipBOM(lf);
2836  if (c == '#') { /* first line is a comment (Unix exec. file)? */
2837  do { /* skip first line */
2838  c = getc(lf->f);
2839  } while (c != EOF && c != '\n');
2840  *cp = getc(lf->f); /* skip end-of-line, if present */
2841  return 1; /* there was a comment */
2842  }
2843  else return 0; /* no comment */
2844 }
2845 
2846 COMPAT53_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode) {
2847  compat53_LoadF lf;
2848  int status, readstatus;
2849  int c;
2850  int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
2851  if (filename == NULL) {
2852  lua_pushliteral(L, "=stdin");
2853  lf.f = stdin;
2854  }
2855  else {
2856  lua_pushfstring(L, "@%s", filename);
2857 #if defined(_MSC_VER)
2858  /* This code is here to stop a deprecation error that stops builds
2859  * if a certain macro is defined. While normally not caring would
2860  * be best, some header-only libraries and builds can't afford to
2861  * dictate this to the user. A quick check shows that fopen_s this
2862  * goes back to VS 2005, and _fsopen goes back to VS 2003 .NET,
2863  * possibly even before that so we don't need to do any version
2864  * number checks, since this has been there since forever. */
2865 
2866  /* TO USER: if you want the behavior of typical fopen_s/fopen,
2867  * which does lock the file on VC++, define the macro used below to 0 */
2868 #if COMPAT53_FOPEN_NO_LOCK
2869  lf.f = _fsopen(filename, "r", _SH_DENYNO); /* do not lock the file in any way */
2870  if (lf.f == NULL)
2871  return compat53_errfile(L, "open", fnameindex);
2872 #else /* use default locking version */
2873  if (fopen_s(&lf.f, filename, "r") != 0)
2874  return compat53_errfile(L, "open", fnameindex);
2875 #endif /* Locking vs. No-locking fopen variants */
2876 #else
2877  lf.f = fopen(filename, "r"); /* default stdlib doesn't forcefully lock files here */
2878  if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex);
2879 #endif
2880  }
2881  if (compat53_skipcomment(&lf, &c)) /* read initial portion */
2882  lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
2883  if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
2884 #if defined(_MSC_VER)
2885  if (freopen_s(&lf.f, filename, "rb", lf.f) != 0)
2886  return compat53_errfile(L, "reopen", fnameindex);
2887 #else
2888  lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
2889  if (lf.f == NULL) return compat53_errfile(L, "reopen", fnameindex);
2890 #endif
2891  compat53_skipcomment(&lf, &c); /* re-read initial portion */
2892  }
2893  if (c != EOF)
2894  lf.buff[lf.n++] = (char)c; /* 'c' is the first character of the stream */
2895  status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode);
2896  readstatus = ferror(lf.f);
2897  if (filename) fclose(lf.f); /* close file (even in case of errors) */
2898  if (readstatus) {
2899  lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
2900  return compat53_errfile(L, "read", fnameindex);
2901  }
2902  lua_remove(L, fnameindex);
2903  return status;
2904 }
2905 
2906 COMPAT53_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) {
2907  int status = LUA_OK;
2908  if (sz > 0 && buff[0] == LUA_SIGNATURE[0]) {
2909  status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX);
2910  }
2911  else {
2912  status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX);
2913  }
2914  if (status != LUA_OK)
2915  return status;
2916  return luaL_loadbuffer(L, buff, sz, name);
2917 }
2918 
2919 #if !defined(l_inspectstat) && \
2920  (defined(unix) || defined(__unix) || defined(__unix__) || \
2921  defined(__TOS_AIX__) || defined(_SYSTYPE_BSD) || \
2922  (defined(__APPLE__) && defined(__MACH__)))
2923 /* some form of unix; check feature macros in unistd.h for details */
2924 # include <unistd.h>
2925 /* check posix version; the relevant include files and macros probably
2926 * were available before 2001, but I'm not sure */
2927 # if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
2928 # include <sys/wait.h>
2929 # define l_inspectstat(stat,what) \
2930  if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \
2931  else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; }
2932 # endif
2933 #endif
2934 
2935 /* provide default (no-op) version */
2936 #if !defined(l_inspectstat)
2937 # define l_inspectstat(stat,what) ((void)0)
2938 #endif
2939 
2940 COMPAT53_API int luaL_execresult(lua_State *L, int stat) {
2941  const char *what = "exit";
2942  if (stat == -1)
2943  return luaL_fileresult(L, 0, NULL);
2944  else {
2945  l_inspectstat(stat, what);
2946  if (*what == 'e' && stat == 0)
2947  lua_pushboolean(L, 1);
2948  else
2949  lua_pushnil(L);
2950  lua_pushstring(L, what);
2951  lua_pushinteger(L, stat);
2952  return 3;
2953  }
2954 }
2955 
2956 COMPAT53_API void luaL_buffinit(lua_State *L, luaL_Buffer_53 *B) {
2957  /* make it crash if used via pointer to a 5.1-style luaL_Buffer */
2958  B->b.p = NULL;
2959  B->b.L = NULL;
2960  B->b.lvl = 0;
2961  /* reuse the buffer from the 5.1-style luaL_Buffer though! */
2962  B->ptr = B->b.buffer;
2963  B->capacity = LUAL_BUFFERSIZE;
2964  B->nelems = 0;
2965  B->L2 = L;
2966 }
2967 
2968 COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s) {
2969  if (B->capacity - B->nelems < s) { /* needs to grow */
2970  char* newptr = NULL;
2971  size_t newcap = B->capacity * 2;
2972  if (newcap - B->nelems < s)
2973  newcap = B->nelems + s;
2974  if (newcap < B->capacity) /* overflow */
2975  luaL_error(B->L2, "buffer too large");
2976  newptr = (char*)lua_newuserdata(B->L2, newcap);
2977  memcpy(newptr, B->ptr, B->nelems);
2978  if (B->ptr != B->b.buffer)
2979  lua_replace(B->L2, -2); /* remove old buffer */
2980  B->ptr = newptr;
2981  B->capacity = newcap;
2982  }
2983  return B->ptr + B->nelems;
2984 }
2985 
2986 COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l) {
2987  memcpy(luaL_prepbuffsize(B, l), s, l);
2988  luaL_addsize(B, l);
2989 }
2990 
2991 COMPAT53_API void luaL_addvalue(luaL_Buffer_53 *B) {
2992  size_t len = 0;
2993  const char *s = lua_tolstring(B->L2, -1, &len);
2994  if (!s)
2995  luaL_error(B->L2, "cannot convert value to string");
2996  if (B->ptr != B->b.buffer)
2997  lua_insert(B->L2, -2); /* userdata buffer must be at stack top */
2998  luaL_addlstring(B, s, len);
2999  lua_remove(B->L2, B->ptr != B->b.buffer ? -2 : -1);
3000 }
3001 
3002 void luaL_pushresult(luaL_Buffer_53 *B) {
3003  lua_pushlstring(B->L2, B->ptr, B->nelems);
3004  if (B->ptr != B->b.buffer)
3005  lua_replace(B->L2, -2); /* remove userdata buffer */
3006 }
3007 
3008 #endif /* Lua 5.1 */
3009 
3010 /* definitions for Lua 5.1 and Lua 5.2 */
3011 #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502
3012 
3013 COMPAT53_API int lua_geti(lua_State *L, int index, lua_Integer i) {
3014  index = lua_absindex(L, index);
3015  lua_pushinteger(L, i);
3016  lua_gettable(L, index);
3017  return lua_type(L, -1);
3018 }
3019 
3020 COMPAT53_API int lua_isinteger(lua_State *L, int index) {
3021  if (lua_type(L, index) == LUA_TNUMBER) {
3022  lua_Number n = lua_tonumber(L, index);
3023  lua_Integer i = lua_tointeger(L, index);
3024  if (i == n)
3025  return 1;
3026  }
3027  return 0;
3028 }
3029 
3030 COMPAT53_API lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) {
3031  int ok = 0;
3032  lua_Number n = lua_tonumberx(L, i, &ok);
3033  if (ok) {
3034  if (n == (lua_Integer)n) {
3035  if (isnum)
3036  *isnum = 1;
3037  return (lua_Integer)n;
3038  }
3039  }
3040  if (isnum)
3041  *isnum = 0;
3042  return 0;
3043 }
3044 
3045 static void compat53_reverse(lua_State *L, int a, int b) {
3046  for (; a < b; ++a, --b) {
3047  lua_pushvalue(L, a);
3048  lua_pushvalue(L, b);
3049  lua_replace(L, a);
3050  lua_replace(L, b);
3051  }
3052 }
3053 
3054 COMPAT53_API void lua_rotate(lua_State *L, int idx, int n) {
3055  int n_elems = 0;
3056  idx = lua_absindex(L, idx);
3057  n_elems = lua_gettop(L) - idx + 1;
3058  if (n < 0)
3059  n += n_elems;
3060  if (n > 0 && n < n_elems) {
3061  luaL_checkstack(L, 2, "not enough stack slots available");
3062  n = n_elems - n;
3063  compat53_reverse(L, idx, idx + n - 1);
3064  compat53_reverse(L, idx + n, idx + n_elems - 1);
3065  compat53_reverse(L, idx, idx + n_elems - 1);
3066  }
3067 }
3068 
3069 COMPAT53_API void lua_seti(lua_State *L, int index, lua_Integer i) {
3070  luaL_checkstack(L, 1, "not enough stack slots available");
3071  index = lua_absindex(L, index);
3072  lua_pushinteger(L, i);
3073  lua_insert(L, -2);
3074  lua_settable(L, index);
3075 }
3076 
3077 #if !defined(lua_str2number)
3078 # define lua_str2number(s, p) strtod((s), (p))
3079 #endif
3080 
3081 COMPAT53_API size_t lua_stringtonumber(lua_State *L, const char *s) {
3082  char* endptr;
3083  lua_Number n = lua_str2number(s, &endptr);
3084  if (endptr != s) {
3085  while (*endptr != '\0' && isspace((unsigned char)*endptr))
3086  ++endptr;
3087  if (*endptr == '\0') {
3088  lua_pushnumber(L, n);
3089  return endptr - s + 1;
3090  }
3091  }
3092  return 0;
3093 }
3094 
3095 COMPAT53_API const char *luaL_tolstring(lua_State *L, int idx, size_t *len) {
3096  if (!luaL_callmeta(L, idx, "__tostring")) {
3097  int t = lua_type(L, idx), tt = 0;
3098  char const* name = NULL;
3099  switch (t) {
3100  case LUA_TNIL:
3101  lua_pushliteral(L, "nil");
3102  break;
3103  case LUA_TSTRING:
3104  case LUA_TNUMBER:
3105  lua_pushvalue(L, idx);
3106  break;
3107  case LUA_TBOOLEAN:
3108  if (lua_toboolean(L, idx))
3109  lua_pushliteral(L, "true");
3110  else
3111  lua_pushliteral(L, "false");
3112  break;
3113  default:
3114  tt = luaL_getmetafield(L, idx, "__name");
3115  name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t);
3116  lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx));
3117  if (tt != LUA_TNIL)
3118  lua_replace(L, -2);
3119  break;
3120  }
3121  }
3122  else {
3123  if (!lua_isstring(L, -1))
3124  luaL_error(L, "'__tostring' must return a string");
3125  }
3126  return lua_tolstring(L, -1, len);
3127 }
3128 
3129 COMPAT53_API void luaL_requiref(lua_State *L, const char *modname,
3130  lua_CFunction openf, int glb) {
3131  luaL_checkstack(L, 3, "not enough stack slots available");
3132  luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
3133  if (lua_getfield(L, -1, modname) == LUA_TNIL) {
3134  lua_pop(L, 1);
3135  lua_pushcfunction(L, openf);
3136  lua_pushstring(L, modname);
3137  lua_call(L, 1, 1);
3138  lua_pushvalue(L, -1);
3139  lua_setfield(L, -3, modname);
3140  }
3141  if (glb) {
3142  lua_pushvalue(L, -1);
3143  lua_setglobal(L, modname);
3144  }
3145  lua_replace(L, -2);
3146 }
3147 
3148 #endif /* Lua 5.1 and 5.2 */
3149 
3150 #endif /* KEPLER_PROJECT_COMPAT53_C_ */
3151 
3152 /*********************************************************************
3153 * This file contains parts of Lua 5.2's and Lua 5.3's source code:
3154 *
3155 * Copyright (C) 1994-2014 Lua.org, PUC-Rio.
3156 *
3157 * Permission is hereby granted, free of charge, to any person obtaining
3158 * a copy of this software and associated documentation files (the
3159 * "Software"), to deal in the Software without restriction, including
3160 * without limitation the rights to use, copy, modify, merge, publish,
3161 * distribute, sublicense, and/or sell copies of the Software, and to
3162 * permit persons to whom the Software is furnished to do so, subject to
3163 * the following conditions:
3164 *
3165 * The above copyright notice and this permission notice shall be
3166 * included in all copies or substantial portions of the Software.
3167 *
3168 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
3169 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3170 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
3171 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
3172 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
3173 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
3174 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3175 *********************************************************************/
3176 
3177 // end of sol/compatibility/compat-5.3.c
3178 
3179 #endif
3180 
3181 #endif /* KEPLER_PROJECT_COMPAT53_H_ */
3182 
3183 // end of sol/compatibility/compat-5.3.h
3184 
3185 
3186 #endif // SOL_NO_COMPAT
3187 
3188 // end of sol/compatibility.hpp
3189 
3190 // beginning of sol/in_place.hpp
3191 
3192 #include <utility>
3193 
3194 namespace sol {
3195 
3196 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
3197  using in_place_t = std::in_place_t;
3198  constexpr std::in_place_t in_place{};
3199  constexpr std::in_place_t in_place_of{};
3200 
3201  template <typename T>
3202  using in_place_type_t = std::in_place_type_t<T>;
3203  template <typename T>
3204  constexpr std::in_place_type_t<T> in_place_type{};
3205 
3206  template <size_t I>
3207  using in_place_index_t = std::in_place_index_t<I>;
3208  template <size_t I>
3209  constexpr in_place_index_t<I> in_place_index{};
3210 #else
3211  namespace detail {
3212  struct in_place_of_tag {};
3213  template <std::size_t I>
3214  struct in_place_of_i {};
3215  template <typename T>
3216  struct in_place_of_t {};
3217  } // namespace detail
3218 
3219  struct in_place_tag {
3220  constexpr in_place_tag() = default;
3221  };
3222 
3224  return in_place_tag();
3225  }
3226  template <typename T>
3228  return in_place_tag();
3229  }
3230  template <std::size_t I>
3232  return in_place_tag();
3233  }
3234 
3236  return in_place_tag();
3237  }
3238  template <typename T>
3240  return in_place_tag();
3241  }
3242  template <std::size_t I>
3244  return in_place_tag();
3245  }
3246 
3248  template <typename T>
3250  template <std::size_t I>
3251  using in_place_index_t = in_place_tag (&)(detail::in_place_of_i<I>);
3252 #endif
3253 
3254 } // namespace sol
3255 
3256 // end of sol/in_place.hpp
3257 
3258 #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
3259 #include <boost/optional.hpp>
3260 #else
3261 // beginning of sol/optional_implementation.hpp
3262 
3263 #include <initializer_list>
3264 #include <cassert>
3265 #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
3266 #include <cstdlib>
3267 #endif // Exceptions
3268 
3269 #define TR2_OPTIONAL_REQUIRES(...) typename ::std::enable_if<__VA_ARGS__::value, bool>::type = false
3270 
3271 #if defined __GNUC__ // NOTE: GNUC is also defined for Clang
3272 #if (__GNUC__ >= 5)
3273 #define TR2_OPTIONAL_GCC_5_0_AND_HIGHER___
3274 #define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
3275 #elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)
3276 #define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
3277 #elif (__GNUC__ > 4)
3278 #define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
3279 #endif
3280 #
3281 #if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)
3282 #define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
3283 #elif (__GNUC__ > 4)
3284 #define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
3285 #endif
3286 #
3287 #if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1)
3288 #define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
3289 #elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)
3290 #define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
3291 #elif (__GNUC__ > 4)
3292 #define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
3293 #endif
3294 #endif
3295 #
3296 #if defined __clang_major__
3297 #if (__clang_major__ == 3 && __clang_minor__ >= 5)
3298 #define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
3299 #elif (__clang_major__ > 3)
3300 #define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
3301 #endif
3302 #if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
3303 #define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
3304 #elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2)
3305 #define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
3306 #endif
3307 #endif
3308 #
3309 #if defined _MSC_VER
3310 #if (_MSC_VER >= 1900)
3311 #define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
3312 #endif
3313 #endif
3314 
3315 #if defined __clang__
3316 #if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9)
3317 #define OPTIONAL_HAS_THIS_RVALUE_REFS 1
3318 #else
3319 #define OPTIONAL_HAS_THIS_RVALUE_REFS 0
3320 #endif
3321 #elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
3322 #define OPTIONAL_HAS_THIS_RVALUE_REFS 1
3323 #elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
3324 #define OPTIONAL_HAS_THIS_RVALUE_REFS 1
3325 #else
3326 #define OPTIONAL_HAS_THIS_RVALUE_REFS 0
3327 #endif
3328 
3329 #if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
3330 #define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1
3331 #define OPTIONAL_CONSTEXPR_INIT_LIST constexpr
3332 #else
3333 #define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0
3334 #define OPTIONAL_CONSTEXPR_INIT_LIST
3335 #endif
3336 
3337 #if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || (defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L))
3338 #define OPTIONAL_HAS_MOVE_ACCESSORS 1
3339 #else
3340 #define OPTIONAL_HAS_MOVE_ACCESSORS 0
3341 #endif
3342 
3343 #// In C++11 constexpr implies const, so we need to make non-const members also non-constexpr
3344 #if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || ((defined __cplusplus) && (__cplusplus == 201103L))
3345 #define OPTIONAL_MUTABLE_CONSTEXPR
3346 #else
3347 #define OPTIONAL_MUTABLE_CONSTEXPR constexpr
3348 #endif
3349 
3350 #if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
3351 #pragma warning(push)
3352 #pragma warning(disable : 4814)
3353 #endif
3354 
3355 namespace sol {
3356 
3357  // BEGIN workaround for missing is_trivially_destructible
3358 #if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
3359  // leave it: it is already there
3360 #elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
3361  // leave it: it is already there
3362 #elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
3363  // leave it: it is already there
3364 #elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS
3365  // leave it: the user doesn't want it
3366 #else
3367  template <typename T>
3368  using is_trivially_destructible = ::std::has_trivial_destructor<T>;
3369 #endif
3370  // END workaround for missing is_trivially_destructible
3371 
3372 #if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___)
3373  // leave it; our metafunctions are already defined.
3374 #elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
3375  // leave it; our metafunctions are already defined.
3376 #elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
3377  // leave it: it is already there
3378 #elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS
3379  // leave it: the user doesn't want it
3380 #else
3381 
3382  // workaround for missing traits in GCC and CLANG
3383  template <class T>
3385  static constexprbool value = ::std::is_nothrow_constructible<T, T&&>::value;
3386  };
3387 
3388  template <class T, class U>
3389  struct is_assignable {
3390  template <class X, class Y>
3391  static constexprbool has_assign(...) {
3392  return false;
3393  }
3394 
3395  template <class X, class Y, size_t S = sizeof((::std::declval<X>() = ::std::declval<Y>(), true))>
3396  // the comma operator is necessary for the cases where operator= returns void
3397  static constexprbool has_assign(bool) {
3398  return true;
3399  }
3400 
3401  static constexprbool value = has_assign<T, U>(true);
3402  };
3403 
3404  template <class T>
3406  template <class X, bool has_any_move_assign>
3408  static constexprbool value = false;
3409  };
3410 
3411  template <class X>
3412  struct has_nothrow_move_assign<X, true> {
3413  static constexprbool value = noexcept(::std::declval<X&>() = ::std::declval<X&&>());
3414  };
3415 
3416  static constexprbool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value;
3417  };
3418  // end workaround
3419 
3420 #endif
3421 
3422  // 20.5.4, optional for object types
3423  template <class T>
3424  class optional;
3425 
3426  // 20.5.5, optional for lvalue reference types
3427  template <class T>
3428  class optional<T&>;
3429 
3430  // workaround: std utility functions aren't constexpr yet
3431  template <class T>
3433  return static_cast<T&&>(t);
3434  }
3435 
3436  template <class T>
3438  static_assert(!::std::is_lvalue_reference<T>::value, "!!");
3439  return static_cast<T&&>(t);
3440  }
3441 
3442  template <class T>
3443  inline constexpr typename ::std::remove_reference<T>::type&& constexpr_move(T&& t) noexcept {
3444  return static_cast<typename ::std::remove_reference<T>::type&&>(t);
3445  }
3446 
3447 #if defined NDEBUG
3448 #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
3449 #else
3450 #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([] { assert(!#CHECK); }(), (EXPR)))
3451 #endif
3452 
3453  namespace detail_ {
3454 
3455  // static_addressof: a constexpr version of addressof
3456  template <typename T>
3458  template <class X>
3459  static constexpr bool has_overload(...) {
3460  return false;
3461  }
3462 
3463  template <class X, size_t S = sizeof(::std::declval<X&>().operator&())>
3464  static constexpr bool has_overload(bool) {
3465  return true;
3466  }
3467 
3468  static constexpr bool value = has_overload<T>(true);
3469  };
3470 
3471  template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
3472  constexpr T* static_addressof(T& ref) {
3473  return &ref;
3474  }
3475 
3476  template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)>
3477  T* static_addressof(T& ref) {
3478  return ::std::addressof(ref);
3479  }
3480 
3481  // the call to convert<A>(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A
3482  template <class U>
3483  constexpr U convert(U v) {
3484  return v;
3485  }
3486 
3487  } // namespace detail_
3488 
3489  constexpr struct trivial_init_t {
3490  } trivial_init{};
3491 
3492  // 20.5.7, Disengaged state indicator
3493  struct nullopt_t {
3494  struct init {};
3495  constexpr explicit nullopt_t(init) {
3496  }
3497  };
3499 
3500  // 20.5.8, class bad_optional_access
3501  class bad_optional_access : public ::std::logic_error {
3502  public:
3503  explicit bad_optional_access(const ::std::string& what_arg)
3504  : ::std::logic_error{what_arg} {
3505  }
3506  explicit bad_optional_access(const char* what_arg)
3507  : ::std::logic_error{what_arg} {
3508  }
3509  };
3510 
3511  template <class T>
3512  struct alignas(T) optional_base {
3513  char storage_[sizeof(T)];
3514  bool init_;
3515 
3516  constexpr optional_base() noexcept
3517  : storage_(), init_(false){};
3518 
3519  explicit optional_base(const T& v)
3520  : storage_(), init_(true) {
3521  new (&storage()) T(v);
3522  }
3523 
3524  explicit optional_base(T&& v)
3525  : storage_(), init_(true) {
3526  new (&storage()) T(constexpr_move(v));
3527  }
3528 
3529  template <class... Args>
3530  explicit optional_base(in_place_t, Args&&... args)
3531  : init_(true), storage_() {
3532  new (&storage()) T(constexpr_forward<Args>(args)...);
3533  }
3534 
3535  template <class U, class... Args, TR2_OPTIONAL_REQUIRES(::std::is_constructible<T, ::std::initializer_list<U>>)>
3536  explicit optional_base(in_place_t, ::std::initializer_list<U> il, Args&&... args)
3537  : init_(true), storage_() {
3538  new (&storage()) T(il, constexpr_forward<Args>(args)...);
3539  }
3540 #if defined __GNUC__
3541 #pragma GCC diagnostic push
3542 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
3543 #endif
3544  T& storage() {
3545  return *reinterpret_cast<T*>(&storage_[0]);
3546  }
3547 
3548  constexpr const T& storage() const {
3549  return *reinterpret_cast<T const*>(&storage_[0]);
3550  }
3551 #if defined __GNUC__
3552 #pragma GCC diagnostic pop
3553 #endif
3554 
3556  if (init_) {
3557  storage().T::~T();
3558  }
3559  }
3560  };
3561 
3562 #if defined __GNUC__ && !defined TR2_OPTIONAL_GCC_5_0_AND_HIGHER___
3563  // Sorry, GCC 4.x; you're just a piece of shit
3564  template <typename T>
3566 #else
3567  template <class T>
3568  struct alignas(T) constexpr_optional_base {
3569  char storage_[sizeof(T)];
3570  bool init_;
3571  constexpr constexpr_optional_base() noexcept
3572  : storage_(), init_(false) {
3573  }
3574 
3575  explicit constexpr constexpr_optional_base(const T& v)
3576  : storage_(), init_(true) {
3577  new (&storage()) T(v);
3578  }
3579 
3580  explicit constexpr constexpr_optional_base(T&& v)
3581  : storage_(), init_(true) {
3582  new (&storage()) T(constexpr_move(v));
3583  }
3584 
3585  template <class... Args>
3586  explicit constexpr constexpr_optional_base(in_place_t, Args&&... args)
3587  : init_(true), storage_() {
3588  new (&storage()) T(constexpr_forward<Args>(args)...);
3589  }
3590 
3591  template <class U, class... Args, TR2_OPTIONAL_REQUIRES(::std::is_constructible<T, ::std::initializer_list<U>>)>
3592  OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, ::std::initializer_list<U> il, Args&&... args)
3593  : init_(true), storage_() {
3594  new (&storage()) T(il, constexpr_forward<Args>(args)...);
3595  }
3596 
3597 #if defined __GNUC__
3598 #pragma GCC diagnostic push
3599 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
3600 #endif
3601  T& storage() {
3602  return (*reinterpret_cast<T*>(&storage_[0]));
3603  }
3604 
3605  constexpr const T& storage() const {
3606  return (*reinterpret_cast<T const*>(&storage_[0]));
3607  }
3608 #if defined __GNUC__
3609 #pragma GCC diagnostic pop
3610 #endif
3611 
3612  ~constexpr_optional_base() = default;
3613  };
3614 #endif
3615 
3616  template <class T>
3617  using OptionalBase = typename ::std::conditional<
3618  ::std::is_trivially_destructible<T>::value,
3621 
3622  template <class T>
3623  class optional : private OptionalBase<T> {
3624  static_assert(!::std::is_same<typename ::std::decay<T>::type, nullopt_t>::value, "bad T");
3625  static_assert(!::std::is_same<typename ::std::decay<T>::type, in_place_t>::value, "bad T");
3626 
3627  constexpr bool initialized() const noexcept {
3628  return OptionalBase<T>::init_;
3629  }
3631  return ::std::addressof(OptionalBase<T>::storage());
3632  }
3633  constexpr const T* dataptr() const {
3635  }
3636 
3637 #if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
3638  constexpr const T& contained_val() const& {
3639  return OptionalBase<T>::storage();
3640  }
3641 #if OPTIONAL_HAS_MOVE_ACCESSORS == 1
3642  OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && {
3643  return ::std::move(OptionalBase<T>::storage());
3644  }
3645  OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & {
3646  return OptionalBase<T>::storage();
3647  }
3648 #else
3649  T& contained_val() & {
3650  return OptionalBase<T>::storage();
3651  }
3652  T&& contained_val() && {
3653  return ::std::move(OptionalBase<T>::storage());
3654  }
3655 #endif
3656 #else
3657  constexpr const T& contained_val() const {
3658  return OptionalBase<T>::storage();
3659  }
3661  return OptionalBase<T>::storage();
3662  }
3663 #endif
3664 
3665  void clear() noexcept {
3666  if (initialized())
3667  dataptr()->T::~T();
3668  OptionalBase<T>::init_ = false;
3669  }
3670 
3671  template <class... Args>
3672  void initialize(Args&&... args) noexcept(noexcept(T(::std::forward<Args>(args)...))) {
3673  assert(!OptionalBase<T>::init_);
3674  ::new (static_cast<void*>(dataptr())) T(::std::forward<Args>(args)...);
3675  OptionalBase<T>::init_ = true;
3676  }
3677 
3678  template <class U, class... Args>
3679  void initialize(::std::initializer_list<U> il, Args&&... args) noexcept(noexcept(T(il, ::std::forward<Args>(args)...))) {
3680  assert(!OptionalBase<T>::init_);
3681  ::new (static_cast<void*>(dataptr())) T(il, ::std::forward<Args>(args)...);
3682  OptionalBase<T>::init_ = true;
3683  }
3684 
3685  public:
3686  typedef T value_type;
3687 
3688  // 20.5.5.1, constructors
3689  constexpr optional() noexcept
3690  : OptionalBase<T>(){};
3691  constexpr optional(nullopt_t) noexcept
3692  : OptionalBase<T>(){};
3693 
3694  optional(const optional& rhs)
3695  : OptionalBase<T>() {
3696  if (rhs.initialized()) {
3697  ::new (static_cast<void*>(dataptr())) T(*rhs);
3698  OptionalBase<T>::init_ = true;
3699  }
3700  }
3701 
3703  : optional() {
3704  if (rhs) {
3705  ::new (static_cast<void*>(dataptr())) T(*rhs);
3706  OptionalBase<T>::init_ = true;
3707  }
3708  }
3709 
3710  optional(optional&& rhs) noexcept(::std::is_nothrow_move_constructible<T>::value)
3711  : OptionalBase<T>() {
3712  if (rhs.initialized()) {
3713  ::new (static_cast<void*>(dataptr())) T(::std::move(*rhs));
3714  OptionalBase<T>::init_ = true;
3715  }
3716  }
3717 
3718  constexpr optional(const T& v)
3719  : OptionalBase<T>(v) {
3720  }
3721 
3722  constexpr optional(T&& v)
3723  : OptionalBase<T>(constexpr_move(v)) {
3724  }
3725 
3726  template <class... Args>
3727  explicit constexpr optional(in_place_t, Args&&... args)
3728  : OptionalBase<T>(in_place, constexpr_forward<Args>(args)...) {
3729  }
3730 
3731  template <class U, class... Args, TR2_OPTIONAL_REQUIRES(::std::is_constructible<T, ::std::initializer_list<U>>)>
3732  OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, ::std::initializer_list<U> il, Args&&... args)
3733  : OptionalBase<T>(in_place, il, constexpr_forward<Args>(args)...) {
3734  }
3735 
3736  // 20.5.4.2, Destructor
3737  ~optional() = default;
3738 
3739  // 20.5.4.3, assignment
3741  clear();
3742  return *this;
3743  }
3744 
3745  optional& operator=(const optional& rhs) {
3746  if (initialized() == true && rhs.initialized() == false)
3747  clear();
3748  else if (initialized() == false && rhs.initialized() == true)
3749  initialize(*rhs);
3750  else if (initialized() == true && rhs.initialized() == true)
3751  contained_val() = *rhs;
3752  return *this;
3753  }
3754 
3755  optional& operator=(optional&& rhs) noexcept(::std::is_nothrow_move_assignable<T>::value&& ::std::is_nothrow_move_constructible<T>::value) {
3756  if (initialized() == true && rhs.initialized() == false)
3757  clear();
3758  else if (initialized() == false && rhs.initialized() == true)
3759  initialize(::std::move(*rhs));
3760  else if (initialized() == true && rhs.initialized() == true)
3761  contained_val() = ::std::move(*rhs);
3762  return *this;
3763  }
3764 
3765  template <class U>
3766  auto operator=(U&& v)
3767  -> typename ::std::enable_if<
3769  optional&>::type {
3770  if (initialized()) {
3771  contained_val() = ::std::forward<U>(v);
3772  }
3773  else {
3774  initialize(::std::forward<U>(v));
3775  }
3776  return *this;
3777  }
3778 
3779  template <class... Args>
3780  void emplace(Args&&... args) {
3781  clear();
3782  initialize(::std::forward<Args>(args)...);
3783  }
3784 
3785  template <class U, class... Args>
3786  void emplace(::std::initializer_list<U> il, Args&&... args) {
3787  clear();
3788  initialize<U, Args...>(il, ::std::forward<Args>(args)...);
3789  }
3790 
3791  // 20.5.4.4, Swap
3792  void swap(optional<T>& rhs) noexcept(::std::is_nothrow_move_constructible<T>::value&& noexcept(swap(::std::declval<T&>(), ::std::declval<T&>()))) {
3793  if (initialized() == true && rhs.initialized() == false) {
3794  rhs.initialize(::std::move(**this));
3795  clear();
3796  }
3797  else if (initialized() == false && rhs.initialized() == true) {
3798  initialize(::std::move(*rhs));
3799  rhs.clear();
3800  }
3801  else if (initialized() == true && rhs.initialized() == true) {
3803  swap(**this, *rhs);
3804  }
3805  }
3806 
3807  // 20.5.4.5, Observers
3808 
3809  explicit constexpr operator bool() const noexcept {
3810  return initialized();
3811  }
3812 
3813  constexpr T const* operator->() const {
3814  return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr());
3815  }
3816 
3817 #if OPTIONAL_HAS_MOVE_ACCESSORS == 1
3818 
3819  OPTIONAL_MUTABLE_CONSTEXPR T* operator->() {
3820  assert(initialized());
3821  return dataptr();
3822  }
3823 
3824  constexpr T const& operator*() const& {
3825  return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
3826  }
3827 
3829  assert(initialized());
3830  return contained_val();
3831  }
3832 
3834  assert(initialized());
3835  return constexpr_move(contained_val());
3836  }
3837 
3838  constexpr T const& value() const& {
3839  return initialized() ? contained_val()
3840 #ifdef SOL_NO_EXCEPTIONS
3841  // we can't abort here
3842  // because there's no constexpr abort
3843  : *static_cast<T*>(nullptr);
3844 #else
3845  : (throw bad_optional_access("bad optional access"), contained_val());
3846 #endif
3847  }
3848 
3849  OPTIONAL_MUTABLE_CONSTEXPR T& value() & {
3850  return initialized() ? contained_val()
3851 #ifdef SOL_NO_EXCEPTIONS
3852  : *static_cast<T*>(nullptr);
3853 #else
3854  : (throw bad_optional_access("bad optional access"), contained_val());
3855 #endif
3856  }
3857 
3858  OPTIONAL_MUTABLE_CONSTEXPR T&& value() && {
3859  return initialized() ? contained_val()
3860 #ifdef SOL_NO_EXCEPTIONS
3861  // we can't abort here
3862  // because there's no constexpr abort
3863  : std::move(*static_cast<T*>(nullptr));
3864 #else
3865  : (throw bad_optional_access("bad optional access"), contained_val());
3866 #endif
3867  }
3868 
3869 #else
3870 
3871  T* operator->() {
3872  assert(initialized());
3873  return dataptr();
3874  }
3875 
3876  constexpr T const& operator*() const {
3877  return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
3878  }
3879 
3880  T& operator*() {
3881  assert(initialized());
3882  return contained_val();
3883  }
3884 
3885  constexpr T const& value() const {
3886  return initialized() ? contained_val()
3887 #ifdef SOL_NO_EXCEPTIONS
3888  // we can't abort here
3889  // because there's no constexpr abort
3890  : *static_cast<T*>(nullptr);
3891 #else
3892  : (throw bad_optional_access("bad optional access"), contained_val());
3893 #endif
3894  }
3895 
3896  T& value() {
3897  return initialized() ? contained_val()
3898 #ifdef SOL_NO_EXCEPTIONS
3899  // we can abort here
3900  // but the others are constexpr, so we can't...
3901  : (std::abort(), *static_cast<T*>(nullptr));
3902 #else
3903  : (throw bad_optional_access("bad optional access"), contained_val());
3904 #endif
3905  }
3906 
3907 #endif
3908 
3909 #if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
3910 
3911  template <class V>
3912  constexpr T value_or(V&& v) const& {
3913  return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
3914  }
3915 
3916 #if OPTIONAL_HAS_MOVE_ACCESSORS == 1
3917 
3918  template <class V>
3919  OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) && {
3920  return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
3921  }
3922 
3923 #else
3924 
3925  template <class V>
3926  T value_or(V&& v) && {
3927  return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
3928  }
3929 
3930 #endif
3931 
3932 #else
3933 
3934  template <class V>
3935  constexpr T value_or(V&& v) const {
3936  return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
3937  }
3938 
3939 #endif
3940  };
3941 
3942  template <class T>
3943  class optional<T&> {
3944  static_assert(!::std::is_same<T, nullopt_t>::value, "bad T");
3945  static_assert(!::std::is_same<T, in_place_t>::value, "bad T");
3946  T* ref;
3947 
3948  public:
3949  // 20.5.5.1, construction/destruction
3950  constexpr optional() noexcept
3951  : ref(nullptr) {
3952  }
3953 
3954  constexpr optional(nullopt_t) noexcept
3955  : ref(nullptr) {
3956  }
3957 
3958  constexpr optional(T& v) noexcept
3959  : ref(detail_::static_addressof(v)) {
3960  }
3961 
3962  optional(T&&) = delete;
3963 
3964  constexpr optional(const optional& rhs) noexcept
3965  : ref(rhs.ref) {
3966  }
3967 
3968  explicit constexpr optional(in_place_t, T& v) noexcept
3969  : ref(detail_::static_addressof(v)) {
3970  }
3971 
3972  explicit optional(in_place_t, T&&) = delete;
3973 
3974  ~optional() = default;
3975 
3976  // 20.5.5.2, mutation
3978  ref = nullptr;
3979  return *this;
3980  }
3981 
3982  // optional& operator=(const optional& rhs) noexcept {
3983  // ref = rhs.ref;
3984  // return *this;
3985  // }
3986 
3987  // optional& operator=(optional&& rhs) noexcept {
3988  // ref = rhs.ref;
3989  // return *this;
3990  // }
3991 
3992  template <typename U>
3993  auto operator=(U&& rhs) noexcept
3994  -> typename ::std::enable_if<
3995  ::std::is_same<typename ::std::decay<U>::type, optional<T&>>::value,
3996  optional&>::type {
3997  ref = rhs.ref;
3998  return *this;
3999  }
4000 
4001  template <typename U>
4002  auto operator=(U&& rhs) noexcept
4003  -> typename ::std::enable_if<
4004  !::std::is_same<typename ::std::decay<U>::type, optional<T&>>::value,
4005  optional&>::type = delete;
4006 
4007  void emplace(T& v) noexcept {
4008  ref = detail_::static_addressof(v);
4009  }
4010 
4011  void emplace(T&&) = delete;
4012 
4013  void swap(optional<T&>& rhs) noexcept {
4014  ::std::swap(ref, rhs.ref);
4015  }
4016 
4017  // 20.5.5.3, observers
4018  constexpr T* operator->() const {
4019  return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref);
4020  }
4021 
4022  constexpr T& operator*() const {
4023  return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref);
4024  }
4025 
4026  constexpr T& value() const {
4027 #ifdef SOL_NO_EXCEPTIONS
4028  return *ref;
4029 #else
4030  return ref ? *ref
4031  : (throw bad_optional_access("bad optional access"), *ref);
4032 #endif // Exceptions
4033  }
4034 
4035  explicit constexpr operator bool() const noexcept {
4036  return ref != nullptr;
4037  }
4038 
4039  template <typename V>
4040  constexpr T& value_or(V&& v) const {
4041  return *this ? **this : detail_::convert<T&>(constexpr_forward<V>(v));
4042  }
4043  };
4044 
4045  template <class T>
4046  class optional<T&&> {
4047  static_assert(sizeof(T) == 0, "optional rvalue references disallowed");
4048  };
4049 
4050  // 20.5.8, Relational operators
4051  template <class T>
4052  constexpr bool operator==(const optional<T>& x, const optional<T>& y) {
4053  return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y;
4054  }
4055 
4056  template <class T>
4057  constexpr bool operator!=(const optional<T>& x, const optional<T>& y) {
4058  return !(x == y);
4059  }
4060 
4061  template <class T>
4062  constexpr bool operator<(const optional<T>& x, const optional<T>& y) {
4063  return (!y) ? false : (!x) ? true : *x < *y;
4064  }
4065 
4066  template <class T>
4067  constexpr bool operator>(const optional<T>& x, const optional<T>& y) {
4068  return (y < x);
4069  }
4070 
4071  template <class T>
4072  constexpr bool operator<=(const optional<T>& x, const optional<T>& y) {
4073  return !(y < x);
4074  }
4075 
4076  template <class T>
4077  constexpr bool operator>=(const optional<T>& x, const optional<T>& y) {
4078  return !(x < y);
4079  }
4080 
4081  // 20.5.9, Comparison with nullopt
4082  template <class T>
4083  constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept {
4084  return (!x);
4085  }
4086 
4087  template <class T>
4088  constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept {
4089  return (!x);
4090  }
4091 
4092  template <class T>
4093  constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept {
4094  return bool(x);
4095  }
4096 
4097  template <class T>
4098  constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept {
4099  return bool(x);
4100  }
4101 
4102  template <class T>
4103  constexpr bool operator<(const optional<T>&, nullopt_t) noexcept {
4104  return false;
4105  }
4106 
4107  template <class T>
4108  constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept {
4109  return bool(x);
4110  }
4111 
4112  template <class T>
4113  constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept {
4114  return (!x);
4115  }
4116 
4117  template <class T>
4118  constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept {
4119  return true;
4120  }
4121 
4122  template <class T>
4123  constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept {
4124  return bool(x);
4125  }
4126 
4127  template <class T>
4128  constexpr bool operator>(nullopt_t, const optional<T>&) noexcept {
4129  return false;
4130  }
4131 
4132  template <class T>
4133  constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept {
4134  return true;
4135  }
4136 
4137  template <class T>
4138  constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept {
4139  return (!x);
4140  }
4141 
4142  // 20.5.10, Comparison with T
4143  template <class T>
4144  constexpr bool operator==(const optional<T>& x, const T& v) {
4145  return bool(x) ? *x == v : false;
4146  }
4147 
4148  template <class T>
4149  constexpr bool operator==(const T& v, const optional<T>& x) {
4150  return bool(x) ? v == *x : false;
4151  }
4152 
4153  template <class T>
4154  constexpr bool operator!=(const optional<T>& x, const T& v) {
4155  return bool(x) ? *x != v : true;
4156  }
4157 
4158  template <class T>
4159  constexpr bool operator!=(const T& v, const optional<T>& x) {
4160  return bool(x) ? v != *x : true;
4161  }
4162 
4163  template <class T>
4164  constexpr bool operator<(const optional<T>& x, const T& v) {
4165  return bool(x) ? *x < v : true;
4166  }
4167 
4168  template <class T>
4169  constexpr bool operator>(const T& v, const optional<T>& x) {
4170  return bool(x) ? v > *x : true;
4171  }
4172 
4173  template <class T>
4174  constexpr bool operator>(const optional<T>& x, const T& v) {
4175  return bool(x) ? *x > v : false;
4176  }
4177 
4178  template <class T>
4179  constexpr bool operator<(const T& v, const optional<T>& x) {
4180  return bool(x) ? v < *x : false;
4181  }
4182 
4183  template <class T>
4184  constexpr bool operator>=(const optional<T>& x, const T& v) {
4185  return bool(x) ? *x >= v : false;
4186  }
4187 
4188  template <class T>
4189  constexpr bool operator<=(const T& v, const optional<T>& x) {
4190  return bool(x) ? v <= *x : false;
4191  }
4192 
4193  template <class T>
4194  constexpr bool operator<=(const optional<T>& x, const T& v) {
4195  return bool(x) ? *x <= v : true;
4196  }
4197 
4198  template <class T>
4199  constexpr bool operator>=(const T& v, const optional<T>& x) {
4200  return bool(x) ? v >= *x : true;
4201  }
4202 
4203  // Comparison of optional<T&> with T
4204  template <class T>
4205  constexpr bool operator==(const optional<T&>& x, const T& v) {
4206  return bool(x) ? *x == v : false;
4207  }
4208 
4209  template <class T>
4210  constexpr bool operator==(const T& v, const optional<T&>& x) {
4211  return bool(x) ? v == *x : false;
4212  }
4213 
4214  template <class T>
4215  constexpr bool operator!=(const optional<T&>& x, const T& v) {
4216  return bool(x) ? *x != v : true;
4217  }
4218 
4219  template <class T>
4220  constexpr bool operator!=(const T& v, const optional<T&>& x) {
4221  return bool(x) ? v != *x : true;
4222  }
4223 
4224  template <class T>
4225  constexpr bool operator<(const optional<T&>& x, const T& v) {
4226  return bool(x) ? *x < v : true;
4227  }
4228 
4229  template <class T>
4230  constexpr bool operator>(const T& v, const optional<T&>& x) {
4231  return bool(x) ? v > *x : true;
4232  }
4233 
4234  template <class T>
4235  constexpr bool operator>(const optional<T&>& x, const T& v) {
4236  return bool(x) ? *x > v : false;
4237  }
4238 
4239  template <class T>
4240  constexpr bool operator<(const T& v, const optional<T&>& x) {
4241  return bool(x) ? v < *x : false;
4242  }
4243 
4244  template <class T>
4245  constexpr bool operator>=(const optional<T&>& x, const T& v) {
4246  return bool(x) ? *x >= v : false;
4247  }
4248 
4249  template <class T>
4250  constexpr bool operator<=(const T& v, const optional<T&>& x) {
4251  return bool(x) ? v <= *x : false;
4252  }
4253 
4254  template <class T>
4255  constexpr bool operator<=(const optional<T&>& x, const T& v) {
4256  return bool(x) ? *x <= v : true;
4257  }
4258 
4259  template <class T>
4260  constexpr bool operator>=(const T& v, const optional<T&>& x) {
4261  return bool(x) ? v >= *x : true;
4262  }
4263 
4264  // Comparison of optional<T const&> with T
4265  template <class T>
4266  constexpr bool operator==(const optional<const T&>& x, const T& v) {
4267  return bool(x) ? *x == v : false;
4268  }
4269 
4270  template <class T>
4271  constexpr bool operator==(const T& v, const optional<const T&>& x) {
4272  return bool(x) ? v == *x : false;
4273  }
4274 
4275  template <class T>
4276  constexpr bool operator!=(const optional<const T&>& x, const T& v) {
4277  return bool(x) ? *x != v : true;
4278  }
4279 
4280  template <class T>
4281  constexpr bool operator!=(const T& v, const optional<const T&>& x) {
4282  return bool(x) ? v != *x : true;
4283  }
4284 
4285  template <class T>
4286  constexpr bool operator<(const optional<const T&>& x, const T& v) {
4287  return bool(x) ? *x < v : true;
4288  }
4289 
4290  template <class T>
4291  constexpr bool operator>(const T& v, const optional<const T&>& x) {
4292  return bool(x) ? v > *x : true;
4293  }
4294 
4295  template <class T>
4296  constexpr bool operator>(const optional<const T&>& x, const T& v) {
4297  return bool(x) ? *x > v : false;
4298  }
4299 
4300  template <class T>
4301  constexpr bool operator<(const T& v, const optional<const T&>& x) {
4302  return bool(x) ? v < *x : false;
4303  }
4304 
4305  template <class T>
4306  constexpr bool operator>=(const optional<const T&>& x, const T& v) {
4307  return bool(x) ? *x >= v : false;
4308  }
4309 
4310  template <class T>
4311  constexpr bool operator<=(const T& v, const optional<const T&>& x) {
4312  return bool(x) ? v <= *x : false;
4313  }
4314 
4315  template <class T>
4316  constexpr bool operator<=(const optional<const T&>& x, const T& v) {
4317  return bool(x) ? *x <= v : true;
4318  }
4319 
4320  template <class T>
4321  constexpr bool operator>=(const T& v, const optional<const T&>& x) {
4322  return bool(x) ? v >= *x : true;
4323  }
4324 
4325  // 20.5.12, Specialized algorithms
4326  template <class T>
4327  void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y))) {
4328  x.swap(y);
4329  }
4330 
4331  template <class T>
4333  return optional<typename ::std::decay<T>::type>(constexpr_forward<T>(v));
4334  }
4335 
4336  template <class X>
4337  constexpr optional<X&> make_optional(::std::reference_wrapper<X> v) {
4338  return optional<X&>(v.get());
4339  }
4340 
4341 } // namespace sol
4342 
4343 namespace std {
4344  template <typename T>
4345  struct hash<sol::optional<T>> {
4346  typedef typename hash<T>::result_type result_type;
4348 
4349  constexpr result_type operator()(argument_type const& arg) const {
4350  return arg ? ::std::hash<T>{}(*arg) : result_type{};
4351  }
4352  };
4353 
4354  template <typename T>
4355  struct hash<sol::optional<T&>> {
4356  typedef typename hash<T>::result_type result_type;
4358 
4359  constexpr result_type operator()(argument_type const& arg) const {
4360  return arg ? ::std::hash<T>{}(*arg) : result_type{};
4361  }
4362  };
4363 } // namespace std
4364 
4365 #if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
4366 #pragma warning(pop)
4367 #endif
4368 
4369 #undef TR2_OPTIONAL_REQUIRES
4370 #undef TR2_OPTIONAL_ASSERTED_EXPRESSION
4371 
4372 // end of sol/optional_implementation.hpp
4373 
4374 #endif // Boost vs. Better optional
4375 
4376 namespace sol {
4377 
4378 #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
4379  template <typename T>
4380  using optional = boost::optional<T>;
4381  using nullopt_t = boost::none_t;
4382  const nullopt_t nullopt = boost::none;
4383 #endif // Boost vs. Better optional
4384 
4385  namespace meta {
4386  template <typename T>
4387  struct is_optional : std::false_type {};
4388  template <typename T>
4389  struct is_optional<optional<T>> : std::true_type {};
4390  } // namespace meta
4391 } // namespace sol
4392 
4393 // end of sol/optional.hpp
4394 
4395 // beginning of sol/forward_detail.hpp
4396 
4397 namespace sol {
4398  namespace detail {
4400 #if defined(SOL_SAFE_FUNCTION_CALLS) && SOL_SAFE_FUNCTION_CALLS
4401  true;
4402 #else
4403  false;
4404 #endif
4405  } // namespace detail
4406 
4407  namespace meta {
4408  namespace meta_detail {
4409  }
4410  } // namespace meta::meta_detail
4411 
4412  namespace stack {
4413  namespace stack_detail {
4414  template <typename T>
4416  }
4417  } // namespace stack::stack_detail
4418 
4419  namespace usertype_detail {
4420  template <typename T, typename Regs, typename Fx>
4421  void insert_default_registrations(Regs& l, int& index, Fx&& fx);
4422 
4423  template <typename T, typename Regs, meta::enable<meta::neg<std::is_pointer<T>>, std::is_destructible<T>> = meta::enabler>
4424  void make_destructor(Regs& l, int& index);
4425  template <typename T, typename Regs, meta::disable<meta::neg<std::is_pointer<T>>, std::is_destructible<T>> = meta::enabler>
4426  void make_destructor(Regs& l, int& index);
4427  } // namespace usertype_detail
4428 } // namespace sol
4429 
4430 // end of sol/forward_detail.hpp
4431 
4432 // beginning of sol/raii.hpp
4433 
4434 namespace sol {
4435  namespace detail {
4437  template <typename T, typename... Args>
4438  static void construct(T&& obj, Args&&... args) {
4439  typedef meta::unqualified_t<T> Tu;
4440  std::allocator<Tu> alloc{};
4441  std::allocator_traits<std::allocator<Tu>>::construct(alloc, std::forward<T>(obj), std::forward<Args>(args)...);
4442  }
4443 
4444  template <typename T, typename... Args>
4445  void operator()(T&& obj, Args&&... args) const {
4446  construct(std::forward<T>(obj), std::forward<Args>(args)...);
4447  }
4448  };
4449 
4451  template <typename T>
4452  static void destroy(T&& obj) {
4453  std::allocator<meta::unqualified_t<T>> alloc{};
4454  alloc.destroy(obj);
4455  }
4456 
4457  template <typename T>
4458  void operator()(T&& obj) const {
4459  destroy(std::forward<T>(obj));
4460  }
4461  };
4462 
4463  struct deleter {
4464  template <typename T>
4465  void operator()(T* p) const {
4466  delete p;
4467  }
4468  };
4469 
4470  struct state_deleter {
4471  void operator()(lua_State* L) const {
4472  lua_close(L);
4473  }
4474  };
4475 
4476  template <typename T, typename Dx, typename... Args>
4477  inline std::unique_ptr<T, Dx> make_unique_deleter(Args&&... args) {
4478  return std::unique_ptr<T, Dx>(new T(std::forward<Args>(args)...));
4479  }
4480 
4481  template <typename Tag, typename T>
4482  struct tagged {
4484  template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, tagged>> = meta::enabler>
4485  tagged(Arg&& arg, Args&&... args)
4486  : value(std::forward<Arg>(arg), std::forward<Args>(args)...) {
4487  }
4488  };
4489  } // namespace detail
4490 
4491  template <typename... Args>
4492  struct constructor_list {};
4493 
4494  template <typename... Args>
4495  using constructors = constructor_list<Args...>;
4496 
4498 
4499  struct no_construction {};
4501 
4504 
4505  template <typename... Functions>
4507  std::tuple<Functions...> functions;
4508  template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, constructor_wrapper>> = meta::enabler>
4509  constructor_wrapper(Arg&& arg, Args&&... args)
4510  : functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
4511  }
4512  };
4513 
4514  template <typename... Functions>
4515  inline auto initializers(Functions&&... functions) {
4516  return constructor_wrapper<std::decay_t<Functions>...>(std::forward<Functions>(functions)...);
4517  }
4518 
4519  template <typename... Functions>
4521  std::tuple<Functions...> functions;
4522  template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, factory_wrapper>> = meta::enabler>
4523  factory_wrapper(Arg&& arg, Args&&... args)
4524  : functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
4525  }
4526  };
4527 
4528  template <typename... Functions>
4529  inline auto factories(Functions&&... functions) {
4530  return factory_wrapper<std::decay_t<Functions>...>(std::forward<Functions>(functions)...);
4531  }
4532 
4533  template <typename Function>
4535  Function fx;
4537  : fx(std::move(f)) {
4538  }
4539  };
4540 
4541  template <>
4542  struct destructor_wrapper<void> {};
4543 
4545 
4546  template <typename Fx>
4547  inline auto destructor(Fx&& fx) {
4548  return destructor_wrapper<std::decay_t<Fx>>(std::forward<Fx>(fx));
4549  }
4550 
4551 } // namespace sol
4552 
4553 // end of sol/raii.hpp
4554 
4555 // beginning of sol/filters.hpp
4556 
4557 namespace sol {
4558  namespace detail {
4559  struct filter_base_tag {};
4560  } // namespace detail
4561 
4562  template <int Target, int... In>
4565  template <int... In>
4568 
4570  int target;
4571  std::array<int, 64> stack_indices;
4572  std::size_t len;
4573 
4574  template <typename... Args>
4575  stack_dependencies(int stack_target, Args&&... args)
4576  : target(stack_target), stack_indices(), len(sizeof...(Args)) {
4577  std::size_t i = 0;
4578  (void)detail::swallow{int(), (stack_indices[i++] = static_cast<int>(std::forward<Args>(args)), int())...};
4579  }
4580 
4581  int& operator[](std::size_t i) {
4582  return stack_indices[i];
4583  }
4584 
4585  const int& operator[](std::size_t i) const {
4586  return stack_indices[i];
4587  }
4588 
4589  std::size_t size() const {
4590  return len;
4591  }
4592  };
4593 
4594  template <typename F, typename... Filters>
4595  struct filter_wrapper {
4596  typedef std::index_sequence_for<Filters...> indices;
4597 
4599  std::tuple<Filters...> filters;
4600 
4601  template <typename Fx, typename... Args, meta::enable<meta::neg<std::is_same<meta::unqualified_t<Fx>, filter_wrapper>>> = meta::enabler>
4602  filter_wrapper(Fx&& fx, Args&&... args)
4603  : value(std::forward<Fx>(fx)), filters(std::forward<Args>(args)...) {
4604  }
4605 
4606  filter_wrapper(const filter_wrapper&) = default;
4607  filter_wrapper& operator=(const filter_wrapper&) = default;
4608  filter_wrapper(filter_wrapper&&) = default;
4609  filter_wrapper& operator=(filter_wrapper&&) = default;
4610  };
4611 
4612  template <typename F, typename... Args>
4613  auto filters(F&& f, Args&&... args) {
4614  return filter_wrapper<std::decay_t<F>, std::decay_t<Args>...>(std::forward<F>(f), std::forward<Args>(args)...);
4615  }
4616 } // namespace sol
4617 
4618 // end of sol/filters.hpp
4619 
4620 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
4621 #include <optional>
4622 #ifdef SOL_STD_VARIANT
4623 #include <variant>
4624 #endif
4625 #endif // C++17
4626 #ifdef SOL_USE_BOOST
4627 #include <boost/unordered_map.hpp>
4628 #else
4629 #include <unordered_map>
4630 #endif // Using Boost
4631 
4632 namespace sol {
4633  namespace usertype_detail {
4634 #if defined(SOL_USE_BOOST)
4635 #if defined(SOL_CXX17_FEATURES)
4636  template <typename K, typename V, typename H = std::hash<K>, typename E = std::equal_to<>>
4637  using map_t = boost::unordered_map<K, V, H, E>;
4638 #else
4639  template <typename K, typename V, typename H = boost::hash<K>, typename E = std::equal_to<>>
4640  using map_t = boost::unordered_map<K, V, H, E>;
4641 #endif // C++17 or not, WITH boost
4642 #else
4643  template <typename K, typename V, typename H = std::hash<K>, typename E = std::equal_to<>>
4644  using map_t = std::unordered_map<K, V, H, E>;
4645 #endif // Boost map target
4646  } // namespace usertype_detail
4647 
4648  namespace detail {
4649 #ifdef SOL_NOEXCEPT_FUNCTION_TYPE
4650  typedef int (*lua_CFunction_noexcept)(lua_State* L) noexcept;
4651 #else
4652  typedef int (*lua_CFunction_noexcept)(lua_State* L);
4653 #endif // noexcept function type for lua_CFunction
4654 
4655  template <typename T>
4656  struct unique_usertype {};
4657 
4658  template <typename T>
4660  T& item;
4662  : item(*item) {
4663  }
4665  : item(item) {
4666  }
4667  operator T&() {
4668  return item;
4669  }
4670  operator T*() {
4671  return std::addressof(item);
4672  }
4673  };
4674 
4675  struct unchecked_t {};
4677 
4678  struct yield_tag_t {};
4680  } // namespace detail
4681 
4682  struct lua_nil_t {};
4685  return true;
4686  }
4688  return false;
4689  }
4690  typedef lua_nil_t nil_t;
4691 #if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0)
4692  const nil_t nil{};
4693 #endif
4694 
4695  namespace detail {
4696  struct non_lua_nil_t {};
4697  } // namespace detail
4698 
4699  struct metatable_t {};
4701 
4702  struct env_t {};
4703  const env_t env_key = {};
4704 
4705  struct no_metatable_t {};
4707 
4708  template <typename T>
4709  struct yielding_t {
4710  T func;
4711 
4712  yielding_t() = default;
4713  yielding_t(const yielding_t&) = default;
4714  yielding_t(yielding_t&&) = default;
4715  yielding_t& operator=(const yielding_t&) = default;
4716  yielding_t& operator=(yielding_t&&) = default;
4717  template <typename Arg, meta::enable<meta::neg<std::is_same<meta::unqualified_t<Arg>, yielding_t>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<Arg>>>> = meta::enabler>
4718  yielding_t(Arg&& arg)
4719  : func(std::forward<Arg>(arg)) {
4720  }
4721  template <typename Arg0, typename Arg1, typename... Args>
4722  yielding_t(Arg0&& arg0, Arg1&& arg1, Args&&... args)
4723  : func(std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...) {
4724  }
4725  };
4726 
4727  template <typename F>
4729  return yielding_t<std::decay_t<F>>(std::forward<F>(f));
4730  }
4731 
4732  typedef std::remove_pointer_t<lua_CFunction> lua_CFunction_ref;
4733 
4734  template <typename T>
4735  struct unique_usertype_traits {
4736  typedef T type;
4737  typedef T actual_type;
4738  template <typename X>
4739  using rebind_base = void;
4740 
4741  static const bool value = false;
4742 
4743  template <typename U>
4744  static bool is_null(U&&) {
4745  return false;
4746  }
4747 
4748  template <typename U>
4749  static auto get(U&& value) {
4750  return std::addressof(detail::deref(value));
4751  }
4752  };
4753 
4754  template <typename T>
4755  struct unique_usertype_traits<std::shared_ptr<T>> {
4756  typedef T type;
4757  typedef std::shared_ptr<T> actual_type;
4758  // rebind is non-void
4759  // if and only if unique usertype
4760  // is cast-capable
4761  template <typename X>
4762  using rebind_base = std::shared_ptr<X>;
4763 
4764  static const bool value = true;
4765 
4766  static bool is_null(const actual_type& p) {
4767  return p == nullptr;
4768  }
4769 
4770  static type* get(const actual_type& p) {
4771  return p.get();
4772  }
4773  };
4774 
4775  template <typename T, typename D>
4776  struct unique_usertype_traits<std::unique_ptr<T, D>> {
4777  typedef T type;
4778  typedef std::unique_ptr<T, D> actual_type;
4779  template <typename X>
4780  using rebind_base = void;
4781 
4782  static const bool value = true;
4783 
4784  static bool is_null(const actual_type& p) {
4785  return p == nullptr;
4786  }
4787 
4788  static type* get(const actual_type& p) {
4789  return p.get();
4790  }
4791  };
4792 
4793  template <typename T>
4794  struct non_null {};
4795 
4796  template <typename... Args>
4797  struct function_sig {};
4798 
4799  struct upvalue_index {
4800  int index;
4801  upvalue_index(int idx)
4802  : index(lua_upvalueindex(idx)) {
4803  }
4804 
4805  operator int() const {
4806  return index;
4807  }
4808  };
4809 
4810  struct raw_index {
4811  int index;
4812  raw_index(int i)
4813  : index(i) {
4814  }
4815 
4816  operator int() const {
4817  return index;
4818  }
4819  };
4820 
4822  int index;
4823  absolute_index(lua_State* L, int idx)
4824  : index(lua_absindex(L, idx)) {
4825  }
4826 
4827  operator int() const {
4828  return index;
4829  }
4830  };
4831 
4832  struct ref_index {
4833  int index;
4834  ref_index(int idx)
4835  : index(idx) {
4836  }
4837 
4838  operator int() const {
4839  return index;
4840  }
4841  };
4842 
4843  struct stack_count {
4844  int count;
4845 
4846  stack_count(int cnt)
4847  : count(cnt) {
4848  }
4849  };
4850 
4852  void* value;
4854  : value(data) {
4855  }
4856  operator void*() const {
4857  return value;
4858  }
4859  };
4860 
4862  void* value;
4863  userdata_value(void* data)
4864  : value(data) {
4865  }
4866  operator void*() const {
4867  return value;
4868  }
4869  };
4870 
4871  template <typename L>
4872  struct light {
4873  L* value;
4874 
4875  light(L& x)
4876  : value(std::addressof(x)) {
4877  }
4878  light(L* x)
4879  : value(x) {
4880  }
4881  light(void* x)
4882  : value(static_cast<L*>(x)) {
4883  }
4884  operator L*() const {
4885  return value;
4886  }
4887  operator L&() const {
4888  return *value;
4889  }
4890  };
4891 
4892  template <typename T>
4893  auto make_light(T& l) {
4895  return light<L>(l);
4896  }
4897 
4898  template <typename U>
4899  struct user {
4901 
4902  user(U&& x)
4903  : value(std::forward<U>(x)) {
4904  }
4905  operator std::add_pointer_t<std::remove_reference_t<U>>() {
4906  return std::addressof(value);
4907  }
4908  operator std::add_lvalue_reference_t<U>() {
4909  return value;
4910  }
4911  operator std::add_const_t<std::add_lvalue_reference_t<U>>&() const {
4912  return value;
4913  }
4914  };
4915 
4916  template <typename T>
4917  auto make_user(T&& u) {
4919  return user<U>(std::forward<T>(u));
4920  }
4921 
4922  template <typename T>
4924  T key;
4925 
4927  : key(std::forward<T>(key)) {
4928  }
4929  };
4930 
4931  template <typename T>
4932  auto meta_registry_key(T&& key) {
4933  typedef meta::unqualified_t<T> K;
4934  return metatable_registry_key<K>(std::forward<T>(key));
4935  }
4936 
4937  template <typename... Upvalues>
4938  struct closure {
4939  lua_CFunction c_function;
4940  std::tuple<Upvalues...> upvalues;
4941  closure(lua_CFunction f, Upvalues... targetupvalues)
4942  : c_function(f), upvalues(std::forward<Upvalues>(targetupvalues)...) {
4943  }
4944  };
4945 
4946  template <>
4947  struct closure<> {
4948  lua_CFunction c_function;
4950  closure(lua_CFunction f, int upvalue_count = 0)
4951  : c_function(f), upvalues(upvalue_count) {
4952  }
4953  };
4954 
4956 
4957  template <typename... Args>
4958  closure<Args...> make_closure(lua_CFunction f, Args&&... args) {
4959  return closure<Args...>(f, std::forward<Args>(args)...);
4960  }
4961 
4962  template <typename Sig, typename... Ps>
4964  std::tuple<Ps...> arguments;
4965  template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, function_arguments>> = meta::enabler>
4966  function_arguments(Arg&& arg, Args&&... args)
4967  : arguments(std::forward<Arg>(arg), std::forward<Args>(args)...) {
4968  }
4969  };
4970 
4971  template <typename Sig = function_sig<>, typename... Args>
4972  auto as_function(Args&&... args) {
4973  return function_arguments<Sig, std::decay_t<Args>...>(std::forward<Args>(args)...);
4974  }
4975 
4976  template <typename Sig = function_sig<>, typename... Args>
4977  auto as_function_reference(Args&&... args) {
4978  return function_arguments<Sig, Args...>(std::forward<Args>(args)...);
4979  }
4980 
4981  template <typename T>
4982  struct as_table_t {
4984 
4985  as_table_t() = default;
4986  as_table_t(const as_table_t&) = default;
4987  as_table_t(as_table_t&&) = default;
4988  as_table_t& operator=(const as_table_t&) = default;
4989  as_table_t& operator=(as_table_t&&) = default;
4990  template <typename Arg, meta::enable<meta::neg<std::is_same<meta::unqualified_t<Arg>, as_table_t>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<Arg>>>> = meta::enabler>
4991  as_table_t(Arg&& arg)
4992  : source(std::forward<Arg>(arg)) {
4993  }
4994  template <typename Arg0, typename Arg1, typename... Args>
4995  as_table_t(Arg0&& arg0, Arg1&& arg1, Args&&... args)
4996  : source(std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...) {
4997  }
4998 
4999  operator std::add_lvalue_reference_t<T>() {
5000  return source;
5001  }
5002  };
5003 
5004  template <typename T>
5005  struct nested {
5007 
5008  nested() = default;
5009  nested(const nested&) = default;
5010  nested(nested&&) = default;
5011  nested& operator=(const nested&) = default;
5012  nested& operator=(nested&&) = default;
5013  template <typename Arg, meta::enable<meta::neg<std::is_same<meta::unqualified_t<Arg>, nested>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<Arg>>>> = meta::enabler>
5014  nested(Arg&& arg)
5015  : source(std::forward<Arg>(arg)) {
5016  }
5017  template <typename Arg0, typename Arg1, typename... Args>
5018  nested(Arg0&& arg0, Arg1&& arg1, Args&&... args)
5019  : source(std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...) {
5020  }
5021 
5022  operator std::add_lvalue_reference_t<T>() {
5023  return source;
5024  }
5025  };
5026 
5027  template <typename T>
5028  as_table_t<T> as_table_ref(T&& container) {
5029  return as_table_t<T>(std::forward<T>(container));
5030  }
5031 
5032  template <typename T>
5034  return as_table_t<meta::unqualified_t<T>>(std::forward<T>(container));
5035  }
5036 
5037  template <typename T>
5038  nested<T> as_nested_ref(T&& container) {
5039  return nested<T>(std::forward<T>(container));
5040  }
5041 
5042  template <typename T>
5044  return nested<meta::unqualified_t<T>>(std::forward<T>(container));
5045  }
5046 
5047  struct this_state {
5048  lua_State* L;
5049 
5050  this_state(lua_State* Ls)
5051  : L(Ls) {
5052  }
5053 
5054  operator lua_State*() const noexcept {
5055  return lua_state();
5056  }
5057 
5058  lua_State* operator->() const noexcept {
5059  return lua_state();
5060  }
5061 
5062  lua_State* lua_state() const noexcept {
5063  return L;
5064  }
5065  };
5066 
5068  lua_State* L;
5069 
5070  this_main_state(lua_State* Ls)
5071  : L(Ls) {
5072  }
5073 
5074  operator lua_State*() const noexcept {
5075  return lua_state();
5076  }
5077 
5078  lua_State* operator->() const noexcept {
5079  return lua_state();
5080  }
5081 
5082  lua_State* lua_state() const noexcept {
5083  return L;
5084  }
5085  };
5086 
5087  struct new_table {
5088  int sequence_hint = 0;
5089  int map_hint = 0;
5090 
5091  new_table() = default;
5092  new_table(const new_table&) = default;
5093  new_table(new_table&&) = default;
5094  new_table& operator=(const new_table&) = default;
5095  new_table& operator=(new_table&&) = default;
5096 
5097  new_table(int sequence_hint, int map_hint = 0)
5098  : sequence_hint(sequence_hint), map_hint(map_hint) {
5099  }
5100  };
5101 
5102  enum class lib : char {
5103  // print, assert, and other base functions
5104  base,
5105  // require and other package functions
5106  package,
5107  // coroutine functions and utilities
5108  coroutine,
5109  // string library
5110  string,
5111  // functionality from the OS
5112  os,
5113  // all things math
5114  math,
5115  // the table manipulator and observer functions
5116  table,
5117  // the debug library
5118  debug,
5119  // the bit library: different based on which you're using
5120  bit32,
5121  // input/output library
5122  io,
5123  // LuaJIT only
5124  ffi,
5125  // LuaJIT only
5126  jit,
5127  // library for handling utf8: new to Lua
5128  utf8,
5129  // do not use
5130  count
5131  };
5132 
5133  enum class call_syntax {
5134  dot = 0,
5135  colon = 1
5136  };
5137 
5138  enum class load_mode {
5139  any = 0,
5140  text = 1,
5141  binary = 2,
5142  };
5143 
5144  enum class call_status : int {
5145  ok = LUA_OK,
5146  yielded = LUA_YIELD,
5147  runtime = LUA_ERRRUN,
5148  memory = LUA_ERRMEM,
5149  handler = LUA_ERRERR,
5150  gc = LUA_ERRGCMM,
5151  syntax = LUA_ERRSYNTAX,
5152  file = LUA_ERRFILE,
5153  };
5154 
5155  enum class thread_status : int {
5156  ok = LUA_OK,
5157  yielded = LUA_YIELD,
5158  runtime = LUA_ERRRUN,
5159  memory = LUA_ERRMEM,
5160  gc = LUA_ERRGCMM,
5161  handler = LUA_ERRERR,
5162  dead = -1,
5163  };
5164 
5165  enum class load_status : int {
5166  ok = LUA_OK,
5167  syntax = LUA_ERRSYNTAX,
5168  memory = LUA_ERRMEM,
5169  gc = LUA_ERRGCMM,
5170  file = LUA_ERRFILE,
5171  };
5172 
5173  enum class type : int {
5174  none = LUA_TNONE,
5175  lua_nil = LUA_TNIL,
5176 #if !defined(SOL_NO_NIL)
5177  nil = lua_nil,
5178 #endif // Objective C/C++ Keyword that's found in OSX SDK and OBJC -- check for all forms to protect
5179  string = LUA_TSTRING,
5180  number = LUA_TNUMBER,
5181  thread = LUA_TTHREAD,
5182  boolean = LUA_TBOOLEAN,
5183  function = LUA_TFUNCTION,
5184  userdata = LUA_TUSERDATA,
5185  lightuserdata = LUA_TLIGHTUSERDATA,
5186  table = LUA_TTABLE,
5187  poly = -0xFFFF
5188  };
5189 
5190  inline const std::string& to_string(call_status c) {
5191  static const std::array<std::string, 10> names{ { "ok",
5192  "yielded",
5193  "runtime",
5194  "memory",
5195  "handler",
5196  "gc",
5197  "syntax",
5198  "file",
5199  "CRITICAL_EXCEPTION_FAILURE",
5200  "CRITICAL_INDETERMINATE_STATE_FAILURE" } };
5201  switch (c) {
5202  case call_status::ok:
5203  return names[0];
5204  case call_status::yielded:
5205  return names[1];
5206  case call_status::runtime:
5207  return names[2];
5208  case call_status::memory:
5209  return names[3];
5210  case call_status::handler:
5211  return names[4];
5212  case call_status::gc:
5213  return names[5];
5214  case call_status::syntax:
5215  return names[6];
5216  case call_status::file:
5217  return names[7];
5218  }
5219  if (static_cast<std::ptrdiff_t>(c) == -1) {
5220  // One of the many cases where a critical exception error has occurred
5221  return names[8];
5222  }
5223  return names[9];
5224  }
5225 
5227  switch (c) {
5228  case call_status::ok:
5229  case call_status::yielded:
5230  case call_status::runtime:
5231  case call_status::memory:
5232  case call_status::handler:
5233  case call_status::gc:
5234  case call_status::syntax:
5235  case call_status::file:
5236  return false;
5237  }
5238  return true;
5239  }
5240 
5241  inline const std::string& to_string(load_status c) {
5242  static const std::array<std::string, 7> names{ { "ok",
5243  "memory",
5244  "gc",
5245  "syntax",
5246  "file",
5247  "CRITICAL_EXCEPTION_FAILURE",
5248  "CRITICAL_INDETERMINATE_STATE_FAILURE" } };
5249  switch (c) {
5250  case load_status::ok:
5251  return names[0];
5252  case load_status::memory:
5253  return names[1];
5254  case load_status::gc:
5255  return names[2];
5256  case load_status::syntax:
5257  return names[3];
5258  case load_status::file:
5259  return names[4];
5260  }
5261  if (static_cast<int>(c) == -1) {
5262  // One of the many cases where a critical exception error has occurred
5263  return names[5];
5264  }
5265  return names[6];
5266  }
5267 
5268  inline const std::string& to_string(load_mode c) {
5269  static const std::array<std::string, 3> names{ {
5270  "bt",
5271  "t",
5272  "b",
5273  } };
5274  return names[static_cast<std::size_t>(c)];
5275  }
5276 
5277  enum class meta_function {
5278  construct,
5279  index,
5280  new_index,
5281  mode,
5282  call,
5283  call_function = call,
5284  metatable,
5285  to_string,
5286  length,
5287  unary_minus,
5288  addition,
5289  subtraction,
5291  division,
5292  modulus,
5293  power_of,
5294  involution = power_of,
5295  concatenation,
5296  equal_to,
5297  less_than,
5303  bitwise_not,
5304  bitwise_and,
5305  bitwise_or,
5306  bitwise_xor,
5307  pairs,
5308  ipairs,
5309  next,
5310  type,
5311  type_info,
5312  };
5313 
5315 
5316  inline const std::array<std::string, 32>& meta_function_names() {
5317  static const std::array<std::string, 32> names = { { "new",
5318  "__index",
5319  "__newindex",
5320  "__mode",
5321  "__call",
5322  "__mt",
5323  "__tostring",
5324  "__len",
5325  "__unm",
5326  "__add",
5327  "__sub",
5328  "__mul",
5329  "__div",
5330  "__mod",
5331  "__pow",
5332  "__concat",
5333  "__eq",
5334  "__lt",
5335  "__le",
5336  "__gc",
5337 
5338  "__idiv",
5339  "__shl",
5340  "__shr",
5341  "__bnot",
5342  "__band",
5343  "__bor",
5344  "__bxor",
5345 
5346  "__pairs",
5347  "__ipairs",
5348  "next",
5349  "__type",
5350  "__typeinfo" } };
5351  return names;
5352  }
5353 
5355  return meta_function_names()[static_cast<int>(mf)];
5356  }
5357 
5358  inline type type_of(lua_State* L, int index) {
5359  return static_cast<type>(lua_type(L, index));
5360  }
5361 
5362  inline std::string type_name(lua_State* L, type t) {
5363  return lua_typename(L, static_cast<int>(t));
5364  }
5365 
5366  template <typename T>
5367  struct is_lua_reference : std::integral_constant<bool,
5368  std::is_base_of<reference, meta::unqualified_t<T>>::value
5369  || std::is_base_of<main_reference, meta::unqualified_t<T>>::value
5370  || std::is_base_of<stack_reference, meta::unqualified_t<T>>::value> {};
5371 
5372  template <typename T>
5373  struct is_lua_reference_or_proxy : std::integral_constant<bool,
5374  is_lua_reference<meta::unqualified_t<T>>::value
5375  || meta::is_specialization_of<meta::unqualified_t<T>, proxy>::value> {};
5376 
5377  template <typename T>
5378  struct is_transparent_argument : std::false_type {};
5379  template <>
5380  struct is_transparent_argument<this_state> : std::true_type {};
5381  template <>
5382  struct is_transparent_argument<this_main_state> : std::true_type {};
5383  template <>
5384  struct is_transparent_argument<this_environment> : std::true_type {};
5385  template <>
5386  struct is_transparent_argument<variadic_args> : std::true_type {};
5387  template <typename T>
5388  struct is_variadic_arguments : std::is_same<meta::unqualified_t<T>, variadic_args> {};
5389 
5390  namespace detail {
5391  template <typename T>
5392  struct is_initializer_list : std::false_type {};
5393 
5394  template <typename T>
5395  struct is_initializer_list<std::initializer_list<T>> : std::true_type {};
5396 
5397  template <typename T, typename C = void>
5398  struct is_container : std::false_type {};
5399 
5400  template <typename T>
5401  struct is_container<std::initializer_list<T>> : std::false_type {};
5402 
5403  template <typename T>
5404  struct is_container<T, std::enable_if_t<meta::is_string_like<meta::unqualified_t<T>>::value>> : std::false_type {};
5405 
5406  template <typename T>
5407  struct is_container<T, std::enable_if_t<meta::all<std::is_array<meta::unqualified_t<T>>, meta::neg<meta::any_same<std::remove_all_extents_t<meta::unqualified_t<T>>, char, wchar_t, char16_t, char32_t>>>::value>> : std::true_type {};
5408 
5409  template <typename T>
5410  struct is_container<T, std::enable_if_t<meta::all<meta::has_begin_end<meta::unqualified_t<T>>, meta::neg<is_initializer_list<meta::unqualified_t<T>>>, meta::neg<meta::is_string_like<meta::unqualified_t<T>>>>::value>> : std::true_type {};
5411  } // namespace detail
5412 
5413  template <typename T>
5415 
5416  template <typename T>
5417  struct is_to_stringable : meta::any<meta::supports_to_string_member<meta::unqualified_t<T>>, meta::supports_adl_to_string<meta::unqualified_t<T>>, meta::supports_ostream_op<meta::unqualified_t<T>>> {};
5418 
5419  namespace detail {
5420  template <typename T, typename = void>
5421  struct lua_type_of : std::integral_constant<type, type::userdata> {};
5422 
5423  template <typename C, typename T, typename A>
5424  struct lua_type_of<std::basic_string<C, T, A>> : std::integral_constant<type, type::string> {};
5425 
5426  template <typename C, typename T>
5427  struct lua_type_of<basic_string_view<C, T>> : std::integral_constant<type, type::string> {};
5428 
5429  template <std::size_t N>
5430  struct lua_type_of<char[N]> : std::integral_constant<type, type::string> {};
5431 
5432  template <std::size_t N>
5433  struct lua_type_of<wchar_t[N]> : std::integral_constant<type, type::string> {};
5434 
5435  template <std::size_t N>
5436  struct lua_type_of<char16_t[N]> : std::integral_constant<type, type::string> {};
5437 
5438  template <std::size_t N>
5439  struct lua_type_of<char32_t[N]> : std::integral_constant<type, type::string> {};
5440 
5441  template <>
5442  struct lua_type_of<char> : std::integral_constant<type, type::string> {};
5443 
5444  template <>
5445  struct lua_type_of<wchar_t> : std::integral_constant<type, type::string> {};
5446 
5447  template <>
5448  struct lua_type_of<char16_t> : std::integral_constant<type, type::string> {};
5449 
5450  template <>
5451  struct lua_type_of<char32_t> : std::integral_constant<type, type::string> {};
5452 
5453  template <>
5454  struct lua_type_of<const char*> : std::integral_constant<type, type::string> {};
5455 
5456  template <>
5457  struct lua_type_of<const char16_t*> : std::integral_constant<type, type::string> {};
5458 
5459  template <>
5460  struct lua_type_of<const char32_t*> : std::integral_constant<type, type::string> {};
5461 
5462  template <>
5463  struct lua_type_of<bool> : std::integral_constant<type, type::boolean> {};
5464 
5465  template <>
5466  struct lua_type_of<lua_nil_t> : std::integral_constant<type, type::lua_nil> {};
5467 
5468  template <>
5469  struct lua_type_of<nullopt_t> : std::integral_constant<type, type::lua_nil> {};
5470 
5471  template <>
5472  struct lua_type_of<detail::non_lua_nil_t> : std::integral_constant<type, type::poly> {};
5473 
5474  template <>
5475  struct lua_type_of<std::nullptr_t> : std::integral_constant<type, type::lua_nil> {};
5476 
5477  template <>
5478  struct lua_type_of<error> : std::integral_constant<type, type::string> {};
5479 
5480  template <bool b, typename Base>
5481  struct lua_type_of<basic_table_core<b, Base>> : std::integral_constant<type, type::table> {};
5482 
5483  template <>
5484  struct lua_type_of<metatable_t> : std::integral_constant<type, type::table> {};
5485 
5486  template <typename B>
5487  struct lua_type_of<basic_environment<B>> : std::integral_constant<type, type::poly> {};
5488 
5489  template <>
5490  struct lua_type_of<env_t> : std::integral_constant<type, type::poly> {};
5491 
5492  template <>
5493  struct lua_type_of<new_table> : std::integral_constant<type, type::table> {};
5494 
5495  template <typename T>
5496  struct lua_type_of<as_table_t<T>> : std::integral_constant<type, type::table> {};
5497 
5498  template <typename T>
5499  struct lua_type_of<std::initializer_list<T>> : std::integral_constant<type, type::table> {};
5500 
5501  template <bool b>
5502  struct lua_type_of<basic_reference<b>> : std::integral_constant<type, type::poly> {};
5503 
5504  template <>
5505  struct lua_type_of<stack_reference> : std::integral_constant<type, type::poly> {};
5506 
5507  template <typename Base>
5508  struct lua_type_of<basic_object<Base>> : std::integral_constant<type, type::poly> {};
5509 
5510  template <typename... Args>
5511  struct lua_type_of<std::tuple<Args...>> : std::integral_constant<type, type::poly> {};
5512 
5513  template <typename A, typename B>
5514  struct lua_type_of<std::pair<A, B>> : std::integral_constant<type, type::poly> {};
5515 
5516  template <>
5517  struct lua_type_of<void*> : std::integral_constant<type, type::lightuserdata> {};
5518 
5519  template <>
5520  struct lua_type_of<const void*> : std::integral_constant<type, type::lightuserdata> {};
5521 
5522  template <>
5523  struct lua_type_of<lightuserdata_value> : std::integral_constant<type, type::lightuserdata> {};
5524 
5525  template <>
5526  struct lua_type_of<userdata_value> : std::integral_constant<type, type::userdata> {};
5527 
5528  template <typename T>
5529  struct lua_type_of<light<T>> : std::integral_constant<type, type::lightuserdata> {};
5530 
5531  template <typename T>
5532  struct lua_type_of<user<T>> : std::integral_constant<type, type::userdata> {};
5533 
5534  template <typename Base>
5535  struct lua_type_of<basic_lightuserdata<Base>> : std::integral_constant<type, type::lightuserdata> {};
5536 
5537  template <typename Base>
5538  struct lua_type_of<basic_userdata<Base>> : std::integral_constant<type, type::userdata> {};
5539 
5540  template <>
5541  struct lua_type_of<lua_CFunction> : std::integral_constant<type, type::function> {};
5542 
5543  template <>
5544  struct lua_type_of<std::remove_pointer_t<lua_CFunction>> : std::integral_constant<type, type::function> {};
5545 
5546  template <typename Base, bool aligned>
5547  struct lua_type_of<basic_function<Base, aligned>> : std::integral_constant<type, type::function> {};
5548 
5549  template <typename Base, bool aligned, typename Handler>
5550  struct lua_type_of<basic_protected_function<Base, aligned, Handler>> : std::integral_constant<type, type::function> {};
5551 
5552  template <typename Base>
5553  struct lua_type_of<basic_coroutine<Base>> : std::integral_constant<type, type::function> {};
5554 
5555  template <typename Base>
5556  struct lua_type_of<basic_thread<Base>> : std::integral_constant<type, type::thread> {};
5557 
5558  template <typename Signature>
5559  struct lua_type_of<std::function<Signature>> : std::integral_constant<type, type::function> {};
5560 
5561  template <typename T>
5562  struct lua_type_of<optional<T>> : std::integral_constant<type, type::poly> {};
5563 
5564 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
5565  template <typename T>
5566  struct lua_type_of<std::optional<T>> : std::integral_constant<type, type::poly> {};
5567 #endif // std::optional
5568 
5569  template <>
5570  struct lua_type_of<variadic_args> : std::integral_constant<type, type::poly> {};
5571 
5572  template <>
5573  struct lua_type_of<variadic_results> : std::integral_constant<type, type::poly> {};
5574 
5575  template <>
5576  struct lua_type_of<stack_count> : std::integral_constant<type, type::poly> {};
5577 
5578  template <>
5579  struct lua_type_of<this_state> : std::integral_constant<type, type::poly> {};
5580 
5581  template <>
5582  struct lua_type_of<this_main_state> : std::integral_constant<type, type::poly> {};
5583 
5584  template <>
5585  struct lua_type_of<this_environment> : std::integral_constant<type, type::poly> {};
5586 
5587  template <>
5588  struct lua_type_of<type> : std::integral_constant<type, type::poly> {};
5589 
5590  template <typename T>
5591  struct lua_type_of<T*> : std::integral_constant<type, type::userdata> {};
5592 
5593  template <typename T>
5594  struct lua_type_of<T, std::enable_if_t<std::is_arithmetic<T>::value>> : std::integral_constant<type, type::number> {};
5595 
5596  template <typename T>
5597  struct lua_type_of<T, std::enable_if_t<std::is_enum<T>::value>> : std::integral_constant<type, type::number> {};
5598 
5599  template <>
5600  struct lua_type_of<meta_function> : std::integral_constant<type, type::string> {};
5601 
5602 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
5603 #ifdef SOL_STD_VARIANT
5604  template <typename... Tn>
5605  struct lua_type_of<std::variant<Tn...>> : std::integral_constant<type, type::poly> {};
5606 #endif // SOL_STD_VARIANT
5607 #endif // SOL_CXX17_FEATURES
5608 
5609  template <typename T>
5610  struct lua_type_of<nested<T>, std::enable_if_t<::sol::is_container<T>::value>> : std::integral_constant<type, type::table> {};
5611 
5612  template <typename T>
5613  struct lua_type_of<nested<T>, std::enable_if_t<!::sol::is_container<T>::value>> : lua_type_of<T> {};
5614 
5615  template <typename C, C v, template <typename...> class V, typename... Args>
5616  struct accumulate : std::integral_constant<C, v> {};
5617 
5618  template <typename C, C v, template <typename...> class V, typename T, typename... Args>
5619  struct accumulate<C, v, V, T, Args...> : accumulate<C, v + V<T>::value, V, Args...> {};
5620 
5621  template <typename C, C v, template <typename...> class V, typename List>
5623 
5624  template <typename C, C v, template <typename...> class V, typename... Args>
5625  struct accumulate_list<C, v, V, types<Args...>> : accumulate<C, v, V, Args...> {};
5626  } // namespace detail
5627 
5628  template <typename T>
5629  struct is_unique_usertype : std::integral_constant<bool, unique_usertype_traits<T>::value> {};
5630 
5631  template <typename T>
5634  };
5635 
5636  template <typename T>
5637  struct lua_size : std::integral_constant<int, 1> {
5639  };
5640 
5641  template <typename A, typename B>
5642  struct lua_size<std::pair<A, B>> : std::integral_constant<int, lua_size<A>::value + lua_size<B>::value> {};
5643 
5644  template <typename... Args>
5645  struct lua_size<std::tuple<Args...>> : std::integral_constant<int, detail::accumulate<int, 0, lua_size, Args...>::value> {};
5646 
5647  namespace detail {
5648  template <typename...>
5649  struct void_ { typedef void type; };
5650  template <typename T, typename = void>
5651  struct has_internal_marker_impl : std::false_type {};
5652  template <typename T>
5654 
5655  template <typename T>
5657  } // namespace detail
5658 
5659  template <typename T>
5660  struct is_lua_primitive : std::integral_constant<bool,
5661  type::userdata != lua_type_of<meta::unqualified_t<T>>::value
5662  || ((type::userdata == lua_type_of<meta::unqualified_t<T>>::value)
5663  && detail::has_internal_marker<lua_type_of<meta::unqualified_t<T>>>::value
5664  && !detail::has_internal_marker<lua_size<meta::unqualified_t<T>>>::value)
5665  || is_lua_reference<meta::unqualified_t<T>>::value
5666  || meta::is_specialization_of<meta::unqualified_t<T>, std::tuple>::value
5667  || meta::is_specialization_of<meta::unqualified_t<T>, std::pair>::value> {};
5668 
5669  template <typename T>
5670  struct is_main_threaded : std::is_base_of<main_reference, T> {};
5671 
5672  template <typename T>
5673  struct is_stack_based : std::is_base_of<stack_reference, T> {};
5674  template <>
5675  struct is_stack_based<variadic_args> : std::true_type {};
5676  template <>
5677  struct is_stack_based<unsafe_function_result> : std::true_type {};
5678  template <>
5679  struct is_stack_based<protected_function_result> : std::true_type {};
5680  template <>
5681  struct is_stack_based<stack_proxy> : std::true_type {};
5682  template <>
5683  struct is_stack_based<stack_proxy_base> : std::true_type {};
5684 
5685  template <typename T>
5686  struct is_lua_primitive<T*> : std::true_type {};
5687  template <>
5688  struct is_lua_primitive<unsafe_function_result> : std::true_type {};
5689  template <>
5690  struct is_lua_primitive<protected_function_result> : std::true_type {};
5691  template <typename T>
5692  struct is_lua_primitive<std::reference_wrapper<T>> : std::true_type {};
5693  template <typename T>
5694  struct is_lua_primitive<user<T>> : std::true_type {};
5695  template <typename T>
5697  template <typename T>
5698  struct is_lua_primitive<optional<T>> : std::true_type {};
5699 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
5700  template <typename T>
5701  struct is_lua_primitive<std::optional<T>> : std::true_type {};
5702 #endif
5703  template <typename T>
5704  struct is_lua_primitive<as_table_t<T>> : std::true_type {};
5705  template <typename T>
5706  struct is_lua_primitive<nested<T>> : std::true_type {};
5707  template <>
5708  struct is_lua_primitive<userdata_value> : std::true_type {};
5709  template <>
5710  struct is_lua_primitive<lightuserdata_value> : std::true_type {};
5711  template <typename T>
5713 
5714  template <typename T>
5716 
5717  template <typename T>
5718  struct is_lua_index : std::is_integral<T> {};
5719  template <>
5720  struct is_lua_index<raw_index> : std::true_type {};
5721  template <>
5722  struct is_lua_index<absolute_index> : std::true_type {};
5723  template <>
5724  struct is_lua_index<ref_index> : std::true_type {};
5725  template <>
5726  struct is_lua_index<upvalue_index> : std::true_type {};
5727 
5728  template <typename Signature>
5729  struct lua_bind_traits : meta::bind_traits<Signature> {
5730  private:
5732 
5733  public:
5734  typedef std::integral_constant<bool, meta::count_for<is_variadic_arguments, typename base_t::args_list>::value != 0> runtime_variadics_t;
5735  static const std::size_t true_arity = base_t::arity;
5737  static const std::size_t true_free_arity = base_t::free_arity;
5738  static const std::size_t free_arity = detail::accumulate_list<std::size_t, 0, lua_size, typename base_t::free_args_list>::value - meta::count_for<is_transparent_argument, typename base_t::args_list>::value;
5739  };
5740 
5741  template <typename T>
5742  struct is_table : std::false_type {};
5743  template <bool x, typename T>
5744  struct is_table<basic_table_core<x, T>> : std::true_type {};
5745 
5746  template <typename T>
5747  struct is_function : std::false_type {};
5748  template <typename T, bool aligned>
5749  struct is_function<basic_function<T, aligned>> : std::true_type {};
5750  template <typename T, bool aligned, typename Handler>
5751  struct is_function<basic_protected_function<T, aligned, Handler>> : std::true_type {};
5752 
5753  template <typename T>
5754  struct is_lightuserdata : std::false_type {};
5755  template <typename T>
5756  struct is_lightuserdata<basic_lightuserdata<T>> : std::true_type {};
5757 
5758  template <typename T>
5759  struct is_userdata : std::false_type {};
5760  template <typename T>
5761  struct is_userdata<basic_userdata<T>> : std::true_type {};
5762 
5763  template <typename T>
5764  struct is_environment : std::integral_constant<bool, is_userdata<T>::value || is_table<T>::value> {};
5765 
5766  template <typename T>
5767  struct is_automagical : meta::neg<std::is_array<meta::unqualified_t<T>>> {};
5768 
5769  template <typename T>
5770  inline type type_of() {
5771  return lua_type_of<meta::unqualified_t<T>>::value;
5772  }
5773 
5774  namespace detail {
5775  template <typename T>
5776  struct is_non_factory_constructor : std::false_type {};
5777 
5778  template <typename... Args>
5779  struct is_non_factory_constructor<constructors<Args...>> : std::true_type {};
5780 
5781  template <typename... Args>
5782  struct is_non_factory_constructor<constructor_wrapper<Args...>> : std::true_type {};
5783 
5784  template <>
5785  struct is_non_factory_constructor<no_construction> : std::true_type {};
5786 
5787  template <typename T>
5789 
5790  template <typename... Args>
5791  struct is_constructor<factory_wrapper<Args...>> : std::true_type {};
5792 
5793  template <typename T>
5794  struct is_constructor<protect_t<T>> : is_constructor<meta::unqualified_t<T>> {};
5795 
5796  template <typename F, typename... Filters>
5797  struct is_constructor<filter_wrapper<F, Filters...>> : is_constructor<meta::unqualified_t<F>> {};
5798 
5799  template <typename... Args>
5801 
5802  template <typename T>
5803  struct is_destructor : std::false_type {};
5804 
5805  template <typename Fx>
5806  struct is_destructor<destructor_wrapper<Fx>> : std::true_type {};
5807 
5808  template <typename... Args>
5810 
5813  struct verified_tag {
5814  } const verified{};
5815  } // namespace detail
5816 } // namespace sol
5817 
5818 // end of sol/types.hpp
5819 
5820 #include <exception>
5821 #include <cstring>
5822 
5823 #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
5824 #include <iostream>
5825 #endif
5826 
5827 namespace sol {
5828  // must push a single object to be the error object
5829  // NOTE: the VAST MAJORITY of all Lua libraries -- C or otherwise -- expect a string for the type of error
5830  // break this convention at your own risk
5832 
5833  namespace detail {
5834  inline const char(&default_exception_handler_name())[11]{
5835  static const char name[11] = "sol.\xE2\x98\xA2\xE2\x98\xA2";
5836  return name;
5837  }
5838 
5839  // must push at least 1 object on the stack
5840  inline int default_exception_handler(lua_State* L, optional<const std::exception&>, string_view what) {
5841 #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
5842  std::cerr << "[sol2] An exception occurred: ";
5843  std::cerr.write(what.data(), what.size());
5844  std::cerr << std::endl;
5845 #endif
5846  lua_pushlstring(L, what.data(), what.size());
5847  return 1;
5848  }
5849 
5850  inline int call_exception_handler(lua_State* L, optional<const std::exception&> maybe_ex, string_view what) {
5851  lua_getglobal(L, default_exception_handler_name());
5852  type t = static_cast<type>(lua_type(L, -1));
5853  if (t != type::lightuserdata) {
5854  lua_pop(L, 1);
5855  return default_exception_handler(L, std::move(maybe_ex), std::move(what));
5856  }
5857  void* vfunc = lua_touserdata(L, -1);
5858  lua_pop(L, 1);
5859  if (vfunc == nullptr) {
5860  return default_exception_handler(L, std::move(maybe_ex), std::move(what));
5861  }
5862  exception_handler_function exfunc = reinterpret_cast<exception_handler_function>(vfunc);
5863  return exfunc(L, std::move(maybe_ex), std::move(what));
5864  }
5865 
5866 #ifdef SOL_NO_EXCEPTIONS
5867  template <lua_CFunction f>
5868  int static_trampoline(lua_State* L) noexcept {
5869  return f(L);
5870  }
5871 
5872 #ifdef SOL_NOEXCEPT_FUNCTION_TYPE
5873  template <lua_CFunction_noexcept f>
5874  int static_trampoline_noexcept(lua_State* L) noexcept {
5875  return f(L);
5876  }
5877 #else
5878  template <lua_CFunction f>
5879  int static_trampoline_noexcept(lua_State* L) noexcept {
5880  return f(L);
5881  }
5882 #endif
5883 
5884  template <typename Fx, typename... Args>
5885  int trampoline(lua_State* L, Fx&& f, Args&&... args) noexcept {
5886  return f(L, std::forward<Args>(args)...);
5887  }
5888 
5889  inline int c_trampoline(lua_State* L, lua_CFunction f) noexcept {
5890  return trampoline(L, f);
5891  }
5892 #else
5893  template <lua_CFunction f>
5894  int static_trampoline(lua_State* L) {
5895 #if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT)
5896  return f(L);
5897 
5898 #else
5899  try {
5900  return f(L);
5901  }
5902  catch (const char* cs) {
5903  call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(cs));
5904  }
5905  catch (const std::string& s) {
5906  call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(s.c_str(), s.size()));
5907  }
5908  catch (const std::exception& e) {
5909  call_exception_handler(L, optional<const std::exception&>(e), e.what());
5910  }
5911 #if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
5912  // LuaJIT cannot have the catchall when the safe propagation is on
5913  // but LuaJIT will swallow all C++ errors
5914  // if we don't at least catch std::exception ones
5915  catch (...) {
5916  call_exception_handler(L, optional<const std::exception&>(nullopt), "caught (...) exception");
5917  }
5918 #endif // LuaJIT cannot have the catchall, but we must catch std::exceps for it
5919  return lua_error(L);
5920 #endif // Safe exceptions
5921  }
5922 
5923 #ifdef SOL_NOEXCEPT_FUNCTION_TYPE
5924 #if 0
5925  // impossible: g++/clang++ choke as they think this function is ambiguous:
5926  // to fix, wait for template <auto X> and then switch on no-exceptness of the function
5927  template <lua_CFunction_noexcept f>
5928  int static_trampoline(lua_State* L) noexcept {
5929  return f(L);
5930  }
5931 #else
5932  template <lua_CFunction_noexcept f>
5933  int static_trampoline_noexcept(lua_State* L) noexcept {
5934  return f(L);
5935  }
5936 #endif // impossible
5937 
5938 #else
5939  template <lua_CFunction f>
5940  int static_trampoline_noexcept(lua_State* L) noexcept {
5941  return f(L);
5942  }
5943 #endif // noexcept lua_CFunction type
5944 
5945  template <typename Fx, typename... Args>
5946  int trampoline(lua_State* L, Fx&& f, Args&&... args) {
5947  if (meta::bind_traits<meta::unqualified_t<Fx>>::is_noexcept) {
5948  return f(L, std::forward<Args>(args)...);
5949  }
5950 #if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT)
5951  return f(L, std::forward<Args>(args)...);
5952 #else
5953  try {
5954  return f(L, std::forward<Args>(args)...);
5955  }
5956  catch (const char* cs) {
5957  call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(cs));
5958  }
5959  catch (const std::string& s) {
5960  call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(s.c_str(), s.size()));
5961  }
5962  catch (const std::exception& e) {
5963  call_exception_handler(L, optional<const std::exception&>(e), e.what());
5964  }
5965 #if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
5966  // LuaJIT cannot have the catchall when the safe propagation is on
5967  // but LuaJIT will swallow all C++ errors
5968  // if we don't at least catch std::exception ones
5969  catch (...) {
5970  call_exception_handler(L, optional<const std::exception&>(nullopt), "caught (...) exception");
5971  }
5972 #endif
5973  return lua_error(L);
5974 #endif
5975  }
5976 
5977  inline int c_trampoline(lua_State* L, lua_CFunction f) {
5978  return trampoline(L, f);
5979  }
5980 #endif // Exceptions vs. No Exceptions
5981 
5982  template <typename F, F fx>
5983  inline int typed_static_trampoline_raw(std::true_type, lua_State* L) {
5984  return static_trampoline_noexcept<fx>(L);
5985  }
5986 
5987  template <typename F, F fx>
5988  inline int typed_static_trampoline_raw(std::false_type, lua_State* L) {
5989  return static_trampoline<fx>(L);
5990  }
5991 
5992  template <typename F, F fx>
5993  inline int typed_static_trampoline(lua_State* L) {
5994  return typed_static_trampoline_raw<F, fx>(std::integral_constant<bool, meta::bind_traits<F>::is_noexcept>(), L);
5995  }
5996  } // namespace detail
5997 
5999  static_assert(sizeof(void*) >= sizeof(exception_handler_function), "void* storage is too small to transport the exception handler: please file a bug on the issue tracker");
6000  void* storage;
6001  std::memcpy(&storage, &exf, sizeof(exception_handler_function));
6002  lua_pushlightuserdata(L, storage);
6003  lua_setglobal(L, detail::default_exception_handler_name());
6004  }
6005 } // sol
6006 
6007 // end of sol/trampoline.hpp
6008 
6009 // beginning of sol/stack_core.hpp
6010 
6011 // beginning of sol/inheritance.hpp
6012 
6013 // beginning of sol/usertype_traits.hpp
6014 
6015 // beginning of sol/demangle.hpp
6016 
6017 #include <cctype>
6018 #if defined(__GNUC__) && defined(__MINGW32__) && (__GNUC__ < 6)
6019 extern "C" {
6020 }
6021 #endif // MinGW is on some stuff
6022 #include <locale>
6023 
6024 namespace sol {
6025 namespace detail {
6026 #if defined(__GNUC__) || defined(__clang__)
6027  template <typename T, class seperator_mark = int>
6028  inline std::string ctti_get_type_name() {
6029  // cardinal sins from MINGW
6030  using namespace std;
6031  static const std::array<std::string, 2> removals = {{"{anonymous}", "(anonymous namespace)"}};
6032  std::string name = __PRETTY_FUNCTION__;
6033  std::size_t start = name.find_first_of('[');
6034  start = name.find_first_of('=', start);
6035  std::size_t end = name.find_last_of(']');
6036  if (end == std::string::npos)
6037  end = name.size();
6038  if (start == std::string::npos)
6039  start = 0;
6040  if (start < name.size() - 1)
6041  start += 1;
6042  name = name.substr(start, end - start);
6043  start = name.rfind("seperator_mark");
6044  if (start != std::string::npos) {
6045  name.erase(start - 2, name.length());
6046  }
6047  while (!name.empty() && isblank(name.front()))
6048  name.erase(name.begin());
6049  while (!name.empty() && isblank(name.back()))
6050  name.pop_back();
6051 
6052  for (std::size_t r = 0; r < removals.size(); ++r) {
6053  auto found = name.find(removals[r]);
6054  while (found != std::string::npos) {
6055  name.erase(found, removals[r].size());
6056  found = name.find(removals[r]);
6057  }
6058  }
6059 
6060  return name;
6061  }
6062 #elif defined(_MSC_VER)
6063  template <typename T>
6064  inline std::string ctti_get_type_name() {
6065  static const std::array<std::string, 7> removals = {{"public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'"}};
6066  std::string name = __FUNCSIG__;
6067  std::size_t start = name.find("get_type_name");
6068  if (start == std::string::npos)
6069  start = 0;
6070  else
6071  start += 13;
6072  if (start < name.size() - 1)
6073  start += 1;
6074  std::size_t end = name.find_last_of('>');
6075  if (end == std::string::npos)
6076  end = name.size();
6077  name = name.substr(start, end - start);
6078  if (name.find("struct", 0) == 0)
6079  name.replace(0, 6, "", 0);
6080  if (name.find("class", 0) == 0)
6081  name.replace(0, 5, "", 0);
6082  while (!name.empty() && isblank(name.front()))
6083  name.erase(name.begin());
6084  while (!name.empty() && isblank(name.back()))
6085  name.pop_back();
6086 
6087  for (std::size_t r = 0; r < removals.size(); ++r) {
6088  auto found = name.find(removals[r]);
6089  while (found != std::string::npos) {
6090  name.erase(found, removals[r].size());
6091  found = name.find(removals[r]);
6092  }
6093  }
6094 
6095  return name;
6096  }
6097 #else
6098 #error Compiler not supported for demangling
6099 #endif // compilers
6100 
6101  template <typename T>
6103  std::string realname = ctti_get_type_name<T>();
6104  return realname;
6105  }
6106 
6107  template <typename T>
6109  std::string realname = ctti_get_type_name<T>();
6110  // This isn't the most complete but it'll do for now...?
6111  static const std::array<std::string, 10> ops = {{"operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*"}};
6112  int level = 0;
6113  std::ptrdiff_t idx = 0;
6114  for (idx = static_cast<std::ptrdiff_t>(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) {
6115  if (level == 0 && realname[idx] == ':') {
6116  break;
6117  }
6118  bool isleft = realname[idx] == '<';
6119  bool isright = realname[idx] == '>';
6120  if (!isleft && !isright)
6121  continue;
6122  bool earlybreak = false;
6123  for (const auto& op : ops) {
6124  std::size_t nisop = realname.rfind(op, idx);
6125  if (nisop == std::string::npos)
6126  continue;
6127  std::size_t nisopidx = idx - op.size() + 1;
6128  if (nisop == nisopidx) {
6129  idx = static_cast<std::ptrdiff_t>(nisopidx);
6130  earlybreak = true;
6131  }
6132  break;
6133  }
6134  if (earlybreak) {
6135  continue;
6136  }
6137  level += isleft ? -1 : 1;
6138  }
6139  if (idx > 0) {
6140  realname.erase(0, realname.length() < static_cast<std::size_t>(idx) ? realname.length() : idx + 1);
6141  }
6142  return realname;
6143  }
6144 
6145  template <typename T>
6146  inline const std::string& demangle() {
6147  static const std::string d = demangle_once<T>();
6148  return d;
6149  }
6150 
6151  template <typename T>
6152  inline const std::string& short_demangle() {
6153  static const std::string d = short_demangle_once<T>();
6154  return d;
6155  }
6156 }
6157 } // namespace sol::detail
6158 
6159 // end of sol/demangle.hpp
6160 
6161 namespace sol {
6162 
6163  template <typename T>
6164  struct usertype_traits {
6165  static const std::string& name() {
6166  static const std::string& n = detail::short_demangle<T>();
6167  return n;
6168  }
6169  static const std::string& qualified_name() {
6170  static const std::string& q_n = detail::demangle<T>();
6171  return q_n;
6172  }
6173  static const std::string& metatable() {
6174  static const std::string m = std::string("sol.").append(detail::demangle<T>());
6175  return m;
6176  }
6177  static const std::string& user_metatable() {
6178  static const std::string u_m = std::string("sol.").append(detail::demangle<T>()).append(".user");
6179  return u_m;
6180  }
6181  static const std::string& user_gc_metatable() {
6182  static const std::string u_g_m = std::string("sol.").append(detail::demangle<T>()).append(".user\xE2\x99\xBB");
6183  return u_g_m;
6184  }
6185  static const std::string& gc_table() {
6186  static const std::string g_t = std::string("sol.").append(detail::demangle<T>()).append(".\xE2\x99\xBB");
6187  return g_t;
6188  }
6189  };
6190 
6191 } // namespace sol
6192 
6193 // end of sol/usertype_traits.hpp
6194 
6195 namespace sol {
6196  template <typename... Args>
6197  struct base_list {};
6198  template <typename... Args>
6199  using bases = base_list<Args...>;
6200 
6203 
6204  namespace detail {
6205 
6206  template <typename T>
6207  struct has_derived {
6208  static bool value;
6209  };
6210 
6211  template <typename T>
6212  bool has_derived<T>::value = false;
6213 
6214  inline decltype(auto) base_class_check_key() {
6215  static const auto& key = "class_check";
6216  return key;
6217  }
6218 
6219  inline decltype(auto) base_class_cast_key() {
6220  static const auto& key = "class_cast";
6221  return key;
6222  }
6223 
6224  inline decltype(auto) base_class_index_propogation_key() {
6225  static const auto& key = u8"\xF0\x9F\x8C\xB2.index";
6226  return key;
6227  }
6228 
6229  inline decltype(auto) base_class_new_index_propogation_key() {
6230  static const auto& key = u8"\xF0\x9F\x8C\xB2.new_index";
6231  return key;
6232  }
6233 
6234  template <typename T, typename... Bases>
6235  struct inheritance {
6236  static bool type_check_bases(types<>, const std::string&) {
6237  return false;
6238  }
6239 
6240  template <typename Base, typename... Args>
6242  return ti == usertype_traits<Base>::qualified_name() || type_check_bases(types<Args...>(), ti);
6243  }
6244 
6245  static bool type_check(const std::string& ti) {
6246  return ti == usertype_traits<T>::qualified_name() || type_check_bases(types<Bases...>(), ti);
6247  }
6248 
6249  static void* type_cast_bases(types<>, T*, const std::string&) {
6250  return nullptr;
6251  }
6252 
6253  template <typename Base, typename... Args>
6254  static void* type_cast_bases(types<Base, Args...>, T* data, const std::string& ti) {
6255  // Make sure to convert to T first, and then dynamic cast to the proper type
6256  return ti != usertype_traits<Base>::qualified_name() ? type_cast_bases(types<Args...>(), data, ti) : static_cast<void*>(static_cast<Base*>(data));
6257  }
6258 
6259  static void* type_cast(void* voiddata, const std::string& ti) {
6260  T* data = static_cast<T*>(voiddata);
6261  return static_cast<void*>(ti != usertype_traits<T>::qualified_name() ? type_cast_bases(types<Bases...>(), data, ti) : data);
6262  }
6263 
6264  template <typename U>
6265  static bool type_unique_cast_bases(void*, void*, const string_view&) {
6266  return false;
6267  }
6268 
6269  template <typename U, typename Base, typename... Args>
6270  static bool type_unique_cast_bases(void* source_data, void* target_data, const string_view& ti) {
6271  typedef unique_usertype_traits<U> uu_traits;
6272  typedef typename uu_traits::template rebind_base<Base> base_ptr;
6274  if (base_ti == ti) {
6275  if (target_data != nullptr) {
6276  U* source = static_cast<U*>(source_data);
6277  base_ptr* target = static_cast<base_ptr*>(target_data);
6278  // perform proper derived -> base conversion
6279  *target = *source;
6280  }
6281  return true;
6282  }
6283  return type_unique_cast_bases<U, Args...>(source_data, target_data, ti);
6284  }
6285 
6286  template <typename U>
6287  static bool type_unique_cast(void* source_data, void* target_data, const string_view& ti, const string_view& rebind_ti) {
6288  typedef unique_usertype_traits<U> uu_traits;
6289  typedef typename uu_traits::template rebind_base<T> rebind_t;
6291  if (rebind_ti != this_rebind_ti) {
6292  // this is not even of the same container type
6293  return false;
6294  }
6295  return type_unique_cast_bases<U, Bases...>(source_data, target_data, ti);
6296  }
6297  };
6298 
6302  } // namespace detail
6303 } // namespace sol
6304 
6305 // end of sol/inheritance.hpp
6306 
6307 // beginning of sol/error_handler.hpp
6308 
6309 namespace sol {
6310 
6311  inline std::string associated_type_name(lua_State* L, int index, type t) {
6312  switch (t) {
6313  case type::poly:
6314  return "anything";
6315  case type::userdata:
6316  {
6317  if (lua_getmetatable(L, index) == 0) {
6318  break;
6319  }
6320  lua_pushlstring(L, "__name", 6);
6321  lua_rawget(L, -2);
6322  size_t sz;
6323  const char* name = lua_tolstring(L, -1, &sz);
6324  std::string tn(name, static_cast<std::string::size_type>(sz));
6325  lua_pop(L, 2);
6326  return name;
6327  }
6328  default:
6329  break;
6330  }
6331  return lua_typename(L, static_cast<int>(t));
6332  }
6333 
6334  inline int type_panic_string(lua_State* L, int index, type expected, type actual, const std::string& message = "") noexcept(false) {
6335  const char* err = message.empty() ? "stack index %d, expected %s, received %s" : "stack index %d, expected %s, received %s: %s";
6336  std::string actualname = associated_type_name(L, index, actual);
6337  return luaL_error(L, err, index,
6338  expected == type::poly ? "anything" : lua_typename(L, static_cast<int>(expected)),
6339  actualname.c_str(),
6340  message.c_str());
6341  }
6342 
6343  inline int type_panic_c_str(lua_State* L, int index, type expected, type actual, const char* message = nullptr) noexcept(false) {
6344  const char* err = message == nullptr || (std::char_traits<char>::length(message) == 0) ? "stack index %d, expected %s, received %s" : "stack index %d, expected %s, received %s: %s";
6345  std::string actualname = associated_type_name(L, index, actual);
6346  return luaL_error(L, err, index,
6347  expected == type::poly ? "anything" : lua_typename(L, static_cast<int>(expected)),
6348  actualname.c_str(),
6349  message);
6350  }
6351 
6352  struct type_panic_t {
6353  int operator()(lua_State* L, int index, type expected, type actual) const noexcept(false) {
6354  return type_panic_c_str(L, index, expected, actual, nullptr);
6355  }
6356  int operator()(lua_State* L, int index, type expected, type actual, const char* message) const noexcept(false) {
6357  return type_panic_c_str(L, index, expected, actual, message);
6358  }
6359  int operator()(lua_State* L, int index, type expected, type actual, const std::string& message) const noexcept(false) {
6360  return type_panic_string(L, index, expected, actual, message);
6361  }
6362  };
6363 
6365 
6367  int operator()(lua_State* L, int index, type expected, type actual, const std::string& message) const noexcept(false) {
6368  std::string str = "(type check failed in constructor)";
6369  return type_panic_string(L, index, expected, actual, message.empty() ? str : message + " " + str);
6370  }
6371  };
6372 
6373  template <typename F = void>
6375  int operator()(lua_State* L, int index, type expected, type actual, const std::string& message) const noexcept(false) {
6376  std::string str = "(bad argument to variable or function call)";
6377  return type_panic_string(L, index, expected, actual, message.empty() ? str : message + " " + str );
6378  }
6379  };
6380 
6381  template <typename R, typename... Args>
6382  struct argument_handler<types<R, Args...>> {
6383  int operator()(lua_State* L, int index, type expected, type actual, const std::string& message) const noexcept(false) {
6384  std::string addendum = "(bad argument into '";
6385  addendum += detail::demangle<R>();
6386  addendum += "(";
6387  int marker = 0;
6388  auto action = [&addendum, &marker](const std::string& n) {
6389  if (marker > 0) {
6390  addendum += ", ";
6391  }
6392  addendum += n;
6393  ++marker;
6394  };
6395  (void)detail::swallow{int(), (action(detail::demangle<Args>()), int())...};
6396  addendum += ")')";
6397  return type_panic_string(L, index, expected, actual, message.empty() ? addendum : message + " " + addendum);
6398  }
6399  };
6400 
6401  // Specify this function as the handler for lua::check if you know there's nothing wrong
6402  inline int no_panic(lua_State*, int, type, type, const char* = nullptr) noexcept {
6403  return 0;
6404  }
6405 
6406  inline void type_error(lua_State* L, int expected, int actual) noexcept(false) {
6407  luaL_error(L, "expected %s, received %s", lua_typename(L, expected), lua_typename(L, actual));
6408  }
6409 
6410  inline void type_error(lua_State* L, type expected, type actual) noexcept(false) {
6411  type_error(L, static_cast<int>(expected), static_cast<int>(actual));
6412  }
6413 
6414  inline void type_assert(lua_State* L, int index, type expected, type actual) noexcept(false) {
6415  if (expected != type::poly && expected != actual) {
6416  type_panic_c_str(L, index, expected, actual, nullptr);
6417  }
6418  }
6419 
6420  inline void type_assert(lua_State* L, int index, type expected) {
6421  type actual = type_of(L, index);
6422  type_assert(L, index, expected, actual);
6423  }
6424 
6425 } // namespace sol
6426 
6427 // end of sol/error_handler.hpp
6428 
6429 // beginning of sol/reference.hpp
6430 
6431 // beginning of sol/stack_reference.hpp
6432 
6433 namespace sol {
6434  namespace detail {
6435  inline bool xmovable(lua_State* leftL, lua_State* rightL) {
6436  if (rightL == nullptr || leftL == nullptr || leftL == rightL) {
6437  return false;
6438  }
6439  const void* leftregistry = lua_topointer(leftL, LUA_REGISTRYINDEX);
6440  const void* rightregistry = lua_topointer(rightL, LUA_REGISTRYINDEX);
6441  return leftregistry == rightregistry;
6442  }
6443  } // namespace detail
6444 
6446  private:
6447  lua_State* luastate = nullptr;
6448  int index = 0;
6449 
6450  protected:
6451  int registry_index() const noexcept {
6452  return LUA_NOREF;
6453  }
6454 
6455  public:
6456  stack_reference() noexcept = default;
6458  : stack_reference(){};
6459  stack_reference(lua_State* L, lua_nil_t) noexcept
6460  : luastate(L), index(0) {
6461  }
6462  stack_reference(lua_State* L, int i) noexcept
6463  : stack_reference(L, absolute_index(L, i)) {
6464  }
6465  stack_reference(lua_State* L, absolute_index i) noexcept
6466  : luastate(L), index(i) {
6467  }
6468  stack_reference(lua_State* L, raw_index i) noexcept
6469  : luastate(L), index(i) {
6470  }
6471  stack_reference(lua_State* L, ref_index i) noexcept = delete;
6472  stack_reference(lua_State* L, const reference& r) noexcept = delete;
6473  stack_reference(lua_State* L, const stack_reference& r) noexcept
6474  : luastate(L) {
6475  if (!r.valid()) {
6476  index = 0;
6477  return;
6478  }
6479  int i = r.stack_index();
6480  if (detail::xmovable(lua_state(), r.lua_state())) {
6481  lua_pushvalue(r.lua_state(), r.index);
6482  lua_xmove(r.lua_state(), luastate, 1);
6483  i = absolute_index(luastate, -1);
6484  }
6485  index = i;
6486  }
6487  stack_reference(stack_reference&& o) noexcept = default;
6488  stack_reference& operator=(stack_reference&&) noexcept = default;
6489  stack_reference(const stack_reference&) noexcept = default;
6490  stack_reference& operator=(const stack_reference&) noexcept = default;
6491 
6492  int push() const noexcept {
6493  return push(lua_state());
6494  }
6495 
6496  int push(lua_State* Ls) const noexcept {
6497  if (lua_state() == nullptr) {
6498  lua_pushnil(Ls);
6499  return 1;
6500  }
6501  lua_pushvalue(lua_state(), index);
6502  if (Ls != lua_state()) {
6503  lua_xmove(lua_state(), Ls, 1);
6504  }
6505  return 1;
6506  }
6507 
6508  void pop() const noexcept {
6509  pop(lua_state());
6510  }
6511 
6512  void pop(lua_State* Ls, int n = 1) const noexcept {
6513  lua_pop(Ls, n);
6514  }
6515 
6516  int stack_index() const noexcept {
6517  return index;
6518  }
6519 
6520  const void* pointer() const noexcept {
6521  const void* vp = lua_topointer(lua_state(), stack_index());
6522  return vp;
6523  }
6524 
6525  type get_type() const noexcept {
6526  int result = lua_type(lua_state(), index);
6527  return static_cast<type>(result);
6528  }
6529 
6530  lua_State* lua_state() const noexcept {
6531  return luastate;
6532  }
6533 
6534  bool valid() const noexcept {
6535  type t = get_type();
6536  return t != type::lua_nil && t != type::none;
6537  }
6538  };
6539 
6540  inline bool operator==(const stack_reference& l, const stack_reference& r) {
6541  return lua_compare(l.lua_state(), l.stack_index(), r.stack_index(), LUA_OPEQ) == 0;
6542  }
6543 
6544  inline bool operator!=(const stack_reference& l, const stack_reference& r) {
6545  return !operator==(l, r);
6546  }
6547 
6548  inline bool operator==(const stack_reference& lhs, const lua_nil_t&) {
6549  return !lhs.valid();
6550  }
6551 
6552  inline bool operator==(const lua_nil_t&, const stack_reference& rhs) {
6553  return !rhs.valid();
6554  }
6555 
6556  inline bool operator!=(const stack_reference& lhs, const lua_nil_t&) {
6557  return lhs.valid();
6558  }
6559 
6560  inline bool operator!=(const lua_nil_t&, const stack_reference& rhs) {
6561  return rhs.valid();
6562  }
6563 } // namespace sol
6564 
6565 // end of sol/stack_reference.hpp
6566 
6567 namespace sol {
6568  namespace detail {
6569  inline const char (&default_main_thread_name())[9] {
6570  static const char name[9] = "sol.\xF0\x9F\x93\x8C";
6571  return name;
6572  }
6573  } // namespace detail
6574 
6575  namespace stack {
6576  inline void remove(lua_State* L, int rawindex, int count) {
6577  if (count < 1)
6578  return;
6579  int top = lua_gettop(L);
6580  if (top < 1) {
6581  return;
6582  }
6583  if (rawindex == -count || top == rawindex) {
6584  // Slice them right off the top
6585  lua_pop(L, static_cast<int>(count));
6586  return;
6587  }
6588 
6589  // Remove each item one at a time using stack operations
6590  // Probably slower, maybe, haven't benchmarked,
6591  // but necessary
6592  int index = lua_absindex(L, rawindex);
6593  if (index < 0) {
6594  index = lua_gettop(L) + (index + 1);
6595  }
6596  int last = index + count;
6597  for (int i = index; i < last; ++i) {
6598  lua_remove(L, index);
6599  }
6600  }
6601 
6603  lua_State* L;
6604  int index;
6605  int count;
6606  push_popper_at(lua_State* luastate, int index = -1, int count = 1)
6607  : L(luastate), index(index), count(count) {
6608  }
6610  remove(L, index, count);
6611  }
6612  };
6613 
6614  template <bool top_level>
6615  struct push_popper_n {
6616  lua_State* L;
6617  int t;
6618  push_popper_n(lua_State* luastate, int x)
6619  : L(luastate), t(x) {
6620  }
6621  push_popper_n(const push_popper_n&) = delete;
6622  push_popper_n(push_popper_n&&) = default;
6623  push_popper_n& operator=(const push_popper_n&) = delete;
6624  push_popper_n& operator=(push_popper_n&&) = default;
6626  lua_pop(L, t);
6627  }
6628  };
6629  template <>
6630  struct push_popper_n<true> {
6631  push_popper_n(lua_State*, int) {
6632  }
6633  };
6634  template <bool, typename T, typename = void>
6635  struct push_popper {
6636  T t;
6638  : t(x) {
6639  t.push();
6640  }
6642  t.pop();
6643  }
6644  };
6645  template <typename T, typename C>
6646  struct push_popper<true, T, C> {
6648  }
6650  }
6651  };
6652  template <typename T>
6653  struct push_popper<false, T, std::enable_if_t<std::is_base_of<stack_reference, meta::unqualified_t<T>>::value>> {
6655  }
6657  }
6658  };
6659 
6660  template <bool top_level = false, typename T>
6662  return push_popper<top_level, T>(std::forward<T>(x));
6663  }
6664  template <typename T>
6666  int c = x.push();
6667  lua_State* L = x.lua_state();
6668  return push_popper_at(L, lua_absindex(L, -c), c);
6669  }
6670  template <bool top_level = false>
6671  push_popper_n<top_level> pop_n(lua_State* L, int x) {
6672  return push_popper_n<top_level>(L, x);
6673  }
6674  } // namespace stack
6675 
6676  inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) {
6677 #if SOL_LUA_VERSION < 502
6678  if (L == nullptr)
6679  return backup_if_unsupported;
6680  lua_getglobal(L, detail::default_main_thread_name());
6681  auto pp = stack::pop_n(L, 1);
6682  if (type_of(L, -1) == type::thread) {
6683  return lua_tothread(L, -1);
6684  }
6685  return backup_if_unsupported;
6686 #else
6687  if (L == nullptr)
6688  return backup_if_unsupported;
6689  lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
6690  lua_State* Lmain = lua_tothread(L, -1);
6691  lua_pop(L, 1);
6692  return Lmain;
6693 #endif // Lua 5.2+ has the main thread getter
6694  }
6695 
6696  namespace detail {
6697  struct global_tag {
6698  } const global_{};
6699  struct no_safety_tag {
6700  } const no_safety{};
6701 
6702  template <bool b>
6703  inline lua_State* pick_main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) {
6704  (void)L;
6705  (void)backup_if_unsupported;
6706  if (b) {
6707  return main_thread(L, backup_if_unsupported);
6708  }
6709  return L;
6710  }
6711  } // namespace detail
6712 
6713  template <bool main_only = false>
6714  class basic_reference {
6715  private:
6716  template <bool o_main_only>
6717  friend class basic_reference;
6718  lua_State* luastate = nullptr; // non-owning
6719  int ref = LUA_NOREF;
6720 
6721  int copy() const noexcept {
6722  if (ref == LUA_NOREF)
6723  return LUA_NOREF;
6724  push();
6725  return luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6726  }
6727 
6728  template <bool r_main_only>
6730  if (valid()) {
6731  deref();
6732  }
6733  if (r.ref == LUA_REFNIL) {
6734  luastate = detail::pick_main_thread < main_only && !r_main_only > (r.lua_state(), r.lua_state());
6735  ref = LUA_REFNIL;
6736  return;
6737  }
6738  if (r.ref == LUA_NOREF) {
6739  luastate = r.luastate;
6740  ref = LUA_NOREF;
6741  return;
6742  }
6743  if (detail::xmovable(lua_state(), r.lua_state())) {
6744  r.push(lua_state());
6745  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6746  return;
6747  }
6748  luastate = detail::pick_main_thread < main_only && !r_main_only > (r.lua_state(), r.lua_state());
6749  ref = r.copy();
6750  }
6751 
6752  template <bool r_main_only>
6754  if (valid()) {
6755  deref();
6756  }
6757  if (r.ref == LUA_REFNIL) {
6758  luastate = detail::pick_main_thread < main_only && !r_main_only > (r.lua_state(), r.lua_state());
6759  ref = LUA_REFNIL;
6760  return;
6761  }
6762  if (r.ref == LUA_NOREF) {
6763  luastate = r.luastate;
6764  ref = LUA_NOREF;
6765  return;
6766  }
6767  if (detail::xmovable(lua_state(), r.lua_state())) {
6768  r.push(lua_state());
6769  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6770  return;
6771  }
6772 
6773  luastate = detail::pick_main_thread < main_only && !r_main_only > (r.lua_state(), r.lua_state());
6774  ref = r.ref;
6775  r.ref = LUA_NOREF;
6776  r.luastate = nullptr;
6777  }
6778 
6779  protected:
6780  basic_reference(lua_State* L, detail::global_tag) noexcept
6781  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6782  lua_pushglobaltable(lua_state());
6783  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6784  }
6785 
6786  int stack_index() const noexcept {
6787  return -1;
6788  }
6789 
6790  void deref() const noexcept {
6791  luaL_unref(lua_state(), LUA_REGISTRYINDEX, ref);
6792  }
6793 
6794  public:
6795  basic_reference() noexcept = default;
6797  : basic_reference() {
6798  }
6800  : basic_reference(r.lua_state(), r.stack_index()) {
6801  }
6803  : basic_reference(r.lua_state(), r.stack_index()) {
6804  }
6805  template <bool r_main_only>
6806  basic_reference(lua_State* L, const basic_reference<r_main_only>& r) noexcept
6807  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6808  if (r.ref == LUA_REFNIL) {
6809  ref = LUA_REFNIL;
6810  return;
6811  }
6812  if (r.ref == LUA_NOREF || lua_state() == nullptr) {
6813  ref = LUA_NOREF;
6814  return;
6815  }
6816  if (detail::xmovable(lua_state(), r.lua_state())) {
6817  r.push(lua_state());
6818  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6819  return;
6820  }
6821  ref = r.copy();
6822  }
6823 
6824  template <bool r_main_only>
6825  basic_reference(lua_State* L, basic_reference<r_main_only>&& r) noexcept
6826  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6827  if (r.ref == LUA_REFNIL) {
6828  ref = LUA_REFNIL;
6829  return;
6830  }
6831  if (r.ref == LUA_NOREF || lua_state() == nullptr) {
6832  ref = LUA_NOREF;
6833  return;
6834  }
6835  if (detail::xmovable(lua_state(), r.lua_state())) {
6836  r.push(lua_state());
6837  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6838  return;
6839  }
6840  ref = r.ref;
6841  r.ref = LUA_NOREF;
6842  r.luastate = nullptr;
6843  }
6844 
6845  basic_reference(lua_State* L, const stack_reference& r) noexcept
6846  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6847  if (lua_state() == nullptr || r.lua_state() == nullptr || r.get_type() == type::none) {
6848  ref = LUA_NOREF;
6849  return;
6850  }
6851  if (r.get_type() == type::lua_nil) {
6852  ref = LUA_REFNIL;
6853  return;
6854  }
6855  if (lua_state() != r.lua_state() && !detail::xmovable(lua_state(), r.lua_state())) {
6856  return;
6857  }
6858  r.push(lua_state());
6859  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6860  }
6861  basic_reference(lua_State* L, int index = -1) noexcept
6862  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6863  // use L to stick with that state's execution stack
6864  lua_pushvalue(L, index);
6865  ref = luaL_ref(L, LUA_REGISTRYINDEX);
6866  }
6867  basic_reference(lua_State* L, ref_index index) noexcept
6868  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6869  lua_rawgeti(lua_state(), LUA_REGISTRYINDEX, index.index);
6870  ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
6871  }
6872  basic_reference(lua_State* L, lua_nil_t) noexcept
6873  : luastate(detail::pick_main_thread<main_only>(L, L)) {
6874  }
6875 
6876  ~basic_reference() noexcept {
6877  if (lua_state() == nullptr || ref == LUA_NOREF)
6878  return;
6879  deref();
6880  }
6881 
6883  : luastate(o.lua_state()), ref(o.copy()) {
6884  }
6885 
6887  : luastate(o.lua_state()), ref(o.ref) {
6888  o.luastate = nullptr;
6889  o.ref = LUA_NOREF;
6890  }
6891 
6893  : luastate(detail::pick_main_thread < main_only && !main_only > (o.lua_state(), o.lua_state())), ref(o.copy()) {
6894  }
6895 
6897  : luastate(detail::pick_main_thread < main_only && !main_only > (o.lua_state(), o.lua_state())), ref(o.ref) {
6898  o.luastate = nullptr;
6899  o.ref = LUA_NOREF;
6900  }
6901 
6903  move_assign(std::move(r));
6904  return *this;
6905  }
6906 
6908  copy_assign(r);
6909  return *this;
6910  }
6911 
6913  move_assign(std::move(r));
6914  return *this;
6915  }
6916 
6918  copy_assign(r);
6919  return *this;
6920  }
6921 
6923  if (valid()) {
6924  deref();
6925  }
6926  luastate = nullptr;
6927  ref = LUA_NOREF;
6928  return *this;
6929  }
6930 
6931  template <typename Super>
6932  basic_reference& operator=(proxy_base<Super>&& r);
6933 
6934  template <typename Super>
6935  basic_reference& operator=(const proxy_base<Super>& r);
6936 
6937  int push() const noexcept {
6938  return push(lua_state());
6939  }
6940 
6941  int push(lua_State* Ls) const noexcept {
6942  if (lua_state() == nullptr) {
6943  lua_pushnil(Ls);
6944  return 1;
6945  }
6946  lua_rawgeti(lua_state(), LUA_REGISTRYINDEX, ref);
6947  if (Ls != lua_state()) {
6948  lua_xmove(lua_state(), Ls, 1);
6949  }
6950  return 1;
6951  }
6952 
6953  void pop() const noexcept {
6954  pop(lua_state());
6955  }
6956 
6957  void pop(lua_State* Ls, int n = 1) const noexcept {
6958  lua_pop(Ls, n);
6959  }
6960 
6961  int registry_index() const noexcept {
6962  return ref;
6963  }
6964 
6965  bool valid() const noexcept {
6966  return !(ref == LUA_NOREF || ref == LUA_REFNIL);
6967  }
6968 
6969  const void* pointer() const noexcept {
6970  int si = push();
6971  const void* vp = lua_topointer(lua_state(), -si);
6972  lua_pop(this->lua_state(), si);
6973  return vp;
6974  }
6975 
6976  explicit operator bool() const noexcept {
6977  return valid();
6978  }
6979 
6980  type get_type() const noexcept {
6981  auto pp = stack::push_pop(*this);
6982  int result = lua_type(lua_state(), -1);
6983  return static_cast<type>(result);
6984  }
6985 
6986  lua_State* lua_state() const noexcept {
6987  return luastate;
6988  }
6989  };
6990 
6991  template <bool lb, bool rb>
6992  inline bool operator==(const basic_reference<lb>& l, const basic_reference<rb>& r) {
6993  auto ppl = stack::push_pop(l);
6994  auto ppr = stack::push_pop(r);
6995  return lua_compare(l.lua_state(), -1, -2, LUA_OPEQ) == 1;
6996  }
6997 
6998  template <bool lb, bool rb>
6999  inline bool operator!=(const basic_reference<lb>& l, const basic_reference<rb>& r) {
7000  return !operator==(l, r);
7001  }
7002 
7003  template <bool lb>
7004  inline bool operator==(const basic_reference<lb>& lhs, const lua_nil_t&) {
7005  return !lhs.valid();
7006  }
7007 
7008  template <bool rb>
7009  inline bool operator==(const lua_nil_t&, const basic_reference<rb>& rhs) {
7010  return !rhs.valid();
7011  }
7012 
7013  template <bool lb>
7014  inline bool operator!=(const basic_reference<lb>& lhs, const lua_nil_t&) {
7015  return lhs.valid();
7016  }
7017 
7018  template <bool rb>
7019  inline bool operator!=(const lua_nil_t&, const basic_reference<rb>& rhs) {
7020  return rhs.valid();
7021  }
7022 } // namespace sol
7023 
7024 // end of sol/reference.hpp
7025 
7026 // beginning of sol/tie.hpp
7027 
7028 namespace sol {
7029 
7030  namespace detail {
7031  template <typename T>
7032  struct is_speshul : std::false_type {};
7033  } // namespace detail
7034 
7035  template <typename T>
7036  struct tie_size : std::tuple_size<T> {};
7037 
7038  template <typename T>
7039  struct is_tieable : std::integral_constant<bool, (::sol::tie_size<T>::value > 0)> {};
7040 
7041  template <typename... Tn>
7042  struct tie_t : public std::tuple<std::add_lvalue_reference_t<Tn>...> {
7043  private:
7044  typedef std::tuple<std::add_lvalue_reference_t<Tn>...> base_t;
7045 
7046  template <typename T>
7047  void set(std::false_type, T&& target) {
7048  std::get<0>(*this) = std::forward<T>(target);
7049  }
7050 
7051  template <typename T>
7052  void set(std::true_type, T&& target) {
7053  typedef tie_size<meta::unqualified_t<T>> value_size;
7054  typedef tie_size<std::tuple<Tn...>> tie_size;
7055  typedef std::conditional_t<(value_size::value < tie_size::value), value_size, tie_size> indices_size;
7056  typedef std::make_index_sequence<indices_size::value> indices;
7057  set_extra(detail::is_speshul<meta::unqualified_t<T>>(), indices(), std::forward<T>(target));
7058  }
7059 
7060  template <std::size_t... I, typename T>
7061  void set_extra(std::true_type, std::index_sequence<I...>, T&& target) {
7062  using std::get;
7063  (void)detail::swallow{0,
7064  (get<I>(static_cast<base_t&>(*this)) = get<I>(types<Tn...>(), target), 0)..., 0};
7065  }
7066 
7067  template <std::size_t... I, typename T>
7068  void set_extra(std::false_type, std::index_sequence<I...>, T&& target) {
7069  using std::get;
7070  (void)detail::swallow{0,
7071  (get<I>(static_cast<base_t&>(*this)) = get<I>(target), 0)..., 0};
7072  }
7073 
7074  public:
7075  using base_t::base_t;
7076 
7077  template <typename T>
7078  tie_t& operator=(T&& value) {
7079  typedef is_tieable<meta::unqualified_t<T>> tieable;
7080  set(tieable(), std::forward<T>(value));
7081  return *this;
7082  }
7083  };
7084 
7085  template <typename... Tn>
7086  struct tie_size<tie_t<Tn...>> : std::tuple_size<std::tuple<Tn...>> {};
7087 
7088  namespace adl_barrier_detail {
7089  template <typename... Tn>
7090  inline tie_t<std::remove_reference_t<Tn>...> tie(Tn&&... argn) {
7091  return tie_t<std::remove_reference_t<Tn>...>(std::forward<Tn>(argn)...);
7092  }
7093  } // namespace adl_barrier_detail
7094 
7095  using namespace adl_barrier_detail;
7096 
7097 } // namespace sol
7098 
7099 // end of sol/tie.hpp
7100 
7101 // beginning of sol/stack_guard.hpp
7102 
7103 namespace sol {
7104  namespace detail {
7105  inline void stack_fail(int, int) {
7106 #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
7107  throw error(detail::direct_error, "imbalanced stack after operation finish");
7108 #else
7109  // Lol, what do you want, an error printout? :3c
7110  // There's no sane default here. The right way would be C-style abort(), and that's not acceptable, so
7111  // hopefully someone will register their own stack_fail thing for the `fx` parameter of stack_guard.
7112 #endif // No Exceptions
7113  }
7114  } // namespace detail
7115 
7116  struct stack_guard {
7117  lua_State* L;
7118  int top;
7119  std::function<void(int, int)> on_mismatch;
7120 
7121  stack_guard(lua_State* L)
7122  : stack_guard(L, lua_gettop(L)) {
7123  }
7124  stack_guard(lua_State* L, int top, std::function<void(int, int)> fx = detail::stack_fail)
7125  : L(L), top(top), on_mismatch(std::move(fx)) {
7126  }
7127  bool check_stack(int modification = 0) const {
7128  int bottom = lua_gettop(L) + modification;
7129  if (top == bottom) {
7130  return true;
7131  }
7132  on_mismatch(top, bottom);
7133  return false;
7134  }
7136  check_stack();
7137  }
7138  };
7139 } // namespace sol
7140 
7141 // end of sol/stack_guard.hpp
7142 
7143 #include <vector>
7144 #include <forward_list>
7145 #include <algorithm>
7146 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
7147 #endif // C++17
7148 
7149 namespace sol {
7150  namespace detail {
7151  struct as_reference_tag {};
7152  template <typename T>
7153  struct as_pointer_tag {};
7154  template <typename T>
7155  struct as_value_tag {};
7156  template <typename T>
7157  struct as_table_tag {};
7158 
7159  using unique_destructor = void (*)(void*);
7160 #if 0
7162 #else
7163  using unique_tag = const char*;
7164 #endif
7165 
7166  inline void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space, std::size_t& required_space) {
7167  // this handels arbitrary alignments...
7168  // make this into a power-of-2-only?
7169  // actually can't: this is a C++14-compatible framework,
7170  // power of 2 alignment is C++17
7171  std::uintptr_t initial = reinterpret_cast<std::uintptr_t>(ptr);
7172  std::uintptr_t offby = static_cast<std::uintptr_t>(initial % alignment);
7173  std::uintptr_t padding = (alignment - offby) % alignment;
7174  required_space += size + padding;
7175  if (space < required_space) {
7176  return nullptr;
7177  }
7178  ptr = static_cast<void*>(static_cast<char*>(ptr) + padding);
7179  space -= padding;
7180  return ptr;
7181  }
7182 
7183  inline void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space) {
7184  std::size_t required_space = 0;
7185  return align(alignment, size, ptr, space, required_space);
7186  }
7187 
7188  template <typename... Args>
7189  inline std::size_t aligned_space_for(void* alignment = nullptr) {
7190  char* start = static_cast<char*>(alignment);
7191  auto specific_align = [&alignment](std::size_t a, std::size_t s) {
7192  std::size_t space = (std::numeric_limits<std::size_t>::max)();
7193  alignment = align(a, s, alignment, space);
7194  alignment = static_cast<void*>(static_cast<char*>(alignment) + s);
7195  };
7196  (void)detail::swallow{ int{}, (specific_align(std::alignment_of<Args>::value, sizeof(Args)), int{})... };
7197  return static_cast<char*>(alignment) - start;
7198  }
7199 
7200  inline void* align_usertype_pointer(void* ptr) {
7201  typedef std::integral_constant<bool,
7202 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7203  false
7204 #else
7205  (std::alignment_of<void*>::value > 1)
7206 #endif
7207  >
7208  use_align;
7209  if (!use_align::value) {
7210  return ptr;
7211  }
7212  std::size_t space = (std::numeric_limits<std::size_t>::max)();
7213  return align(std::alignment_of<void*>::value, sizeof(void*), ptr, space);
7214  }
7215 
7216  template <bool pre_aligned = false>
7218  typedef std::integral_constant<bool,
7219 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7220  false
7221 #else
7222  (std::alignment_of<unique_destructor>::value > 1)
7223 #endif
7224  >
7225  use_align;
7226  if (!pre_aligned) {
7227  ptr = align_usertype_pointer(ptr);
7228  ptr = static_cast<void*>(static_cast<char*>(ptr) + sizeof(void*));
7229  }
7230  if (!use_align::value) {
7231  return static_cast<void*>(static_cast<void**>(ptr) + 1);
7232  }
7233  std::size_t space = (std::numeric_limits<std::size_t>::max)();
7234  return align(std::alignment_of<unique_destructor>::value, sizeof(unique_destructor), ptr, space);
7235  }
7236 
7237  template <bool pre_aligned = false>
7238  inline void* align_usertype_unique_tag(void* ptr) {
7239  typedef std::integral_constant<bool,
7240 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7241  false
7242 #else
7243  (std::alignment_of<unique_tag>::value > 1)
7244 #endif
7245  >
7246  use_align;
7247  if (!pre_aligned) {
7249  ptr = static_cast<void*>(static_cast<char*>(ptr) + sizeof(unique_destructor));
7250  }
7251  if (!use_align::value) {
7252  return ptr;
7253  }
7254  std::size_t space = (std::numeric_limits<std::size_t>::max)();
7255  return align(std::alignment_of<unique_tag>::value, sizeof(unique_tag), ptr, space);
7256  }
7257  template <typename T, bool pre_aligned = false>
7258  inline void* align_usertype_unique(void* ptr) {
7259  typedef std::integral_constant<bool,
7260 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7261  false
7262 #else
7263  (std::alignment_of<T>::value > 1)
7264 #endif
7265  >
7266  use_align;
7267  if (!pre_aligned) {
7268  ptr = align_usertype_unique_tag(ptr);
7269  ptr = static_cast<void*>(static_cast<char*>(ptr) + sizeof(unique_tag));
7270  }
7271  if (!use_align::value) {
7272  return ptr;
7273  }
7274  std::size_t space = (std::numeric_limits<std::size_t>::max)();
7275  return align(std::alignment_of<T>::value, sizeof(T), ptr, space);
7276  }
7277 
7278  template <typename T>
7279  inline void* align_user(void* ptr) {
7280  typedef std::integral_constant<bool,
7281 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7282  false
7283 #else
7284  (std::alignment_of<T>::value > 1)
7285 #endif
7286  >
7287  use_align;
7288  if (!use_align::value) {
7289  return ptr;
7290  }
7291  std::size_t space = (std::numeric_limits<std::size_t>::max)();
7292  return align(std::alignment_of<T>::value, sizeof(T), ptr, space);
7293  }
7294 
7295  template <typename T>
7296  inline T** usertype_allocate_pointer(lua_State* L) {
7297  typedef std::integral_constant<bool,
7298 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7299  false
7300 #else
7301  (std::alignment_of<T*>::value > 1)
7302 #endif
7303  >
7304  use_align;
7305  if (!use_align::value) {
7306  T** pointerpointer = static_cast<T**>(lua_newuserdata(L, sizeof(T*)));
7307  return pointerpointer;
7308  }
7309  static const std::size_t initial_size = aligned_space_for<T*>(nullptr);
7310  static const std::size_t misaligned_size = aligned_space_for<T*>(reinterpret_cast<void*>(0x1));
7311 
7312  std::size_t allocated_size = initial_size;
7313  void* unadjusted = lua_newuserdata(L, initial_size);
7314  void* adjusted = align(std::alignment_of<T*>::value, sizeof(T*), unadjusted, allocated_size);
7315  if (adjusted == nullptr) {
7316  lua_pop(L, 1);
7317  // what kind of absolute garbage trash allocator are we dealing with?
7318  // whatever, add some padding in the case of MAXIMAL alignment waste...
7319  allocated_size = misaligned_size;
7320  unadjusted = lua_newuserdata(L, allocated_size);
7321  adjusted = align(std::alignment_of<T*>::value, sizeof(T*), unadjusted, allocated_size);
7322  if (adjusted == nullptr) {
7323  // trash allocator can burn in hell
7324  lua_pop(L, 1);
7325  //luaL_error(L, "if you are the one that wrote this allocator you should feel bad for doing a worse job than malloc/realloc and should go read some books, yeah?");
7326  luaL_error(L, "cannot properly align memory for '%s'", detail::demangle<T*>().data());
7327  }
7328  }
7329  return static_cast<T**>(adjusted);
7330  }
7331 
7332  template <typename T>
7333  inline T* usertype_allocate(lua_State* L) {
7334  typedef std::integral_constant<bool,
7335 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7336  false
7337 #else
7338  (std::alignment_of<T*>::value > 1 || std::alignment_of<T>::value > 1)
7339 #endif
7340  >
7341  use_align;
7342  if (!use_align::value) {
7343  T** pointerpointer = static_cast<T**>(lua_newuserdata(L, sizeof(T*) + sizeof(T)));
7344  T*& pointerreference = *pointerpointer;
7345  T* allocationtarget = reinterpret_cast<T*>(pointerpointer + 1);
7346  pointerreference = allocationtarget;
7347  return allocationtarget;
7348  }
7349 
7350  /* the assumption is that `lua_newuserdata` -- unless someone
7351  passes a specific lua_Alloc that gives us bogus, un-aligned pointers
7352  -- uses malloc, which tends to hand out more or less aligned pointers to memory
7353  (most of the time, anyhow)
7354 
7355  but it's not guaranteed, so we have to do a post-adjustment check and increase padding
7356 
7357  we do this preliminarily with compile-time stuff, to see
7358  if we strike lucky with the allocator and alignment values
7359 
7360  otherwise, we have to re-allocate the userdata and
7361  over-allocate some space for additional padding because
7362  compilers are optimized for aligned reads/writes
7363  (and clang will barf UBsan errors on us for not being aligned)
7364  */
7365  static const std::size_t initial_size = aligned_space_for<T*, T>(nullptr);
7366  static const std::size_t misaligned_size = aligned_space_for<T*, T>(reinterpret_cast<void*>(0x1));
7367 
7368  void* pointer_adjusted;
7369  void* data_adjusted;
7370  auto attempt_alloc = [](lua_State* L, std::size_t allocated_size, void*& pointer_adjusted, void*& data_adjusted) -> bool {
7371  void* adjusted = lua_newuserdata(L, allocated_size);
7372  pointer_adjusted = align(std::alignment_of<T*>::value, sizeof(T*), adjusted, allocated_size);
7373  if (pointer_adjusted == nullptr) {
7374  lua_pop(L, 1);
7375  return false;
7376  }
7377  // subtract size of what we're going to allocate there
7378  allocated_size -= sizeof(T*);
7379  adjusted = static_cast<void*>(static_cast<char*>(pointer_adjusted) + sizeof(T*));
7380  data_adjusted = align(std::alignment_of<T>::value, sizeof(T), adjusted, allocated_size);
7381  if (data_adjusted == nullptr) {
7382  lua_pop(L, 1);
7383  return false;
7384  }
7385  return true;
7386  };
7387  bool result = attempt_alloc(L, initial_size, pointer_adjusted, data_adjusted);
7388  if (!result) {
7389  // we're likely to get something that fails to perform the proper allocation a second time,
7390  // so we use the suggested_new_size bump to help us out here
7391  pointer_adjusted = nullptr;
7392  data_adjusted = nullptr;
7393  result = attempt_alloc(L, misaligned_size, pointer_adjusted, data_adjusted);
7394  if (!result) {
7395  if (pointer_adjusted == nullptr) {
7396  luaL_error(L, "aligned allocation of userdata block (pointer section) for '%s' failed", detail::demangle<T>().c_str());
7397  }
7398  else {
7399  luaL_error(L, "aligned allocation of userdata block (data section) for '%s' failed", detail::demangle<T>().c_str());
7400  }
7401  return nullptr;
7402  }
7403  }
7404 
7405  T** pointerpointer = reinterpret_cast<T**>(pointer_adjusted);
7406  T*& pointerreference = *pointerpointer;
7407  T* allocationtarget = reinterpret_cast<T*>(data_adjusted);
7408  pointerreference = allocationtarget;
7409  return allocationtarget;
7410  }
7411 
7412  template <typename T, typename Real>
7413  inline Real* usertype_unique_allocate(lua_State* L, T**& pref, unique_destructor*& dx, unique_tag*& id) {
7414  typedef std::integral_constant<bool,
7415 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7416  false
7417 #else
7418  (std::alignment_of<T*>::value > 1 || std::alignment_of<unique_tag>::value > 1 || std::alignment_of<unique_destructor>::value > 1 || std::alignment_of<Real>::value > 1)
7419 #endif
7420  >
7421  use_align;
7422  if (!use_align::value) {
7423  pref = static_cast<T**>(lua_newuserdata(L, sizeof(T*) + sizeof(detail::unique_destructor) + sizeof(unique_tag) + sizeof(Real)));
7424  dx = static_cast<detail::unique_destructor*>(static_cast<void*>(pref + 1));
7425  id = static_cast<unique_tag*>(static_cast<void*>(dx + 1));
7426  Real* mem = static_cast<Real*>(static_cast<void*>(id + 1));
7427  return mem;
7428  }
7429 
7430  static const std::size_t initial_size = aligned_space_for<T*, unique_destructor, unique_tag, Real>(nullptr);
7431  static const std::size_t misaligned_size = aligned_space_for<T*, unique_destructor, unique_tag, Real>(reinterpret_cast<void*>(0x1));
7432 
7433  void* pointer_adjusted;
7434  void* dx_adjusted;
7435  void* id_adjusted;
7436  void* data_adjusted;
7437  auto attempt_alloc = [](lua_State* L, std::size_t allocated_size, void*& pointer_adjusted, void*& dx_adjusted, void*& id_adjusted, void*& data_adjusted) -> bool {
7438  void* adjusted = lua_newuserdata(L, allocated_size);
7439  pointer_adjusted = align(std::alignment_of<T*>::value, sizeof(T*), adjusted, allocated_size);
7440  if (pointer_adjusted == nullptr) {
7441  lua_pop(L, 1);
7442  return false;
7443  }
7444  allocated_size -= sizeof(T*);
7445 
7446  adjusted = static_cast<void*>(static_cast<char*>(pointer_adjusted) + sizeof(T*));
7447  dx_adjusted = align(std::alignment_of<unique_destructor>::value, sizeof(unique_destructor), adjusted, allocated_size);
7448  if (dx_adjusted == nullptr) {
7449  lua_pop(L, 1);
7450  return false;
7451  }
7452  allocated_size -= sizeof(unique_destructor);
7453 
7454  adjusted = static_cast<void*>(static_cast<char*>(dx_adjusted) + sizeof(unique_destructor));
7455 
7456  id_adjusted = align(std::alignment_of<unique_tag>::value, sizeof(unique_tag), adjusted, allocated_size);
7457  if (id_adjusted == nullptr) {
7458  lua_pop(L, 1);
7459  return false;
7460  }
7461  allocated_size -= sizeof(unique_tag);
7462 
7463  adjusted = static_cast<void*>(static_cast<char*>(id_adjusted) + sizeof(unique_tag));
7464  data_adjusted = align(std::alignment_of<Real>::value, sizeof(Real), adjusted, allocated_size);
7465  if (data_adjusted == nullptr) {
7466  lua_pop(L, 1);
7467  return false;
7468  }
7469  return true;
7470  };
7471  bool result = attempt_alloc(L, initial_size, pointer_adjusted, dx_adjusted, id_adjusted, data_adjusted);
7472  if (!result) {
7473  // we're likely to get something that fails to perform the proper allocation a second time,
7474  // so we use the suggested_new_size bump to help us out here
7475  pointer_adjusted = nullptr;
7476  dx_adjusted = nullptr;
7477  id_adjusted = nullptr;
7478  data_adjusted = nullptr;
7479  result = attempt_alloc(L, misaligned_size, pointer_adjusted, dx_adjusted, id_adjusted, data_adjusted);
7480  if (!result) {
7481  if (pointer_adjusted == nullptr) {
7482  luaL_error(L, "aligned allocation of userdata block (pointer section) for '%s' failed", detail::demangle<T>().c_str());
7483  }
7484  else if (dx_adjusted == nullptr) {
7485  luaL_error(L, "aligned allocation of userdata block (deleter section) for '%s' failed", detail::demangle<T>().c_str());
7486  }
7487  else {
7488  luaL_error(L, "aligned allocation of userdata block (data section) for '%s' failed", detail::demangle<T>().c_str());
7489  }
7490  return nullptr;
7491  }
7492  }
7493 
7494  pref = static_cast<T**>(pointer_adjusted);
7495  dx = static_cast<detail::unique_destructor*>(dx_adjusted);
7496  id = static_cast<unique_tag*>(id_adjusted);
7497  Real* mem = static_cast<Real*>(data_adjusted);
7498  return mem;
7499  }
7500 
7501  template <typename T>
7502  inline T* user_allocate(lua_State* L) {
7503  typedef std::integral_constant<bool,
7504 #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
7505  false
7506 #else
7507  (std::alignment_of<T>::value > 1)
7508 #endif
7509  >
7510  use_align;
7511  if (!use_align::value) {
7512  T* pointer = static_cast<T*>(lua_newuserdata(L, sizeof(T)));
7513  return pointer;
7514  }
7515 
7516  static const std::size_t initial_size = aligned_space_for<T>(nullptr);
7517  static const std::size_t misaligned_size = aligned_space_for<T>(reinterpret_cast<void*>(0x1));
7518 
7519  std::size_t allocated_size = initial_size;
7520  void* unadjusted = lua_newuserdata(L, allocated_size);
7521  void* adjusted = align(std::alignment_of<T>::value, sizeof(T), unadjusted, allocated_size);
7522  if (adjusted == nullptr) {
7523  lua_pop(L, 1);
7524  // try again, add extra space for alignment padding
7525  allocated_size = misaligned_size;
7526  unadjusted = lua_newuserdata(L, allocated_size);
7527  adjusted = align(std::alignment_of<T>::value, sizeof(T), unadjusted, allocated_size);
7528  if (adjusted == nullptr) {
7529  lua_pop(L, 1);
7530  luaL_error(L, "cannot properly align memory for '%s'", detail::demangle<T>().data());
7531  }
7532  }
7533  return static_cast<T*>(adjusted);
7534  }
7535 
7536  template <typename T>
7537  inline int usertype_alloc_destruct(lua_State* L) {
7538  void* memory = lua_touserdata(L, 1);
7539  memory = align_usertype_pointer(memory);
7540  T** pdata = static_cast<T**>(memory);
7541  T* data = *pdata;
7542  std::allocator<T> alloc{};
7543  std::allocator_traits<std::allocator<T>>::destroy(alloc, data);
7544  return 0;
7545  }
7546 
7547  template <typename T>
7548  inline int unique_destruct(lua_State* L) {
7549  void* memory = lua_touserdata(L, 1);
7550  memory = align_usertype_unique_destructor(memory);
7551  unique_destructor& dx = *static_cast<unique_destructor*>(memory);
7552  memory = static_cast<void*>(static_cast<char*>(memory) + sizeof(unique_destructor));
7553  memory = align_usertype_unique_tag<true>(memory);
7554  memory = static_cast<void*>(static_cast<char*>(memory) + sizeof(unique_tag));
7555  (dx)(memory);
7556  return 0;
7557  }
7558 
7559  template <typename T>
7560  inline int user_alloc_destruct(lua_State* L) {
7561  void* memory = lua_touserdata(L, 1);
7562  memory = align_user<T>(memory);
7563  T* data = static_cast<T*>(memory);
7564  std::allocator<T> alloc;
7565  std::allocator_traits<std::allocator<T>>::destroy(alloc, data);
7566  return 0;
7567  }
7568 
7569  template <typename T, typename Real>
7570  inline void usertype_unique_alloc_destroy(void* memory) {
7571  memory = align_usertype_unique<Real, true>(memory);
7572  Real* target = static_cast<Real*>(memory);
7573  std::allocator<Real> alloc;
7574  std::allocator_traits<std::allocator<Real>>::destroy(alloc, target);
7575  }
7576 
7577  template <typename T>
7578  inline int cannot_destruct(lua_State* L) {
7579  return luaL_error(L, "cannot call the destructor for '%s': it is either hidden (protected/private) or removed with '= delete' and thusly this type is being destroyed without properly destructing, invoking undefined behavior: please bind a usertype and specify a custom destructor to define the behavior properly", detail::demangle<T>().data());
7580  }
7581 
7582  template <typename T>
7583  void reserve(T&, std::size_t) {
7584  }
7585 
7586  template <typename T, typename Al>
7587  void reserve(std::vector<T, Al>& arr, std::size_t hint) {
7588  arr.reserve(hint);
7589  }
7590 
7591  template <typename T, typename Tr, typename Al>
7592  void reserve(std::basic_string<T, Tr, Al>& arr, std::size_t hint) {
7593  arr.reserve(hint);
7594  }
7595  } // namespace detail
7596 
7597  namespace stack {
7598 
7599  template <typename T>
7600  struct extensible {};
7601 
7602  template <typename T, bool global = false, bool raw = false, typename = void>
7604  template <typename T, typename P, bool global = false, bool raw = false, typename = void>
7606  template <typename T, bool global = false, bool raw = false, typename = void>
7608  template <typename T, typename = void>
7609  struct getter;
7610  template <typename T, typename = void>
7612  template <typename T, typename = void>
7614  template <typename T, typename = void>
7615  struct popper;
7616  template <typename T, typename = void>
7617  struct pusher;
7618  template <typename T, type = lua_type_of<T>::value, typename = void>
7619  struct checker;
7620  template <typename T, type = lua_type_of<T>::value, typename = void>
7622  template <typename T, typename = void>
7624  template <typename T, typename = void>
7626  template <typename T, typename = void>
7628 
7629  struct probe {
7630  bool success;
7631  int levels;
7632 
7633  probe(bool s, int l)
7634  : success(s), levels(l) {
7635  }
7636 
7637  operator bool() const {
7638  return success;
7639  };
7640  };
7641 
7642  struct record {
7643  int last;
7644  int used;
7645 
7647  : last(), used() {
7648  }
7649  void use(int count) {
7650  last = count;
7651  used += count;
7652  }
7653  };
7654 
7655  namespace stack_detail {
7656  template <typename T>
7657  struct strip {
7658  typedef T type;
7659  };
7660  template <typename T>
7661  struct strip<std::reference_wrapper<T>> {
7662  typedef T& type;
7663  };
7664  template <typename T>
7665  struct strip<user<T>> {
7666  typedef T& type;
7667  };
7668  template <typename T>
7669  struct strip<non_null<T>> {
7670  typedef T type;
7671  };
7672  template <typename T>
7673  using strip_t = typename strip<T>::type;
7674 
7675  template <typename T>
7676  struct strip_extensible { typedef T type; };
7677 
7678  template <typename T>
7679  struct strip_extensible<extensible<T>> { typedef T type; };
7680 
7681  template <typename T>
7683 
7684  template <typename C>
7685  static int get_size_hint(const C& c) {
7686  return static_cast<int>(c.size());
7687  }
7688 
7689  template <typename V, typename Al>
7690  static int get_size_hint(const std::forward_list<V, Al>&) {
7691  // forward_list makes me sad
7692  return static_cast<int>(32);
7693  }
7694 
7695  template <typename T>
7696  inline decltype(auto) unchecked_unqualified_get(lua_State* L, int index, record& tracking) {
7697  typedef meta::unqualified_t<T> Tu;
7698  getter<Tu> g{};
7699  (void)g;
7700  return g.get(L, index, tracking);
7701  }
7702 
7703  template <typename T>
7704  inline decltype(auto) unchecked_get(lua_State* L, int index, record& tracking) {
7705  qualified_getter<T> g{};
7706  (void)g;
7707  return g.get(L, index, tracking);
7708  }
7709 
7710  template <typename T, typename Arg, typename... Args>
7711  inline int push_reference(lua_State* L, Arg&& arg, Args&&... args) {
7712  typedef meta::all<
7713  std::is_lvalue_reference<T>,
7717  use_reference_tag;
7719  (void)p;
7720  return p.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
7721  }
7722 
7723  template <typename T, typename Handler>
7724  bool check_usertype(std::false_type, lua_State* L, int index, type indextype, Handler&& handler, record& tracking) {
7725  typedef meta::unqualified_t<T> Tu;
7726  typedef detail::as_value_tag<Tu> detail_t;
7727  return checker<detail_t, type::userdata>{}.check(types<meta::unqualified_t<T>>(), L, index, indextype, std::forward<Handler>(handler), tracking);
7728  }
7729 
7730  template <typename T, typename Handler>
7731  bool check_usertype(std::true_type, lua_State* L, int index, type indextype, Handler&& handler, record& tracking) {
7733  typedef detail::as_pointer_tag<Tu> detail_t;
7734  return checker<detail_t, type::userdata>{}.check(L, index, indextype, std::forward<Handler>(handler), tracking);
7735  }
7736  } // namespace stack_detail
7737 
7738  inline bool maybe_indexable(lua_State* L, int index = -1) {
7739  type t = type_of(L, index);
7740  return t == type::userdata || t == type::table;
7741  }
7742 
7743  inline int top(lua_State* L) {
7744  return lua_gettop(L);
7745  }
7746 
7747  inline bool is_main_thread(lua_State* L) {
7748  int ismainthread = lua_pushthread(L);
7749  lua_pop(L, 1);
7750  return ismainthread == 1;
7751  }
7752 
7753  inline void coroutine_create_guard(lua_State* L) {
7754  if (is_main_thread(L)) {
7755  return;
7756  }
7757  int stacksize = lua_gettop(L);
7758  if (stacksize < 1) {
7759  return;
7760  }
7761  if (type_of(L, 1) != type::function) {
7762  return;
7763  }
7764  // well now we're screwed...
7765  // we can clean the stack and pray it doesn't destroy anything?
7766  lua_pop(L, stacksize);
7767  }
7768 
7769  template <typename T, typename... Args>
7770  inline int push(lua_State* L, T&& t, Args&&... args) {
7771  return pusher<meta::unqualified_t<T>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
7772  }
7773 
7774  // overload allows to use a pusher of a specific type, but pass in any kind of args
7775  template <typename T, typename Arg, typename... Args, typename = std::enable_if_t<!std::is_same<T, Arg>::value>>
7776  inline int push(lua_State* L, Arg&& arg, Args&&... args) {
7777  return pusher<meta::unqualified_t<T>>{}.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
7778  }
7779 
7780  template <typename T, typename... Args>
7781  inline int push_reference(lua_State* L, T&& t, Args&&... args) {
7782  return stack_detail::push_reference<T>(L, std::forward<T>(t), std::forward<Args>(args)...);
7783  }
7784 
7785  template <typename T, typename Arg, typename... Args>
7786  inline int push_reference(lua_State* L, Arg&& arg, Args&&... args) {
7787  return stack_detail::push_reference<T>(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
7788  }
7789 
7790  inline int multi_push(lua_State*) {
7791  // do nothing
7792  return 0;
7793  }
7794 
7795  template <typename T, typename... Args>
7796  inline int multi_push(lua_State* L, T&& t, Args&&... args) {
7797  int pushcount = push(L, std::forward<T>(t));
7798  void(detail::swallow{ (pushcount += stack::push(L, std::forward<Args>(args)), 0)... });
7799  return pushcount;
7800  }
7801 
7802  inline int multi_push_reference(lua_State*) {
7803  // do nothing
7804  return 0;
7805  }
7806 
7807  template <typename T, typename... Args>
7808  inline int multi_push_reference(lua_State* L, T&& t, Args&&... args) {
7809  int pushcount = push_reference(L, std::forward<T>(t));
7810  void(detail::swallow{ (pushcount += stack::push_reference(L, std::forward<Args>(args)), 0)... });
7811  return pushcount;
7812  }
7813 
7814  template <typename T, typename Handler>
7815  bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
7817  // VC++ has a bad warning here: shut it up
7818  (void)c;
7819  return c.check(L, index, std::forward<Handler>(handler), tracking);
7820  }
7821 
7822  template <typename T, typename Handler>
7823  bool check(lua_State* L, int index, Handler&& handler) {
7824  record tracking{};
7825  return check<T>(L, index, std::forward<Handler>(handler), tracking);
7826  }
7827 
7828  template <typename T>
7829  bool check(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
7830  auto handler = no_panic;
7831  return check<T>(L, index, handler);
7832  }
7833 
7834  template <typename T, typename Handler>
7835  bool unqualified_check(lua_State* L, int index, Handler&& handler, record& tracking) {
7836  typedef meta::unqualified_t<T> Tu;
7837  checker<Tu> c;
7838  // VC++ has a bad warning here: shut it up
7839  (void)c;
7840  return c.check(L, index, std::forward<Handler>(handler), tracking);
7841  }
7842 
7843  template <typename T, typename Handler>
7844  bool unqualified_check(lua_State* L, int index, Handler&& handler) {
7845  record tracking{};
7846  return unqualified_check<T>(L, index, std::forward<Handler>(handler), tracking);
7847  }
7848 
7849  template <typename T>
7850  bool unqualified_check(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
7851  auto handler = no_panic;
7852  return unqualified_check<T>(L, index, handler);
7853  }
7854 
7855  template <typename T, typename Handler>
7856  bool check_usertype(lua_State* L, int index, Handler&& handler, record& tracking) {
7857  type indextype = type_of(L, index);
7858  return stack_detail::check_usertype<T>(std::is_pointer<T>(), L, index, indextype, std::forward<Handler>(handler), tracking);
7859  }
7860 
7861  template <typename T, typename Handler>
7862  bool check_usertype(lua_State* L, int index, Handler&& handler) {
7863  record tracking{};
7864  return check_usertype<T>(L, index, std::forward<Handler>(handler), tracking);
7865  }
7866 
7867  template <typename T>
7868  bool check_usertype(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
7869  auto handler = no_panic;
7870  return check_usertype<T>(L, index, handler);
7871  }
7872 
7873  template <typename T, typename Handler>
7874  inline decltype(auto) unqualified_check_get(lua_State* L, int index, Handler&& handler, record& tracking) {
7875  typedef meta::unqualified_t<T> Tu;
7876  check_getter<Tu> cg{};
7877  (void)cg;
7878  return cg.get(L, index, std::forward<Handler>(handler), tracking);
7879  }
7880 
7881  template <typename T, typename Handler>
7882  inline decltype(auto) unqualified_check_get(lua_State* L, int index, Handler&& handler) {
7883  record tracking{};
7884  return unqualified_check_get<T>(L, index, handler, tracking);
7885  }
7886 
7887  template <typename T>
7888  inline decltype(auto) unqualified_check_get(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
7889  auto handler = no_panic;
7890  return unqualified_check_get<T>(L, index, handler);
7891  }
7892 
7893  template <typename T, typename Handler>
7894  inline decltype(auto) check_get(lua_State* L, int index, Handler&& handler, record& tracking) {
7896  (void)cg;
7897  return cg.get(L, index, std::forward<Handler>(handler), tracking);
7898  }
7899 
7900  template <typename T, typename Handler>
7901  inline decltype(auto) check_get(lua_State* L, int index, Handler&& handler) {
7902  record tracking{};
7903  return check_get<T>(L, index, handler, tracking);
7904  }
7905 
7906  template <typename T>
7907  inline decltype(auto) check_get(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
7908  auto handler = no_panic;
7909  return check_get<T>(L, index, handler);
7910  }
7911 
7912  namespace stack_detail {
7913 
7914 #if defined(SOL_SAFE_GETTER) && SOL_SAFE_GETTER
7915  template <typename T>
7916  inline auto tagged_unqualified_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_unqualified_get<T>(L, index, tracking)) {
7918  return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
7919  }
7920  auto op = unqualified_check_get<T>(L, index, type_panic_c_str, tracking);
7921  return *std::move(op);
7922  }
7923 
7924  template <typename T>
7925  inline decltype(auto) tagged_unqualified_get(types<optional<T>>, lua_State* L, int index, record& tracking) {
7926  return stack_detail::unchecked_unqualified_get<optional<T>>(L, index, tracking);
7927  }
7928 
7929 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
7930  template <typename T>
7931  inline decltype(auto) tagged_unqualified_get(types<std::optional<T>>, lua_State* L, int index, record& tracking) {
7932  return stack_detail::unchecked_unqualified_get<std::optional<T>>(L, index, tracking);
7933  }
7934 #endif // shitty optional
7935 
7936  template <typename T>
7937  inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) {
7939  return stack_detail::unchecked_get<T>(L, index, tracking);
7940  }
7941  auto op = check_get<T>(L, index, type_panic_c_str, tracking);
7942  return *std::move(op);
7943  }
7944 
7945  template <typename T>
7946  inline decltype(auto) tagged_get(types<optional<T>>, lua_State* L, int index, record& tracking) {
7947  return stack_detail::unchecked_get<optional<T>>(L, index, tracking);
7948  }
7949 
7950 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
7951  template <typename T>
7952  inline decltype(auto) tagged_get(types<std::optional<T>>, lua_State* L, int index, record& tracking) {
7953  return stack_detail::unchecked_get<std::optional<T>>(L, index, tracking);
7954  }
7955 #endif // shitty optional
7956 
7957 #else
7958  template <typename T>
7959  inline decltype(auto) tagged_unqualified_get(types<T>, lua_State* L, int index, record& tracking) {
7960  return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
7961  }
7962 
7963  template <typename T>
7964  inline decltype(auto) tagged_get(types<T>, lua_State* L, int index, record& tracking) {
7965  return stack_detail::unchecked_get<T>(L, index, tracking);
7966  }
7967 #endif
7968 
7969  template <bool b>
7970  struct check_types {
7971  template <typename T, typename... Args, typename Handler>
7972  static bool check(types<T, Args...>, lua_State* L, int firstargument, Handler&& handler, record& tracking) {
7973  if (!stack::check<T>(L, firstargument + tracking.used, handler, tracking))
7974  return false;
7975  return check(types<Args...>(), L, firstargument, std::forward<Handler>(handler), tracking);
7976  }
7977 
7978  template <typename Handler>
7979  static bool check(types<>, lua_State*, int, Handler&&, record&) {
7980  return true;
7981  }
7982  };
7983 
7984  template <>
7985  struct check_types<false> {
7986  template <typename... Args, typename Handler>
7987  static bool check(types<Args...>, lua_State*, int, Handler&&, record&) {
7988  return true;
7989  }
7990  };
7991 
7992  } // namespace stack_detail
7993 
7994  template <bool b, typename... Args, typename Handler>
7995  bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) {
7996  return stack_detail::check_types<b>{}.check(types<meta::unqualified_t<Args>...>(), L, index, std::forward<Handler>(handler), tracking);
7997  }
7998 
7999  template <bool b, typename... Args, typename Handler>
8000  bool multi_check(lua_State* L, int index, Handler&& handler) {
8001  record tracking{};
8002  return multi_check<b, Args...>(L, index, std::forward<Handler>(handler), tracking);
8003  }
8004 
8005  template <bool b, typename... Args>
8006  bool multi_check(lua_State* L, int index) {
8007  auto handler = no_panic;
8008  return multi_check<b, Args...>(L, index, handler);
8009  }
8010 
8011  template <typename... Args, typename Handler>
8012  bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) {
8013  return multi_check<true, Args...>(L, index, std::forward<Handler>(handler), tracking);
8014  }
8015 
8016  template <typename... Args, typename Handler>
8017  bool multi_check(lua_State* L, int index, Handler&& handler) {
8018  return multi_check<true, Args...>(L, index, std::forward<Handler>(handler));
8019  }
8020 
8021  template <typename... Args>
8022  bool multi_check(lua_State* L, int index) {
8023  return multi_check<true, Args...>(L, index);
8024  }
8025 
8026  template <typename T>
8027  inline decltype(auto) get_usertype(lua_State* L, int index, record& tracking) {
8028 #if defined(SOL_SAFE_GETTER) && SOL_SAFE_GETTER
8029  return stack_detail::tagged_get(types<std::conditional_t<std::is_pointer<T>::value, detail::as_pointer_tag<std::remove_pointer_t<T>>, detail::as_value_tag<T>>>(), L, index, tracking);
8030 #else
8031  return stack_detail::unchecked_get<std::conditional_t<std::is_pointer<T>::value, detail::as_pointer_tag<std::remove_pointer_t<T>>, detail::as_value_tag<T>>>(L, index, tracking);
8032 #endif
8033  }
8034 
8035  template <typename T>
8036  inline decltype(auto) get_usertype(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
8037  record tracking{};
8038  return get_usertype<T>(L, index, tracking);
8039  }
8040 
8041  template <typename T>
8042  inline decltype(auto) unqualified_get(lua_State* L, int index, record& tracking) {
8043  return stack_detail::tagged_unqualified_get(types<T>(), L, index, tracking);
8044  }
8045 
8046  template <typename T>
8047  inline decltype(auto) unqualified_get(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
8048  record tracking{};
8049  return unqualified_get<T>(L, index, tracking);
8050  }
8051 
8052  template <typename T>
8053  inline decltype(auto) get(lua_State* L, int index, record& tracking) {
8054  return stack_detail::tagged_get(types<T>(), L, index, tracking);
8055  }
8056 
8057  template <typename T>
8058  inline decltype(auto) get(lua_State* L, int index = -lua_size<meta::unqualified_t<T>>::value) {
8059  record tracking{};
8060  return get<T>(L, index, tracking);
8061  }
8062 
8063  template <typename T>
8064  inline decltype(auto) pop(lua_State* L) {
8065  return popper<meta::unqualified_t<T>>{}.pop(L);
8066  }
8067 
8068  template <bool global = false, bool raw = false, typename Key>
8069  void get_field(lua_State* L, Key&& key) {
8070  field_getter<meta::unqualified_t<Key>, global, raw>{}.get(L, std::forward<Key>(key));
8071  }
8072 
8073  template <bool global = false, bool raw = false, typename Key>
8074  void get_field(lua_State* L, Key&& key, int tableindex) {
8075  field_getter<meta::unqualified_t<Key>, global, raw>{}.get(L, std::forward<Key>(key), tableindex);
8076  }
8077 
8078  template <bool global = false, typename Key>
8079  void raw_get_field(lua_State* L, Key&& key) {
8080  get_field<global, true>(L, std::forward<Key>(key));
8081  }
8082 
8083  template <bool global = false, typename Key>
8084  void raw_get_field(lua_State* L, Key&& key, int tableindex) {
8085  get_field<global, true>(L, std::forward<Key>(key), tableindex);
8086  }
8087 
8088  template <bool global = false, bool raw = false, typename C = detail::non_lua_nil_t, typename Key>
8089  probe probe_get_field(lua_State* L, Key&& key) {
8090  return probe_field_getter<meta::unqualified_t<Key>, C, global, raw>{}.get(L, std::forward<Key>(key));
8091  }
8092 
8093  template <bool global = false, bool raw = false, typename C = detail::non_lua_nil_t, typename Key>
8094  probe probe_get_field(lua_State* L, Key&& key, int tableindex) {
8095  return probe_field_getter<meta::unqualified_t<Key>, C, global, raw>{}.get(L, std::forward<Key>(key), tableindex);
8096  }
8097 
8098  template <bool global = false, typename C = detail::non_lua_nil_t, typename Key>
8099  probe probe_raw_get_field(lua_State* L, Key&& key) {
8100  return probe_get_field<global, true, C>(L, std::forward<Key>(key));
8101  }
8102 
8103  template <bool global = false, typename C = detail::non_lua_nil_t, typename Key>
8104  probe probe_raw_get_field(lua_State* L, Key&& key, int tableindex) {
8105  return probe_get_field<global, true, C>(L, std::forward<Key>(key), tableindex);
8106  }
8107 
8108  template <bool global = false, bool raw = false, typename Key, typename Value>
8109  void set_field(lua_State* L, Key&& key, Value&& value) {
8110  field_setter<meta::unqualified_t<Key>, global, raw>{}.set(L, std::forward<Key>(key), std::forward<Value>(value));
8111  }
8112 
8113  template <bool global = false, bool raw = false, typename Key, typename Value>
8114  void set_field(lua_State* L, Key&& key, Value&& value, int tableindex) {
8115  field_setter<meta::unqualified_t<Key>, global, raw>{}.set(L, std::forward<Key>(key), std::forward<Value>(value), tableindex);
8116  }
8117 
8118  template <bool global = false, typename Key, typename Value>
8119  void raw_set_field(lua_State* L, Key&& key, Value&& value) {
8120  set_field<global, true>(L, std::forward<Key>(key), std::forward<Value>(value));
8121  }
8122 
8123  template <bool global = false, typename Key, typename Value>
8124  void raw_set_field(lua_State* L, Key&& key, Value&& value, int tableindex) {
8125  set_field<global, true>(L, std::forward<Key>(key), std::forward<Value>(value), tableindex);
8126  }
8127 
8128  template <typename T, typename F>
8129  inline void modify_unique_usertype_as(const stack_reference& obj, F&& f) {
8130  typedef unique_usertype_traits<T> u_traits;
8131  void* raw = lua_touserdata(obj.lua_state(), obj.stack_index());
8132  void* ptr_memory = detail::align_usertype_pointer(raw);
8133  void* uu_memory = detail::align_usertype_unique<T>(raw);
8134  T& uu = *static_cast<T*>(uu_memory);
8135  f(uu);
8136  *static_cast<void**>(ptr_memory) = static_cast<void*>(u_traits::get(uu));
8137  }
8138 
8139  template <typename F>
8140  inline void modify_unique_usertype(const stack_reference& obj, F&& f) {
8142  typedef typename bt::template arg_at<0> T;
8143  modify_unique_usertype_as<meta::unqualified_t<T>>(obj, std::forward<F>(f));
8144  }
8145  } // namespace stack
8146 } // namespace sol
8147 
8148 // end of sol/stack_core.hpp
8149 
8150 // beginning of sol/stack_check.hpp
8151 
8152 // beginning of sol/stack_check_unqualified.hpp
8153 
8154 #include <cmath>
8155 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
8156 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
8157 #endif // SOL_STD_VARIANT
8158 #endif // SOL_CXX17_FEATURES
8159 
8160 namespace sol {
8161 namespace stack {
8162  namespace stack_detail {
8163  template <typename T, bool poptable = true>
8164  inline bool check_metatable(lua_State* L, int index = -2) {
8165  const auto& metakey = usertype_traits<T>::metatable();
8166  luaL_getmetatable(L, &metakey[0]);
8167  const type expectedmetatabletype = static_cast<type>(lua_type(L, -1));
8168  if (expectedmetatabletype != type::lua_nil) {
8169  if (lua_rawequal(L, -1, index) == 1) {
8170  lua_pop(L, 1 + static_cast<int>(poptable));
8171  return true;
8172  }
8173  }
8174  lua_pop(L, 1);
8175  return false;
8176  }
8177 
8178  template <type expected, int (*check_func)(lua_State*, int)>
8179  struct basic_check {
8180  template <typename Handler>
8181  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8182  tracking.use(1);
8183  bool success = check_func(L, index) == 1;
8184  if (!success) {
8185  // expected type, actual type
8186  handler(L, index, expected, type_of(L, index), "");
8187  }
8188  return success;
8189  }
8190  };
8191  } // namespace stack_detail
8192 
8193  template <typename T, typename>
8194  struct userdata_checker {
8195  template <typename Handler>
8196  static bool check(lua_State*, int, type, Handler&&, record&) {
8197  return false;
8198  }
8199  };
8200 
8201  template <typename T, type expected, typename>
8202  struct checker {
8203  template <typename Handler>
8204  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8205  tracking.use(1);
8206  const type indextype = type_of(L, index);
8207  bool success = expected == indextype;
8208  if (!success) {
8209  // expected type, actual type, message
8210  handler(L, index, expected, indextype, "");
8211  }
8212  return success;
8213  }
8214  };
8215 
8216  template <typename T, type expected, typename C>
8217  struct qualified_checker : checker<meta::unqualified_t<T>, lua_type_of<meta::unqualified_t<T>>::value, C> {};
8218 
8219  template <typename T>
8220  struct checker<T, type::number, std::enable_if_t<std::is_integral<T>::value>> {
8221  template <typename Handler>
8222  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8223  tracking.use(1);
8224 #if SOL_LUA_VERSION >= 503
8225 #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
8226  int isnum = 0;
8227  lua_tointegerx(L, index, &isnum);
8228  const bool success = isnum != 0;
8229  if (!success) {
8230  // expected type, actual type
8231  handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
8232  }
8233 #elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
8234  // this check is precise, does not convert
8235  if (lua_isinteger(L, index) == 1) {
8236  return true;
8237  }
8238  const bool success = false;
8239  if (!success) {
8240  // expected type, actual type
8241  handler(L, index, type::number, type_of(L, index), "not a numeric (integral) type");
8242  }
8243 #else
8244  type t = type_of(L, index);
8245  const bool success = t == type::number;
8246 #endif // If numbers are enabled, use the imprecise check
8247  if (!success) {
8248  // expected type, actual type
8249  handler(L, index, type::number, type_of(L, index), "not a numeric type");
8250  }
8251  return success;
8252 #else
8253 #if !defined(SOL_STRINGS_ARE_NUMBERS) || !SOL_STRINGS_ARE_NUMBERS
8254  // must pre-check, because it will convert
8255  type t = type_of(L, index);
8256  if (t != type::number) {
8257  // expected type, actual type
8258  handler(L, index, type::number, t, "not a numeric type");
8259  return false;
8260  }
8261 #endif // Do not allow strings to be numbers
8262 #if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
8263  int isnum = 0;
8264  const lua_Number v = lua_tonumberx(L, index, &isnum);
8265  const bool success = isnum != 0 && static_cast<lua_Number>(llround(v)) == v;
8266 #else
8267  const bool success = true;
8268 #endif // Safe numerics and number precision checking
8269  if (!success) {
8270  // expected type, actual type
8271 #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
8272  handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
8273 #else
8274  handler(L, index, type::number, t, "not a numeric type");
8275 #endif
8276  }
8277  return success;
8278 #endif // Lua Version 5.3 versus others
8279  }
8280  };
8281 
8282  template <typename T>
8283  struct checker<T, type::number, std::enable_if_t<std::is_floating_point<T>::value>> {
8284  template <typename Handler>
8285  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8286  tracking.use(1);
8287 #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
8288  bool success = lua_isnumber(L, index) == 1;
8289  if (!success) {
8290  // expected type, actual type
8291  handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
8292  }
8293  return success;
8294 #else
8295  type t = type_of(L, index);
8296  bool success = t == type::number;
8297  if (!success) {
8298  // expected type, actual type
8299  handler(L, index, type::number, t, "not a numeric type");
8300  }
8301  return success;
8302 #endif // Strings are Numbers
8303  }
8304  };
8305 
8306  template <type expected, typename C>
8307  struct checker<lua_nil_t, expected, C> {
8308  template <typename Handler>
8309  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8310  bool success = lua_isnil(L, index);
8311  if (success) {
8312  tracking.use(1);
8313  return success;
8314  }
8315  tracking.use(0);
8316  success = lua_isnone(L, index);
8317  if (!success) {
8318  // expected type, actual type
8319  handler(L, index, expected, type_of(L, index), "");
8320  }
8321  return success;
8322  }
8323  };
8324 
8325  template <typename C>
8326  struct checker<detail::non_lua_nil_t, type::poly, C> {
8327  template <typename Handler>
8328  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8329  return !stack::unqualified_check<lua_nil_t>(L, index, std::forward<Handler>(handler), tracking);
8330  }
8331  };
8332 
8333  template <type expected, typename C>
8334  struct checker<nullopt_t, expected, C> : checker<lua_nil_t> {};
8335 
8336  template <typename C>
8337  struct checker<this_state, type::poly, C> {
8338  template <typename Handler>
8339  static bool check(lua_State*, int, Handler&&, record& tracking) {
8340  tracking.use(0);
8341  return true;
8342  }
8343  };
8344 
8345  template <typename C>
8347  template <typename Handler>
8348  static bool check(lua_State*, int, Handler&&, record& tracking) {
8349  tracking.use(0);
8350  return true;
8351  }
8352  };
8353 
8354  template <typename C>
8356  template <typename Handler>
8357  static bool check(lua_State*, int, Handler&&, record& tracking) {
8358  tracking.use(0);
8359  return true;
8360  }
8361  };
8362 
8363  template <typename C>
8365  template <typename Handler>
8366  static bool check(lua_State*, int, Handler&&, record& tracking) {
8367  tracking.use(0);
8368  return true;
8369  }
8370  };
8371 
8372  template <typename C>
8373  struct checker<type, type::poly, C> {
8374  template <typename Handler>
8375  static bool check(lua_State*, int, Handler&&, record& tracking) {
8376  tracking.use(0);
8377  return true;
8378  }
8379  };
8380 
8381  template <typename T, typename C>
8382  struct checker<T, type::poly, C> {
8383  template <typename Handler>
8384  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8385  tracking.use(1);
8386  bool success = is_lua_reference<T>::value || !lua_isnone(L, index);
8387  if (!success) {
8388  // expected type, actual type
8389  handler(L, index, type::poly, type_of(L, index), "");
8390  }
8391  return success;
8392  }
8393  };
8394 
8395  template <typename T, typename C>
8396  struct checker<T, type::lightuserdata, C> {
8397  template <typename Handler>
8398  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8399  tracking.use(1);
8400  type t = type_of(L, index);
8401  bool success = t == type::userdata || t == type::lightuserdata;
8402  if (!success) {
8403  // expected type, actual type
8404  handler(L, index, type::lightuserdata, t, "");
8405  }
8406  return success;
8407  }
8408  };
8409 
8410  template <typename C>
8412  template <typename Handler>
8413  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8414  tracking.use(1);
8415  type t = type_of(L, index);
8416  bool success = t == type::userdata;
8417  if (!success) {
8418  // expected type, actual type
8419  handler(L, index, type::userdata, t, "");
8420  }
8421  return success;
8422  }
8423  };
8424 
8425  template <typename B, typename C>
8427  template <typename Handler>
8428  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8429  return stack::check<userdata_value>(L, index, std::forward<Handler>(handler), tracking);
8430  }
8431  };
8432 
8433  template <typename T, typename C>
8434  struct checker<user<T>, type::userdata, C> : checker<user<T>, type::lightuserdata, C> {};
8435 
8436  template <typename T, typename C>
8437  struct checker<non_null<T>, type::userdata, C> : checker<T, lua_type_of<T>::value, C> {};
8438 
8439  template <typename C>
8440  struct checker<lua_CFunction, type::function, C> : stack_detail::basic_check<type::function, lua_iscfunction> {};
8441  template <typename C>
8442  struct checker<std::remove_pointer_t<lua_CFunction>, type::function, C> : checker<lua_CFunction, type::function, C> {};
8443  template <typename C>
8444  struct checker<c_closure, type::function, C> : checker<lua_CFunction, type::function, C> {};
8445 
8446  template <typename T, typename C>
8447  struct checker<T, type::function, C> {
8448  template <typename Handler>
8449  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8450  tracking.use(1);
8451  type t = type_of(L, index);
8452  if (t == type::lua_nil || t == type::none || t == type::function) {
8453  // allow for lua_nil to be returned
8454  return true;
8455  }
8456  if (t != type::userdata && t != type::table) {
8457  handler(L, index, type::function, t, "must be a function or table or a userdata");
8458  return false;
8459  }
8460  // Do advanced check for call-style userdata?
8461  static const auto& callkey = to_string(meta_function::call);
8462  if (lua_getmetatable(L, index) == 0) {
8463  // No metatable, no __call key possible
8464  handler(L, index, type::function, t, "value is not a function and does not have overriden metatable");
8465  return false;
8466  }
8467  if (lua_isnoneornil(L, -1)) {
8468  lua_pop(L, 1);
8469  handler(L, index, type::function, t, "value is not a function and does not have valid metatable");
8470  return false;
8471  }
8472  lua_getfield(L, -1, &callkey[0]);
8473  if (lua_isnoneornil(L, -1)) {
8474  lua_pop(L, 2);
8475  handler(L, index, type::function, t, "value's metatable does not have __call overridden in metatable, cannot call this type");
8476  return false;
8477  }
8478  // has call, is definitely a function
8479  lua_pop(L, 2);
8480  return true;
8481  }
8482  };
8483 
8484  template <typename T, typename C>
8485  struct checker<T, type::table, C> {
8486  template <typename Handler>
8487  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8488  tracking.use(1);
8489  type t = type_of(L, index);
8490  if (t == type::table) {
8491  return true;
8492  }
8493  if (t != type::userdata) {
8494  handler(L, index, type::table, t, "value is not a table or a userdata that can behave like one");
8495  return false;
8496  }
8497  return true;
8498  }
8499  };
8500 
8501  template <type expected, typename C>
8502  struct checker<metatable_t, expected, C> {
8503  template <typename Handler>
8504  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8505  tracking.use(1);
8506  if (lua_getmetatable(L, index) == 0) {
8507  return true;
8508  }
8509  type t = type_of(L, -1);
8510  if (t == type::table || t == type::none || t == type::lua_nil) {
8511  lua_pop(L, 1);
8512  return true;
8513  }
8514  if (t != type::userdata) {
8515  lua_pop(L, 1);
8516  handler(L, index, expected, t, "value does not have a valid metatable");
8517  return false;
8518  }
8519  return true;
8520  }
8521  };
8522 
8523  template <typename C>
8524  struct checker<env_t, type::poly, C> {
8525  template <typename Handler>
8526  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8527  tracking.use(1);
8528  type t = type_of(L, index);
8529  if (t == type::table || t == type::none || t == type::lua_nil || t == type::userdata) {
8530  return true;
8531  }
8532  handler(L, index, type::table, t, "value cannot not have a valid environment");
8533  return true;
8534  }
8535  };
8536 
8537  template <typename E, typename C>
8538  struct checker<basic_environment<E>, type::poly, C> {
8539  template <typename Handler>
8540  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8541  tracking.use(1);
8542  if (lua_getmetatable(L, index) == 0) {
8543  return true;
8544  }
8545  type t = type_of(L, -1);
8546  if (t == type::table || t == type::none || t == type::lua_nil) {
8547  lua_pop(L, 1);
8548  return true;
8549  }
8550  if (t != type::userdata) {
8551  lua_pop(L, 1);
8552  handler(L, index, type::table, t, "value does not have a valid metatable");
8553  return false;
8554  }
8555  return true;
8556  }
8557  };
8558 
8559  template <typename T, typename C>
8560  struct checker<detail::as_value_tag<T>, type::userdata, C> {
8561  template <typename Handler>
8562  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8563  const type indextype = type_of(L, index);
8564  return check(types<T>(), L, index, indextype, handler, tracking);
8565  }
8566 
8567  template <typename U, typename Handler>
8568  static bool check(types<U>, lua_State* L, int index, type indextype, Handler&& handler, record& tracking) {
8569 #if defined(SOL_ENABLE_INTEROP) && SOL_ENABLE_INTEROP
8571  (void)uc;
8572  if (uc.check(L, index, indextype, handler, tracking)) {
8573  return true;
8574  }
8575 #endif // interop extensibility
8576  tracking.use(1);
8577  if (indextype != type::userdata) {
8578  handler(L, index, type::userdata, indextype, "value is not a valid userdata");
8579  return false;
8580  }
8581  if (meta::any<std::is_same<T, lightuserdata_value>, std::is_same<T, userdata_value>, std::is_same<T, userdata>, std::is_same<T, lightuserdata>>::value)
8582  return true;
8583  if (lua_getmetatable(L, index) == 0) {
8584  return true;
8585  }
8586  int metatableindex = lua_gettop(L);
8587  if (stack_detail::check_metatable<U>(L, metatableindex))
8588  return true;
8589  if (stack_detail::check_metatable<U*>(L, metatableindex))
8590  return true;
8592  return true;
8593  if (stack_detail::check_metatable<as_container_t<U>>(L, metatableindex))
8594  return true;
8595  bool success = false;
8597  auto pn = stack::pop_n(L, 1);
8598  lua_pushstring(L, &detail::base_class_check_key()[0]);
8599  lua_rawget(L, metatableindex);
8600  if (type_of(L, -1) != type::lua_nil) {
8601  void* basecastdata = lua_touserdata(L, -1);
8602  detail::inheritance_check_function ic = reinterpret_cast<detail::inheritance_check_function>(basecastdata);
8603  success = ic(usertype_traits<T>::qualified_name());
8604  }
8605  }
8606  if (!success) {
8607  lua_pop(L, 1);
8608  handler(L, index, type::userdata, indextype, "value at this index does not properly reflect the desired type");
8609  return false;
8610  }
8611  lua_pop(L, 1);
8612  return true;
8613  }
8614  };
8615 
8616  template <typename T, typename C>
8617  struct checker<detail::as_pointer_tag<T>, type::userdata, C> {
8618  template <typename Handler>
8619  static bool check(lua_State* L, int index, type indextype, Handler&& handler, record& tracking) {
8620  if (indextype == type::lua_nil) {
8621  tracking.use(1);
8622  return true;
8623  }
8624  return stack_detail::check_usertype<T>(std::false_type(), L, index, indextype, std::forward<Handler>(handler), tracking);
8625  }
8626 
8627  template <typename Handler>
8628  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8629  const type indextype = type_of(L, index);
8630  return check(L, index, handler, indextype, tracking);
8631  }
8632  };
8633 
8634  template <typename T, typename C>
8635  struct checker<T, type::userdata, C> {
8636  template <typename Handler>
8637  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8638  return check_usertype<T>(L, index, std::forward<Handler>(handler), tracking);
8639  }
8640  };
8641 
8642  template <typename T, typename C>
8643  struct checker<T*, type::userdata, C> {
8644  template <typename Handler>
8645  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8646  return check_usertype<T*>(L, index, std::forward<Handler>(handler), tracking);
8647  }
8648  };
8649 
8650  template <typename X>
8651  struct checker<X, type::userdata, std::enable_if_t<is_unique_usertype<X>::value>> {
8653  template <typename Handler>
8654  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8655  const type indextype = type_of(L, index);
8656  tracking.use(1);
8657  if (indextype != type::userdata) {
8658  handler(L, index, type::userdata, indextype, "value is not a userdata");
8659  return false;
8660  }
8661  if (lua_getmetatable(L, index) == 0) {
8662  return true;
8663  }
8664  int metatableindex = lua_gettop(L);
8666  void* memory = lua_touserdata(L, index);
8668  detail::unique_destructor& pdx = *static_cast<detail::unique_destructor*>(memory);
8669  bool success = &detail::usertype_unique_alloc_destroy<T, X> == pdx;
8670  if (!success) {
8671  memory = detail::align_usertype_unique_tag<true>(memory);
8672 #if 0
8673  // New version
8674 #else
8675  const char*& name_tag = *static_cast<const char**>(memory);
8676  success = usertype_traits<X>::qualified_name() == name_tag;
8677 #endif
8678  if (!success) {
8679  handler(L, index, type::userdata, indextype, "value is a userdata but is not the correct unique usertype");
8680  }
8681  }
8682  return success;
8683  }
8684  lua_pop(L, 1);
8685  handler(L, index, type::userdata, indextype, "unrecognized userdata (not pushed by sol?)");
8686  return false;
8687  }
8688  };
8689 
8690  template <typename T, typename C>
8691  struct checker<std::reference_wrapper<T>, type::userdata, C> {
8692  template <typename Handler>
8693  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8694  return stack::check<T>(L, index, std::forward<Handler>(handler), tracking);
8695  }
8696  };
8697 
8698  template <typename... Args, typename C>
8699  struct checker<std::tuple<Args...>, type::poly, C> {
8700  template <typename Handler>
8701  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8702  return stack::multi_check<Args...>(L, index, std::forward<Handler>(handler), tracking);
8703  }
8704  };
8705 
8706  template <typename A, typename B, typename C>
8707  struct checker<std::pair<A, B>, type::poly, C> {
8708  template <typename Handler>
8709  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8710  return stack::multi_check<A, B>(L, index, std::forward<Handler>(handler), tracking);
8711  }
8712  };
8713 
8714  template <typename T, typename C>
8715  struct checker<optional<T>, type::poly, C> {
8716  template <typename Handler>
8717  static bool check(lua_State* L, int index, Handler&&, record& tracking) {
8718  type t = type_of(L, index);
8719  if (t == type::none) {
8720  tracking.use(0);
8721  return true;
8722  }
8723  if (t == type::lua_nil) {
8724  tracking.use(1);
8725  return true;
8726  }
8727  return stack::check<T>(L, index, no_panic, tracking);
8728  }
8729  };
8730 
8731 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
8732 
8733  template <typename T, typename C>
8734  struct checker<std::optional<T>, type::poly, C> {
8735  template <typename Handler>
8736  static bool check(lua_State* L, int index, Handler&&, record& tracking) {
8737  type t = type_of(L, index);
8738  if (t == type::none) {
8739  tracking.use(0);
8740  return true;
8741  }
8742  if (t == type::lua_nil) {
8743  tracking.use(1);
8744  return true;
8745  }
8746  return stack::check<T>(L, index, no_panic, tracking);
8747  }
8748  };
8749 
8750 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
8751 
8752  template <typename... Tn, typename C>
8753  struct checker<std::variant<Tn...>, type::poly, C> {
8754  typedef std::variant<Tn...> V;
8755  typedef std::variant_size<V> V_size;
8756  typedef std::integral_constant<bool, V_size::value == 0> V_is_empty;
8757 
8758  template <typename Handler>
8759  static bool is_one(std::integral_constant<std::size_t, 0>, lua_State* L, int index, Handler&& handler, record& tracking) {
8760  if (V_is_empty::value && lua_isnone(L, index)) {
8761  return true;
8762  }
8763  tracking.use(1);
8764  handler(L, index, type::poly, type_of(L, index), "value does not fit any type present in the variant");
8765  return false;
8766  }
8767 
8768  template <std::size_t I, typename Handler>
8769  static bool is_one(std::integral_constant<std::size_t, I>, lua_State* L, int index, Handler&& handler, record& tracking) {
8770  typedef std::variant_alternative_t<I - 1, V> T;
8771  record temp_tracking = tracking;
8772  if (stack::check<T>(L, index, no_panic, temp_tracking)) {
8773  tracking = temp_tracking;
8774  return true;
8775  }
8776  return is_one(std::integral_constant<std::size_t, I - 1>(), L, index, std::forward<Handler>(handler), tracking);
8777  }
8778 
8779  template <typename Handler>
8780  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8781  return is_one(std::integral_constant<std::size_t, V_size::value>(), L, index, std::forward<Handler>(handler), tracking);
8782  }
8783  };
8784 
8785 #endif // SOL_STD_VARIANT
8786 
8787 #endif // SOL_CXX17_FEATURES
8788 }
8789 } // namespace sol::stack
8790 
8791 // end of sol/stack_check_unqualified.hpp
8792 
8793 // beginning of sol/stack_check_qualified.hpp
8794 
8795 namespace sol {
8796 namespace stack {
8797 
8798 #if 0
8799  template <typename X>
8800  struct qualified_checker<X, type::userdata, std::enable_if_t<is_unique_usertype<X>::value && !std::is_reference<X>::value>> {
8802  typedef typename u_traits::type T;
8803 
8804  template <typename Handler>
8805  static bool check(std::false_type, lua_State* L, int index, Handler&& handler, record& tracking) {
8806  return stack::unqualified_check<X>(L, index, std::forward<Handler>(handler), tracking);
8807  }
8808 
8809  template <typename Handler>
8810  static bool check(std::true_type, lua_State* L, int index, Handler&& handler, record& tracking) {
8811  // we have a unique pointer type that can be
8812  // rebound to a base/derived type
8813  const type indextype = type_of(L, index);
8814  tracking.use(1);
8815  if (indextype != type::userdata) {
8816  handler(L, index, type::userdata, indextype, "value is not a userdata");
8817  return false;
8818  }
8819  if (lua_getmetatable(L, index) == 0) {
8820  return true;
8821  }
8822  int metatableindex = lua_gettop(L);
8823  void* basecastdata = lua_touserdata(L, index);
8824  void* memory = detail::align_usertype_unique_destructor(basecastdata);
8825  detail::unique_destructor& pdx = *static_cast<detail::unique_destructor*>(memory);
8826  if (&detail::usertype_unique_alloc_destroy<T, X> == pdx) {
8827  return true;
8828  }
8830  memory = detail::align_usertype_unique_cast<true>(memory);
8834  if (ic(nullptr, basecastdata, ti, rebind_ti)) {
8835  lua_pop(L, 1);
8836  }
8837  }
8838  handler(L, index, type::userdata, indextype, "value is a userdata but is not the correct unique usertype");
8839  return false;
8840  }
8841 
8842  template <typename Handler>
8843  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8844  return check(meta::neg<std::is_void<typename u_traits::base_id>>(), L, index, std::forward<Handler>(handler), tracking);
8845  }
8846  };
8847 
8848 #endif // Not implemented right now...
8849 
8850  template <typename X>
8851  struct qualified_checker<X, type::userdata, std::enable_if_t<is_container<meta::unqualified_t<X>>::value && !std::is_reference<X>::value>> {
8852  template <typename Handler>
8853  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
8854  if (type_of(L, index) == type::userdata) {
8855  return stack::unqualified_check<X>(L, index, std::forward<Handler>(handler), tracking);
8856  }
8857  else {
8858  return stack::unqualified_check<nested<X>>(L, index, std::forward<Handler>(handler), tracking);
8859  }
8860  }
8861  };
8862 }
8863 } // namespace sol::stack
8864 
8865 // end of sol/stack_check_qualified.hpp
8866 
8867 // end of sol/stack_check.hpp
8868 
8869 // beginning of sol/stack_get.hpp
8870 
8871 // beginning of sol/stack_get_unqualified.hpp
8872 
8873 // beginning of sol/overload.hpp
8874 
8875 namespace sol {
8876  template <typename... Functions>
8877  struct overload_set {
8878  std::tuple<Functions...> functions;
8879  template <typename Arg, typename... Args, meta::disable<std::is_same<overload_set, meta::unqualified_t<Arg>>> = meta::enabler>
8880  overload_set(Arg&& arg, Args&&... args)
8881  : functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
8882  }
8883  overload_set(const overload_set&) = default;
8884  overload_set(overload_set&&) = default;
8885  overload_set& operator=(const overload_set&) = default;
8886  overload_set& operator=(overload_set&&) = default;
8887  };
8888 
8889  template <typename... Args>
8890  decltype(auto) overload(Args&&... args) {
8891  return overload_set<std::decay_t<Args>...>(std::forward<Args>(args)...);
8892  }
8893 } // namespace sol
8894 
8895 // end of sol/overload.hpp
8896 
8897 // beginning of sol/unicode.hpp
8898 
8899 namespace sol {
8900  // Everything here was lifted pretty much straight out of
8901  // ogonek, because fuck figuring it out=
8902  namespace unicode {
8903  enum class error_code {
8904  ok = 0,
8911  };
8912 
8913  inline const string_view& to_string(error_code ec) {
8914  static const string_view arr[4] = {
8915  "ok",
8916  "invalid code points",
8917  "invalid code unit",
8918  "overlong sequence"
8919  };
8920  return arr[static_cast<std::size_t>(ec)];
8921  }
8922 
8923  template <typename It>
8926  char32_t codepoint;
8927  It next;
8928  };
8929 
8930  template <typename C>
8933  std::size_t code_units_size;
8934  std::array<C, 4> code_units;
8935  };
8936 
8938  // codepoint related
8939  static constexpr char32_t last_code_point = 0x10FFFF;
8940 
8941  static constexpr char32_t first_lead_surrogate = 0xD800;
8942  static constexpr char32_t last_lead_surrogate = 0xDBFF;
8943 
8944  static constexpr char32_t first_trail_surrogate = 0xDC00;
8945  static constexpr char32_t last_trail_surrogate = 0xDFFF;
8946 
8947  static constexpr char32_t first_surrogate = first_lead_surrogate;
8948  static constexpr char32_t last_surrogate = last_trail_surrogate;
8949 
8950  static constexpr bool is_lead_surrogate(char32_t u) {
8951  return u >= first_lead_surrogate && u <= last_lead_surrogate;
8952  }
8953  static constexpr bool is_trail_surrogate(char32_t u) {
8954  return u >= first_trail_surrogate && u <= last_trail_surrogate;
8955  }
8956  static constexpr bool is_surrogate(char32_t u) {
8957  return u >= first_surrogate && u <= last_surrogate;
8958  }
8959 
8960  // utf8 related
8961  static constexpr auto last_1byte_value = 0x7Fu;
8962  static constexpr auto last_2byte_value = 0x7FFu;
8963  static constexpr auto last_3byte_value = 0xFFFFu;
8964 
8965  static constexpr auto start_2byte_mask = 0x80u;
8966  static constexpr auto start_3byte_mask = 0xE0u;
8967  static constexpr auto start_4byte_mask = 0xF0u;
8968 
8969  static constexpr auto continuation_mask = 0xC0u;
8970  static constexpr auto continuation_signature = 0x80u;
8971 
8972  static constexpr int sequence_length(unsigned char b) {
8973  return (b & start_2byte_mask) == 0 ? 1
8974  : (b & start_3byte_mask) != start_3byte_mask ? 2
8975  : (b & start_4byte_mask) != start_4byte_mask ? 3
8976  : 4;
8977  }
8978 
8979  static constexpr char32_t decode(unsigned char b0, unsigned char b1) {
8980  return ((b0 & 0x1F) << 6) | (b1 & 0x3F);
8981  }
8982  static constexpr char32_t decode(unsigned char b0, unsigned char b1, unsigned char b2) {
8983  return ((b0 & 0x0F) << 12) | ((b1 & 0x3F) << 6) | (b2 & 0x3F);
8984  }
8985  static constexpr char32_t decode(unsigned char b0, unsigned char b1, unsigned char b2, unsigned char b3) {
8986  return ((b0 & 0x07) << 18) | ((b1 & 0x3F) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F);
8987  }
8988 
8989  // utf16 related
8990  static constexpr char32_t last_bmp_value = 0xFFFF;
8991  static constexpr char32_t normalizing_value = 0x10000;
8992  static constexpr int lead_surrogate_bitmask = 0xFFC00;
8993  static constexpr int trail_surrogate_bitmask = 0x3FF;
8994  static constexpr int lead_shifted_bits = 10;
8995  static constexpr char32_t replacement = 0xFFFD;
8996 
8997  static char32_t combine_surrogates(char16_t lead, char16_t trail) {
8998  auto hi = lead - first_lead_surrogate;
8999  auto lo = trail - first_trail_surrogate;
9000  return normalizing_value + ((hi << lead_shifted_bits) | lo);
9001  }
9002  };
9003 
9004  inline encoded_result<char> code_point_to_utf8(char32_t codepoint) {
9006  er.error = error_code::ok;
9007  if (codepoint <= unicode_detail::last_1byte_value) {
9008  er.code_units_size = 1;
9009  er.code_units = std::array<char, 4>{ { static_cast<char>(codepoint) } };
9010  }
9011  else if (codepoint <= unicode_detail::last_2byte_value) {
9012  er.code_units_size = 2;
9013  er.code_units = std::array<char, 4>{{
9014  static_cast<char>(0xC0 | ((codepoint & 0x7C0) >> 6)),
9015  static_cast<char>(0x80 | (codepoint & 0x3F)),
9016  }};
9017  }
9018  else if (codepoint <= unicode_detail::last_3byte_value) {
9019  er.code_units_size = 3;
9020  er.code_units = std::array<char, 4>{{
9021  static_cast<char>(0xE0 | ((codepoint & 0xF000) >> 12)),
9022  static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
9023  static_cast<char>(0x80 | (codepoint & 0x3F)),
9024  }};
9025  }
9026  else {
9027  er.code_units_size = 4;
9028  er.code_units = std::array<char, 4>{ {
9029  static_cast<char>(0xF0 | ((codepoint & 0x1C0000) >> 18)),
9030  static_cast<char>(0x80 | ((codepoint & 0x3F000) >> 12)),
9031  static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
9032  static_cast<char>(0x80 | (codepoint & 0x3F)),
9033  } };
9034  }
9035  return er;
9036  }
9037 
9038  inline encoded_result<char16_t> code_point_to_utf16(char32_t codepoint) {
9040 
9041  if (codepoint <= unicode_detail::last_bmp_value) {
9042  er.code_units_size = 1;
9043  er.code_units = std::array<char16_t, 4>{ { static_cast<char16_t>(codepoint) } };
9044  er.error = error_code::ok;
9045  }
9046  else {
9047  auto normal = codepoint - unicode_detail::normalizing_value;
9048  auto lead = unicode_detail::first_lead_surrogate + ((normal & unicode_detail::lead_surrogate_bitmask) >> unicode_detail::lead_shifted_bits);
9049  auto trail = unicode_detail::first_trail_surrogate + (normal & unicode_detail::trail_surrogate_bitmask);
9050  er.code_units = std::array<char16_t, 4>{ {
9051  static_cast<char16_t>(lead),
9052  static_cast<char16_t>(trail)
9053  } };
9054  er.code_units_size = 2;
9055  er.error = error_code::ok;
9056  }
9057  return er;
9058  }
9059 
9060  inline encoded_result<char32_t> code_point_to_utf32(char32_t codepoint) {
9062  er.code_units_size = 1;
9063  er.code_units[0] = codepoint;
9064  er.error = error_code::ok;
9065  return er;
9066  }
9067 
9068  template <typename It>
9069  inline decoded_result<It> utf8_to_code_point(It it, It last) {
9070  decoded_result<It> dr;
9071  if (it == last) {
9072  dr.next = it;
9073  dr.error = error_code::sequence_too_short;
9074  return dr;
9075  }
9076 
9077  unsigned char b0 = *it;
9078  std::size_t length = unicode_detail::sequence_length(b0);
9079 
9080  if (length == 1) {
9081  dr.codepoint = static_cast<char32_t>(b0);
9082  dr.error = error_code::ok;
9083  ++it;
9084  dr.next = it;
9085  return dr;
9086  }
9087 
9088  auto is_invalid = [](unsigned char b) { return b == 0xC0 || b == 0xC1 || b > 0xF4; };
9089  auto is_continuation = [](unsigned char b) {
9090  return (b & unicode_detail::continuation_mask) == unicode_detail::continuation_signature;
9091  };
9092 
9093  if (is_invalid(b0) || is_continuation(b0)) {
9094  dr.error = error_code::invalid_code_unit;
9095  dr.next = it;
9096  return dr;
9097  }
9098 
9099  ++it;
9100  std::array<unsigned char, 4> b;
9101  b[0] = b0;
9102  for (std::size_t i = 1; i < length; ++i) {
9103  b[i] = *it;
9104  if (!is_continuation(b[i])) {
9105  dr.error = error_code::invalid_code_unit;
9106  dr.next = it;
9107  return dr;
9108  }
9109  ++it;
9110  }
9111 
9112  char32_t decoded;
9113  switch (length) {
9114  case 2:
9115  decoded = unicode_detail::decode(b[0], b[1]);
9116  break;
9117  case 3:
9118  decoded = unicode_detail::decode(b[0], b[1], b[2]);
9119  break;
9120  default:
9121  decoded = unicode_detail::decode(b[0], b[1], b[2], b[3]);
9122  break;
9123  }
9124 
9125  auto is_overlong = [](char32_t u, std::size_t bytes) {
9126  return u <= unicode_detail::last_1byte_value
9127  || (u <= unicode_detail::last_2byte_value && bytes > 2)
9128  || (u <= unicode_detail::last_3byte_value && bytes > 3);
9129  };
9130  if (is_overlong(decoded, length)) {
9131  dr.error = error_code::overlong_sequence;
9132  return dr;
9133  }
9134  if (unicode_detail::is_surrogate(decoded) || decoded > unicode_detail::last_code_point) {
9135  dr.error = error_code::invalid_code_point;
9136  return dr;
9137  }
9138 
9139  // then everything is fine
9140  dr.codepoint = decoded;
9141  dr.error = error_code::ok;
9142  dr.next = it;
9143  return dr;
9144  }
9145 
9146  template <typename It>
9147  inline decoded_result<It> utf16_to_code_point(It it, It last) {
9148  decoded_result<It> dr;
9149  if (it == last) {
9150  dr.next = it;
9151  dr.error = error_code::sequence_too_short;
9152  return dr;
9153  }
9154 
9155  char16_t lead = static_cast<char16_t>(*it);
9156 
9157  if (!unicode_detail::is_surrogate(lead)) {
9158  ++it;
9159  dr.codepoint = static_cast<char32_t>(lead);
9160  dr.next = it;
9161  dr.error = error_code::ok;
9162  return dr;
9163  }
9164  if (!unicode_detail::is_lead_surrogate(lead)) {
9165  dr.error = error_code::invalid_leading_surrogate;
9166  dr.next = it;
9167  return dr;
9168  }
9169 
9170  ++it;
9171  auto trail = *it;
9172  if (!unicode_detail::is_trail_surrogate(trail)) {
9173  dr.error = error_code::invalid_trailing_surrogate;
9174  dr.next = it;
9175  return dr;
9176  }
9177 
9178  dr.codepoint = unicode_detail::combine_surrogates(lead, trail);
9179  dr.next = ++it;
9180  dr.error = error_code::ok;
9181  return dr;
9182  }
9183 
9184  template <typename It>
9185  inline decoded_result<It> utf32_to_code_point(It it, It last) {
9186  decoded_result<It> dr;
9187  if (it == last) {
9188  dr.next = it;
9189  dr.error = error_code::sequence_too_short;
9190  return dr;
9191  }
9192  dr.codepoint = static_cast<char32_t>(*it);
9193  dr.next = ++it;
9194  dr.error = error_code::ok;
9195  return dr;
9196  }
9197  }
9198 }
9199 // end of sol/unicode.hpp
9200 
9201 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
9202 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
9203 #endif // Apple clang screwed up
9204 #endif // C++17
9205 
9206 namespace sol {
9207 namespace stack {
9208 
9209  template <typename U>
9210  struct userdata_getter<U> {
9212 
9213  static std::pair<bool, T*> get(lua_State*, int, void*, record&) {
9214  return { false, nullptr };
9215  }
9216  };
9217 
9218  template <typename T, typename>
9219  struct getter {
9220  static T& get(lua_State* L, int index, record& tracking) {
9221  return getter<detail::as_value_tag<T>>{}.get(L, index, tracking);
9222  }
9223  };
9224 
9225  template <typename T, typename C>
9226  struct qualified_getter : getter<meta::unqualified_t<T>, C> {};
9227 
9228  template <typename T>
9229  struct getter<T, std::enable_if_t<std::is_floating_point<T>::value>> {
9230  static T get(lua_State* L, int index, record& tracking) {
9231  tracking.use(1);
9232  return static_cast<T>(lua_tonumber(L, index));
9233  }
9234  };
9235 
9236  template <typename T>
9237  struct getter<T, std::enable_if_t<std::is_integral<T>::value>> {
9238  static T get(lua_State* L, int index, record& tracking) {
9239  tracking.use(1);
9240 #if SOL_LUA_VERSION >= 503
9241  if (lua_isinteger(L, index) != 0) {
9242  return static_cast<T>(lua_tointeger(L, index));
9243  }
9244 #endif
9245  return static_cast<T>(llround(lua_tonumber(L, index)));
9246  }
9247  };
9248 
9249  template <typename T>
9250  struct getter<T, std::enable_if_t<std::is_enum<T>::value>> {
9251  static T get(lua_State* L, int index, record& tracking) {
9252  tracking.use(1);
9253  return static_cast<T>(lua_tointegerx(L, index, nullptr));
9254  }
9255  };
9256 
9257  template <typename T>
9258  struct getter<as_table_t<T>> {
9260 
9261  template <typename V>
9262  static void push_back_at_end(std::true_type, types<V>, lua_State* L, T& arr, std::size_t) {
9263  arr.push_back(stack::get<V>(L, -lua_size<V>::value));
9264  }
9265 
9266  template <typename V>
9267  static void push_back_at_end(std::false_type, types<V> t, lua_State* L, T& arr, std::size_t idx) {
9268  insert_at_end(meta::has_insert<Tu>(), t, L, arr, idx);
9269  }
9270 
9271  template <typename V>
9272  static void insert_at_end(std::true_type, types<V>, lua_State* L, T& arr, std::size_t) {
9273  using std::end;
9274  arr.insert(end(arr), stack::get<V>(L, -lua_size<V>::value));
9275  }
9276 
9277  template <typename V>
9278  static void insert_at_end(std::false_type, types<V>, lua_State* L, T& arr, std::size_t idx) {
9279  arr[idx] = stack::get<V>(L, -lua_size<V>::value);
9280  }
9281 
9282  static bool max_size_check(std::false_type, T&, std::size_t) {
9283  return false;
9284  }
9285 
9286  static bool max_size_check(std::true_type, T& arr, std::size_t idx) {
9287  return idx >= arr.max_size();
9288  }
9289 
9290  static T get(lua_State* L, int relindex, record& tracking) {
9291  return get(meta::has_key_value_pair<meta::unqualified_t<T>>(), L, relindex, tracking);
9292  }
9293 
9294  static T get(std::false_type, lua_State* L, int relindex, record& tracking) {
9295  typedef typename T::value_type V;
9296  return get(types<V>(), L, relindex, tracking);
9297  }
9298 
9299  template <typename V>
9300  static T get(types<V> t, lua_State* L, int relindex, record& tracking) {
9301  tracking.use(1);
9302 
9303  int index = lua_absindex(L, relindex);
9304  T arr;
9305  std::size_t idx = 0;
9306 #if SOL_LUA_VERSION >= 503
9307  // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
9308  // Questionable in 5.4
9309  for (lua_Integer i = 0;; i += lua_size<V>::value) {
9310  if (max_size_check(meta::has_max_size<Tu>(), arr, idx)) {
9311  return arr;
9312  }
9313  bool isnil = false;
9314  for (int vi = 0; vi < lua_size<V>::value; ++vi) {
9315 #if defined(LUA_NILINTABLE) && LUA_NILINTABLE
9316  lua_pushinteger(L, static_cast<lua_Integer>(i + vi));
9317  if (lua_keyin(L, index) == 0) {
9318  // it's time to stop
9319  isnil = true;
9320  }
9321  else {
9322  // we have a key, have to get the value
9323  lua_geti(L, index, i + vi);
9324  }
9325 #else
9326  type vt = static_cast<type>(lua_geti(L, index, i + vi));
9327  isnil = vt == type::none
9328  || vt == type::lua_nil;
9329 #endif
9330  if (isnil) {
9331  if (i == 0) {
9332  break;
9333  }
9334 #if defined(LUA_NILINTABLE) && LUA_NILINTABLE
9335  lua_pop(L, vi);
9336 #else
9337  lua_pop(L, (vi + 1));
9338 #endif
9339  return arr;
9340  }
9341  }
9342  if (isnil) {
9343 #if defined(LUA_NILINTABLE) && LUA_NILINTABLE
9344 #else
9345  lua_pop(L, lua_size<V>::value);
9346 #endif
9347  continue;
9348  }
9349  push_back_at_end(meta::has_push_back<Tu>(), t, L, arr, idx);
9350  ++idx;
9351  lua_pop(L, lua_size<V>::value);
9352  }
9353 #else
9354  // Zzzz slower but necessary thanks to the lower version API and missing functions qq
9355  for (lua_Integer i = 0;; i += lua_size<V>::value, lua_pop(L, lua_size<V>::value)) {
9356  if (idx >= arr.max_size()) {
9357  return arr;
9358  }
9359  bool isnil = false;
9360  for (int vi = 0; vi < lua_size<V>::value; ++vi) {
9361  lua_pushinteger(L, i);
9362  lua_gettable(L, index);
9363  type vt = type_of(L, -1);
9364  isnil = vt == type::lua_nil;
9365  if (isnil) {
9366  if (i == 0) {
9367  break;
9368  }
9369  lua_pop(L, (vi + 1));
9370  return arr;
9371  }
9372  }
9373  if (isnil)
9374  continue;
9375  push_back_at_end(meta::has_push_back<Tu>(), t, L, arr, idx);
9376  ++idx;
9377  }
9378 #endif
9379  return arr;
9380  }
9381 
9382  static T get(std::true_type, lua_State* L, int index, record& tracking) {
9383  typedef typename T::value_type P;
9384  typedef typename P::first_type K;
9385  typedef typename P::second_type V;
9386  return get(types<K, V>(), L, index, tracking);
9387  }
9388 
9389  template <typename K, typename V>
9390  static T get(types<K, V>, lua_State* L, int relindex, record& tracking) {
9391  tracking.use(1);
9392 
9393  T associative;
9394  int index = lua_absindex(L, relindex);
9395  lua_pushnil(L);
9396  while (lua_next(L, index) != 0) {
9397  decltype(auto) key = stack::check_get<K>(L, -2);
9398  if (!key) {
9399  lua_pop(L, 1);
9400  continue;
9401  }
9402  associative.emplace(std::forward<decltype(*key)>(*key), stack::get<V>(L, -1));
9403  lua_pop(L, 1);
9404  }
9405  return associative;
9406  }
9407  };
9408 
9409  template <typename T, typename Al>
9410  struct getter<as_table_t<std::forward_list<T, Al>>> {
9411  typedef std::forward_list<T, Al> C;
9412 
9413  static C get(lua_State* L, int relindex, record& tracking) {
9414  return get(meta::has_key_value_pair<C>(), L, relindex, tracking);
9415  }
9416 
9417  static C get(std::true_type, lua_State* L, int index, record& tracking) {
9418  typedef typename T::value_type P;
9419  typedef typename P::first_type K;
9420  typedef typename P::second_type V;
9421  return get(types<K, V>(), L, index, tracking);
9422  }
9423 
9424  static C get(std::false_type, lua_State* L, int relindex, record& tracking) {
9425  typedef typename C::value_type V;
9426  return get(types<V>(), L, relindex, tracking);
9427  }
9428 
9429  template <typename V>
9430  static C get(types<V>, lua_State* L, int relindex, record& tracking) {
9431  tracking.use(1);
9432 
9433  int index = lua_absindex(L, relindex);
9434  C arr;
9435  auto at = arr.cbefore_begin();
9436  std::size_t idx = 0;
9437 #if SOL_LUA_VERSION >= 503
9438  // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
9439  for (lua_Integer i = 0;; i += lua_size<V>::value, lua_pop(L, lua_size<V>::value)) {
9440  if (idx >= arr.max_size()) {
9441  return arr;
9442  }
9443  bool isnil = false;
9444  for (int vi = 0; vi < lua_size<V>::value; ++vi) {
9445  type t = static_cast<type>(lua_geti(L, index, i + vi));
9446  isnil = t == type::lua_nil;
9447  if (isnil) {
9448  if (i == 0) {
9449  break;
9450  }
9451  lua_pop(L, (vi + 1));
9452  return arr;
9453  }
9454  }
9455  if (isnil)
9456  continue;
9457  at = arr.insert_after(at, stack::get<V>(L, -lua_size<V>::value));
9458  ++idx;
9459  }
9460 #else
9461  // Zzzz slower but necessary thanks to the lower version API and missing functions qq
9462  for (lua_Integer i = 0;; i += lua_size<V>::value, lua_pop(L, lua_size<V>::value)) {
9463  if (idx >= arr.max_size()) {
9464  return arr;
9465  }
9466  bool isnil = false;
9467  for (int vi = 0; vi < lua_size<V>::value; ++vi) {
9468  lua_pushinteger(L, i);
9469  lua_gettable(L, index);
9470  type t = type_of(L, -1);
9471  isnil = t == type::lua_nil;
9472  if (isnil) {
9473  if (i == 0) {
9474  break;
9475  }
9476  lua_pop(L, (vi + 1));
9477  return arr;
9478  }
9479  }
9480  if (isnil)
9481  continue;
9482  at = arr.insert_after(at, stack::get<V>(L, -lua_size<V>::value));
9483  ++idx;
9484  }
9485 #endif
9486  return arr;
9487  }
9488 
9489  template <typename K, typename V>
9490  static C get(types<K, V>, lua_State* L, int relindex, record& tracking) {
9491  tracking.use(1);
9492 
9493  C associative;
9494  auto at = associative.cbefore_begin();
9495  int index = lua_absindex(L, relindex);
9496  lua_pushnil(L);
9497  while (lua_next(L, index) != 0) {
9498  decltype(auto) key = stack::check_get<K>(L, -2);
9499  if (!key) {
9500  lua_pop(L, 1);
9501  continue;
9502  }
9503  at = associative.emplace_after(at, std::forward<decltype(*key)>(*key), stack::get<V>(L, -1));
9504  lua_pop(L, 1);
9505  }
9506  return associative;
9507  }
9508  };
9509 
9510  template <typename T>
9511  struct getter<nested<T>, std::enable_if_t<!is_container<T>::value>> {
9512  static T get(lua_State* L, int index, record& tracking) {
9513  getter<T> g;
9514  // VC++ has a bad warning here: shut it up
9515  (void)g;
9516  return g.get(L, index, tracking);
9517  }
9518  };
9519 
9520  template <typename T>
9521  struct getter<nested<T>, std::enable_if_t<meta::all<is_container<T>, meta::neg<meta::has_key_value_pair<meta::unqualified_t<T>>>>::value>> {
9522  static T get(lua_State* L, int index, record& tracking) {
9523  typedef typename T::value_type V;
9525  // VC++ has a bad warning here: shut it up
9526  (void)g;
9527  return g.get(types<nested<V>>(), L, index, tracking);
9528  }
9529  };
9530 
9531  template <typename T>
9532  struct getter<nested<T>, std::enable_if_t<meta::all<is_container<T>, meta::has_key_value_pair<meta::unqualified_t<T>>>::value>> {
9533  static T get(lua_State* L, int index, record& tracking) {
9534  typedef typename T::value_type P;
9535  typedef typename P::first_type K;
9536  typedef typename P::second_type V;
9538  // VC++ has a bad warning here: shut it up
9539  (void)g;
9540  return g.get(types<K, nested<V>>(), L, index, tracking);
9541  }
9542  };
9543 
9544  template <typename T>
9545  struct getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
9546  static T get(lua_State* L, int index, record& tracking) {
9547  tracking.use(1);
9548  return T(L, index);
9549  }
9550  };
9551 
9552  template <>
9554  static userdata_value get(lua_State* L, int index, record& tracking) {
9555  tracking.use(1);
9556  return userdata_value(lua_touserdata(L, index));
9557  }
9558  };
9559 
9560  template <>
9562  static lightuserdata_value get(lua_State* L, int index, record& tracking) {
9563  tracking.use(1);
9564  return lightuserdata_value(lua_touserdata(L, index));
9565  }
9566  };
9567 
9568  template <typename T>
9569  struct getter<light<T>> {
9570  static light<T> get(lua_State* L, int index, record& tracking) {
9571  tracking.use(1);
9572  void* memory = lua_touserdata(L, index);
9573  return light<T>(static_cast<T*>(memory));
9574  }
9575  };
9576 
9577  template <typename T>
9578  struct getter<user<T>> {
9579  static std::add_lvalue_reference_t<T> get(lua_State* L, int index, record& tracking) {
9580  tracking.use(1);
9581  void* memory = lua_touserdata(L, index);
9582  memory = detail::align_user<T>(memory);
9583  return *static_cast<std::remove_reference_t<T>*>(memory);
9584  }
9585  };
9586 
9587  template <typename T>
9588  struct getter<user<T*>> {
9589  static T* get(lua_State* L, int index, record& tracking) {
9590  tracking.use(1);
9591  void* memory = lua_touserdata(L, index);
9592  memory = detail::align_user<T*>(memory);
9593  return static_cast<T*>(memory);
9594  }
9595  };
9596 
9597  template <>
9598  struct getter<type> {
9599  static type get(lua_State* L, int index, record& tracking) {
9600  tracking.use(1);
9601  return static_cast<type>(lua_type(L, index));
9602  }
9603  };
9604 
9605  template <>
9606  struct getter<bool> {
9607  static bool get(lua_State* L, int index, record& tracking) {
9608  tracking.use(1);
9609  return lua_toboolean(L, index) != 0;
9610  }
9611  };
9612 
9613  template <>
9614  struct getter<std::string> {
9615  static std::string get(lua_State* L, int index, record& tracking) {
9616  tracking.use(1);
9617  std::size_t len;
9618  auto str = lua_tolstring(L, index, &len);
9619  return std::string(str, len);
9620  }
9621  };
9622 
9623  template <>
9624  struct getter<const char*> {
9625  static const char* get(lua_State* L, int index, record& tracking) {
9626  tracking.use(1);
9627  size_t sz;
9628  return lua_tolstring(L, index, &sz);
9629  }
9630  };
9631 
9632  template <>
9633  struct getter<char> {
9634  static char get(lua_State* L, int index, record& tracking) {
9635  tracking.use(1);
9636  size_t len;
9637  auto str = lua_tolstring(L, index, &len);
9638  return len > 0 ? str[0] : '\0';
9639  }
9640  };
9641 
9642  template <typename Traits>
9643  struct getter<basic_string_view<char, Traits>> {
9644  static string_view get(lua_State* L, int index, record& tracking) {
9645  tracking.use(1);
9646  size_t sz;
9647  const char* str = lua_tolstring(L, index, &sz);
9648  return basic_string_view<char, Traits>(str, sz);
9649  }
9650  };
9651 
9652  template <typename Traits, typename Al>
9653  struct getter<std::basic_string<wchar_t, Traits, Al>> {
9654  typedef std::basic_string<wchar_t, Traits, Al> S;
9655  static S get(lua_State* L, int index, record& tracking) {
9656  typedef std::conditional_t<sizeof(wchar_t) == 2, char16_t, char32_t> Ch;
9657  typedef typename std::allocator_traits<Al>::template rebind_alloc<Ch> ChAl;
9658  typedef std::char_traits<Ch> ChTraits;
9660  (void)g;
9661  return g.template get_into<S>(L, index, tracking);
9662  }
9663  };
9664 
9665  template <typename Traits, typename Al>
9666  struct getter<std::basic_string<char16_t, Traits, Al>> {
9667  template <typename F>
9668  static void convert(const char* strb, const char* stre, F&& f) {
9669  char32_t cp = 0;
9670  for (const char* strtarget = strb; strtarget < stre;) {
9671  auto dr = unicode::utf8_to_code_point(strtarget, stre);
9672  if (dr.error != unicode::error_code::ok) {
9674  ++strtarget;
9675  }
9676  else {
9677  cp = dr.codepoint;
9678  strtarget = dr.next;
9679  }
9680  auto er = unicode::code_point_to_utf16(cp);
9681  f(er);
9682  }
9683  }
9684 
9685  template <typename S>
9686  static S get_into(lua_State* L, int index, record& tracking) {
9687  typedef typename S::value_type Ch;
9688  tracking.use(1);
9689  size_t len;
9690  auto utf8p = lua_tolstring(L, index, &len);
9691  if (len < 1)
9692  return S();
9693  std::size_t needed_size = 0;
9694  const char* strb = utf8p;
9695  const char* stre = utf8p + len;
9696  auto count_units = [&needed_size](const unicode::encoded_result<char16_t> er) {
9697  needed_size += er.code_units_size;
9698  };
9699  convert(strb, stre, count_units);
9700  S r(needed_size, static_cast<Ch>(0));
9701  r.resize(needed_size);
9702  Ch* target = &r[0];
9703  auto copy_units = [&target](const unicode::encoded_result<char16_t> er) {
9704  std::memcpy(target, er.code_units.data(), er.code_units_size * sizeof(Ch));
9705  target += er.code_units_size;
9706  };
9707  convert(strb, stre, copy_units);
9708  return r;
9709  }
9710 
9711  static std::basic_string<char16_t, Traits, Al> get(lua_State* L, int index, record& tracking) {
9712  return get_into<std::basic_string<char16_t, Traits, Al>>(L, index, tracking);
9713  }
9714  };
9715 
9716  template <typename Traits, typename Al>
9717  struct getter<std::basic_string<char32_t, Traits, Al>> {
9718  template <typename F>
9719  static void convert(const char* strb, const char* stre, F&& f) {
9720  char32_t cp = 0;
9721  for (const char* strtarget = strb; strtarget < stre;) {
9722  auto dr = unicode::utf8_to_code_point(strtarget, stre);
9723  if (dr.error != unicode::error_code::ok) {
9725  ++strtarget;
9726  }
9727  else {
9728  cp = dr.codepoint;
9729  strtarget = dr.next;
9730  }
9731  auto er = unicode::code_point_to_utf32(cp);
9732  f(er);
9733  }
9734  }
9735 
9736  template <typename S>
9737  static S get_into(lua_State* L, int index, record& tracking) {
9738  typedef typename S::value_type Ch;
9739  tracking.use(1);
9740  size_t len;
9741  auto utf8p = lua_tolstring(L, index, &len);
9742  if (len < 1)
9743  return S();
9744  std::size_t needed_size = 0;
9745  const char* strb = utf8p;
9746  const char* stre = utf8p + len;
9747  auto count_units = [&needed_size](const unicode::encoded_result<char32_t> er) {
9748  needed_size += er.code_units_size;
9749  };
9750  convert(strb, stre, count_units);
9751  S r(needed_size, static_cast<Ch>(0));
9752  r.resize(needed_size);
9753  Ch* target = &r[0];
9754  auto copy_units = [&target](const unicode::encoded_result<char32_t> er) {
9755  std::memcpy(target, er.code_units.data(), er.code_units_size * sizeof(Ch));
9756  target += er.code_units_size;
9757  };
9758  convert(strb, stre, copy_units);
9759  return r;
9760  }
9761 
9762  static std::basic_string<char32_t, Traits, Al> get(lua_State* L, int index, record& tracking) {
9763  return get_into<std::basic_string<char32_t, Traits, Al>>(L, index, tracking);
9764  }
9765  };
9766 
9767  template <>
9768  struct getter<char16_t> {
9769  static char16_t get(lua_State* L, int index, record& tracking) {
9770  string_view utf8 = stack::get<string_view>(L, index, tracking);
9771  const char* strb = utf8.data();
9772  const char* stre = utf8.data() + utf8.size();
9773  char32_t cp = 0;
9774  auto dr = unicode::utf8_to_code_point(strb, stre);
9775  if (dr.error != unicode::error_code::ok) {
9777  }
9778  else {
9779  cp = dr.codepoint;
9780  }
9781  auto er = unicode::code_point_to_utf16(cp);
9782  return er.code_units[0];
9783  }
9784  };
9785 
9786  template <>
9787  struct getter<char32_t> {
9788  static char32_t get(lua_State* L, int index, record& tracking) {
9789  string_view utf8 = stack::get<string_view>(L, index, tracking);
9790  const char* strb = utf8.data();
9791  const char* stre = utf8.data() + utf8.size();
9792  char32_t cp = 0;
9793  auto dr = unicode::utf8_to_code_point(strb, stre);
9794  if (dr.error != unicode::error_code::ok) {
9796  }
9797  else {
9798  cp = dr.codepoint;
9799  }
9800  auto er = unicode::code_point_to_utf32(cp);
9801  return er.code_units[0];
9802  }
9803  };
9804 
9805  template <>
9806  struct getter<wchar_t> {
9807  static wchar_t get(lua_State* L, int index, record& tracking) {
9808  typedef std::conditional_t<sizeof(wchar_t) == 2, char16_t, char32_t> Ch;
9809  getter<Ch> g;
9810  (void)g;
9811  auto c = g.get(L, index, tracking);
9812  return static_cast<wchar_t>(c);
9813  }
9814  };
9815 
9816  template <>
9818  static meta_function get(lua_State* L, int index, record& tracking) {
9819  tracking.use(1);
9820  const char* name = getter<const char*>{}.get(L, index, tracking);
9821  const auto& mfnames = meta_function_names();
9822  for (std::size_t i = 0; i < mfnames.size(); ++i)
9823  if (mfnames[i] == name)
9824  return static_cast<meta_function>(i);
9825  return meta_function::construct;
9826  }
9827  };
9828 
9829  template <>
9830  struct getter<lua_nil_t> {
9831  static lua_nil_t get(lua_State*, int, record& tracking) {
9832  tracking.use(1);
9833  return lua_nil;
9834  }
9835  };
9836 
9837  template <>
9838  struct getter<std::nullptr_t> {
9839  static std::nullptr_t get(lua_State*, int, record& tracking) {
9840  tracking.use(1);
9841  return nullptr;
9842  }
9843  };
9844 
9845  template <>
9846  struct getter<nullopt_t> {
9847  static nullopt_t get(lua_State*, int, record& tracking) {
9848  tracking.use(1);
9849  return nullopt;
9850  }
9851  };
9852 
9853  template <>
9854  struct getter<this_state> {
9855  static this_state get(lua_State* L, int, record& tracking) {
9856  tracking.use(0);
9857  return this_state(L);
9858  }
9859  };
9860 
9861  template <>
9863  static this_main_state get(lua_State* L, int, record& tracking) {
9864  tracking.use(0);
9865  return this_main_state(main_thread(L, L));
9866  }
9867  };
9868 
9869  template <>
9870  struct getter<lua_CFunction> {
9871  static lua_CFunction get(lua_State* L, int index, record& tracking) {
9872  tracking.use(1);
9873  return lua_tocfunction(L, index);
9874  }
9875  };
9876 
9877  template <>
9878  struct getter<c_closure> {
9879  static c_closure get(lua_State* L, int index, record& tracking) {
9880  tracking.use(1);
9881  return c_closure(lua_tocfunction(L, index), -1);
9882  }
9883  };
9884 
9885  template <>
9886  struct getter<error> {
9887  static error get(lua_State* L, int index, record& tracking) {
9888  tracking.use(1);
9889  size_t sz = 0;
9890  const char* err = lua_tolstring(L, index, &sz);
9891  if (err == nullptr) {
9892  return error(detail::direct_error, "");
9893  }
9894  return error(detail::direct_error, std::string(err, sz));
9895  }
9896  };
9897 
9898  template <>
9899  struct getter<void*> {
9900  static void* get(lua_State* L, int index, record& tracking) {
9901  tracking.use(1);
9902  return lua_touserdata(L, index);
9903  }
9904  };
9905 
9906  template <>
9907  struct getter<const void*> {
9908  static const void* get(lua_State* L, int index, record& tracking) {
9909  tracking.use(1);
9910  return lua_touserdata(L, index);
9911  }
9912  };
9913 
9914  template <typename T>
9915  struct getter<detail::as_value_tag<T>> {
9916  static T* get_no_lua_nil(lua_State* L, int index, record& tracking) {
9917  void* memory = lua_touserdata(L, index);
9918 #if defined(SOL_ENABLE_INTEROP) && SOL_ENABLE_INTEROP
9920  (void)ug;
9921  auto ugr = ug.get(L, index, memory, tracking);
9922  if (ugr.first) {
9923  return ugr.second;
9924  }
9925 #endif // interop extensibility
9926  tracking.use(1);
9927  void* rawdata = detail::align_usertype_pointer(memory);
9928  void** pudata = static_cast<void**>(rawdata);
9929  void* udata = *pudata;
9930  return get_no_lua_nil_from(L, udata, index, tracking);
9931  }
9932 
9933  static T* get_no_lua_nil_from(lua_State* L, void* udata, int index, record&) {
9934  if (detail::has_derived<T>::value && luaL_getmetafield(L, index, &detail::base_class_cast_key()[0]) != 0) {
9935  void* basecastdata = lua_touserdata(L, -1);
9936  detail::inheritance_cast_function ic = reinterpret_cast<detail::inheritance_cast_function>(basecastdata);
9937  // use the casting function to properly adjust the pointer for the desired T
9938  udata = ic(udata, usertype_traits<T>::qualified_name());
9939  lua_pop(L, 1);
9940  }
9941  T* obj = static_cast<T*>(udata);
9942  return obj;
9943  }
9944 
9945  static T& get(lua_State* L, int index, record& tracking) {
9946  return *get_no_lua_nil(L, index, tracking);
9947  }
9948  };
9949 
9950  template <typename T>
9951  struct getter<detail::as_pointer_tag<T>> {
9952  static T* get(lua_State* L, int index, record& tracking) {
9953  type t = type_of(L, index);
9954  if (t == type::lua_nil) {
9955  tracking.use(1);
9956  return nullptr;
9957  }
9959  // Avoid VC++ warning
9960  (void)g;
9961  return g.get_no_lua_nil(L, index, tracking);
9962  }
9963  };
9964 
9965  template <typename T>
9966  struct getter<non_null<T*>> {
9967  static T* get(lua_State* L, int index, record& tracking) {
9969  // Avoid VC++ warning
9970  (void)g;
9971  return g.get_no_lua_nil(L, index, tracking);
9972  }
9973  };
9974 
9975  template <typename T>
9976  struct getter<T&> {
9977  static T& get(lua_State* L, int index, record& tracking) {
9979  // Avoid VC++ warning
9980  (void)g;
9981  return g.get(L, index, tracking);
9982  }
9983  };
9984 
9985  template <typename T>
9986  struct getter<std::reference_wrapper<T>> {
9987  static T& get(lua_State* L, int index, record& tracking) {
9988  getter<T&> g;
9989  // Avoid VC++ warning
9990  (void)g;
9991  return g.get(L, index, tracking);
9992  }
9993  };
9994 
9995  template <typename T>
9996  struct getter<T*> {
9997  static T* get(lua_State* L, int index, record& tracking) {
9999  // Avoid VC++ warning
10000  (void)g;
10001  return g.get(L, index, tracking);
10002  }
10003  };
10004 
10005  template <typename T>
10006  struct getter<T, std::enable_if_t<is_unique_usertype<T>::value>> {
10009 
10010  static Real& get(lua_State* L, int index, record& tracking) {
10011  tracking.use(1);
10012  void* memory = lua_touserdata(L, index);
10013  memory = detail::align_usertype_unique<Real>(memory);
10014  Real* mem = static_cast<Real*>(memory);
10015  return *mem;
10016  }
10017  };
10018 
10019  template <typename... Tn>
10020  struct getter<std::tuple<Tn...>> {
10021  typedef std::tuple<decltype(stack::get<Tn>(nullptr, 0))...> R;
10022 
10023  template <typename... Args>
10024  static R apply(std::index_sequence<>, lua_State*, int, record&, Args&&... args) {
10025  // Fuck you too, VC++
10026  return R{ std::forward<Args>(args)... };
10027  }
10028 
10029  template <std::size_t I, std::size_t... Ix, typename... Args>
10030  static R apply(std::index_sequence<I, Ix...>, lua_State* L, int index, record& tracking, Args&&... args) {
10031  // Fuck you too, VC++
10032  typedef std::tuple_element_t<I, std::tuple<Tn...>> T;
10033  return apply(std::index_sequence<Ix...>(), L, index, tracking, std::forward<Args>(args)..., stack::get<T>(L, index + tracking.used, tracking));
10034  }
10035 
10036  static R get(lua_State* L, int index, record& tracking) {
10037  return apply(std::make_index_sequence<sizeof...(Tn)>(), L, index, tracking);
10038  }
10039  };
10040 
10041  template <typename A, typename B>
10042  struct getter<std::pair<A, B>> {
10043  static decltype(auto) get(lua_State* L, int index, record& tracking) {
10044  return std::pair<decltype(stack::get<A>(L, index)), decltype(stack::get<B>(L, index))>{ stack::get<A>(L, index, tracking), stack::get<B>(L, index + tracking.used, tracking) };
10045  }
10046  };
10047 
10048 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
10049 
10050 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
10051  template <typename... Tn>
10052  struct getter<std::variant<Tn...>> {
10053  typedef std::variant<Tn...> V;
10054  typedef std::variant_size<V> V_size;
10055  typedef std::integral_constant<bool, V_size::value == 0> V_is_empty;
10056 
10057  static V get_empty(std::true_type, lua_State*, int, record&) {
10058  return V();
10059  }
10060 
10061  static V get_empty(std::false_type, lua_State* L, int index, record& tracking) {
10062  typedef std::variant_alternative_t<0, V> T;
10063  // This should never be reached...
10064  // please check your code and understand what you did to bring yourself here
10065  std::abort();
10066  return V(std::in_place_index<0>, stack::get<T>(L, index, tracking));
10067  }
10068 
10069  static V get_one(std::integral_constant<std::size_t, 0>, lua_State* L, int index, record& tracking) {
10070  return get_empty(V_is_empty(), L, index, tracking);
10071  }
10072 
10073  template <std::size_t I>
10074  static V get_one(std::integral_constant<std::size_t, I>, lua_State* L, int index, record& tracking) {
10075  typedef std::variant_alternative_t<I - 1, V> T;
10076  record temp_tracking = tracking;
10077  if (stack::check<T>(L, index, no_panic, temp_tracking)) {
10078  tracking = temp_tracking;
10079  return V(std::in_place_index<I - 1>, stack::get<T>(L, index));
10080  }
10081  return get_one(std::integral_constant<std::size_t, I - 1>(), L, index, tracking);
10082  }
10083 
10084  static V get(lua_State* L, int index, record& tracking) {
10085  return get_one(std::integral_constant<std::size_t, V_size::value>(), L, index, tracking);
10086  }
10087  };
10088 #endif // SOL_STD_VARIANT
10089 #endif // SOL_CXX17_FEATURES
10090 }
10091 } // namespace sol::stack
10092 
10093 // end of sol/stack_get_unqualified.hpp
10094 
10095 // beginning of sol/stack_get_qualified.hpp
10096 
10097 namespace sol {
10098 namespace stack {
10099 
10100 #if 0 // need static reflection / DERIVED_CLASS macros...
10101  template <typename X>
10102  struct qualified_getter<X, std::enable_if_t<
10103  !std::is_reference<X>::value && is_unique_usertype<meta::unqualified_t<X>>::value
10104  >> {
10105  typedef typename unique_usertype_traits<meta::unqualified_t<X>>::type P;
10106  typedef typename unique_usertype_traits<meta::unqualified_t<X>>::actual_type Real;
10107 
10108  static Real& get(lua_State* L, int index, record& tracking) {
10109  tracking.use(1);
10110  void* memory = lua_touserdata(L, index);
10111  void* del = detail::align_usertype_unique_destructor(memory);
10112  memory = detail::align_usertype_unique<Real>(memory);
10113  Real* mem = static_cast<Real*>(memory);
10114  return *mem;
10115  }
10116  };
10117 #endif // need static reflection
10118 
10119  template <typename T>
10120  struct qualified_getter<T, std::enable_if_t<
10121  !std::is_reference<T>::value
10122  && is_container<meta::unqualified_t<T>>::value
10123  && std::is_default_constructible<meta::unqualified_t<T>>::value
10124  && !is_lua_primitive<T>::value
10125  && !is_transparent_argument<T>::value
10126  >> {
10127  static T get(lua_State* L, int index, record& tracking) {
10128  if (type_of(L, index) == type::userdata) {
10129  return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
10130  }
10131  else {
10132  return stack_detail::unchecked_unqualified_get<sol::nested<T>>(L, index, tracking);
10133  }
10134  }
10135  };
10136 }
10137 } // namespace sol::stack
10138 
10139 // end of sol/stack_get_qualified.hpp
10140 
10141 // end of sol/stack_get.hpp
10142 
10143 // beginning of sol/stack_check_get.hpp
10144 
10145 // beginning of sol/stack_check_get_unqualified.hpp
10146 
10147 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
10148 #endif // C++17
10149 
10150 namespace sol {
10151 namespace stack {
10152  template <typename T, typename>
10153  struct check_getter {
10154  typedef decltype(stack_detail::unchecked_unqualified_get<T>(nullptr, 0, std::declval<record&>())) R;
10155 
10156  template <typename Handler>
10157  static optional<R> get(lua_State* L, int index, Handler&& handler, record& tracking) {
10158  if (!unqualified_check<T>(L, index, std::forward<Handler>(handler))) {
10159  tracking.use(static_cast<int>(!lua_isnone(L, index)));
10160  return nullopt;
10161  }
10162  return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
10163  }
10164  };
10165 
10166  template <typename T>
10167  struct check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
10168  template <typename Handler>
10169  static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
10170  // actually check if it's none here, otherwise
10171  // we'll have a none object inside an optional!
10172  bool success = lua_isnoneornil(L, index) == 0 && stack::check<T>(L, index, no_panic);
10173  if (!success) {
10174  // expected type, actual type
10175  tracking.use(static_cast<int>(success));
10176  handler(L, index, type::poly, type_of(L, index), "");
10177  return nullopt;
10178  }
10179  return stack_detail::unchecked_get<T>(L, index, tracking);
10180  }
10181  };
10182 
10183  template <typename T>
10184  struct check_getter<T, std::enable_if_t<std::is_integral<T>::value && lua_type_of<T>::value == type::number>> {
10185  template <typename Handler>
10186  static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
10187 #if SOL_LUA_VERSION >= 503
10188  if (lua_isinteger(L, index) != 0) {
10189  tracking.use(1);
10190  return static_cast<T>(lua_tointeger(L, index));
10191  }
10192 #endif
10193  int isnum = 0;
10194  const lua_Number value = lua_tonumberx(L, index, &isnum);
10195  if (isnum != 0) {
10196 #if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
10197  const auto integer_value = llround(value);
10198  if (static_cast<lua_Number>(integer_value) == value) {
10199  tracking.use(1);
10200  return static_cast<T>(integer_value);
10201  }
10202 #else
10203  tracking.use(1);
10204  return static_cast<T>(value);
10205 #endif
10206  }
10207  const type t = type_of(L, index);
10208  tracking.use(static_cast<int>(t != type::none));
10209  handler(L, index, type::number, t, "not an integer");
10210  return nullopt;
10211  }
10212  };
10213 
10214  template <typename T>
10215  struct check_getter<T, std::enable_if_t<std::is_enum<T>::value && !meta::any_same<T, meta_function, type>::value>> {
10216  template <typename Handler>
10217  static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
10218  int isnum = 0;
10219  lua_Integer value = lua_tointegerx(L, index, &isnum);
10220  if (isnum == 0) {
10221  type t = type_of(L, index);
10222  tracking.use(static_cast<int>(t != type::none));
10223  handler(L, index, type::number, t, "not a valid enumeration value");
10224  return nullopt;
10225  }
10226  tracking.use(1);
10227  return static_cast<T>(value);
10228  }
10229  };
10230 
10231  template <typename T>
10232  struct check_getter<T, std::enable_if_t<std::is_floating_point<T>::value>> {
10233  template <typename Handler>
10234  static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
10235  int isnum = 0;
10236  lua_Number value = lua_tonumberx(L, index, &isnum);
10237  if (isnum == 0) {
10238  type t = type_of(L, index);
10239  tracking.use(static_cast<int>(t != type::none));
10240  handler(L, index, type::number, t, "not a valid floating point number");
10241  return nullopt;
10242  }
10243  tracking.use(1);
10244  return static_cast<T>(value);
10245  }
10246  };
10247 
10248  template <typename T>
10249  struct getter<optional<T>> {
10250  static decltype(auto) get(lua_State* L, int index, record& tracking) {
10251  return check_get<T>(L, index, no_panic, tracking);
10252  }
10253  };
10254 
10255 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
10256  template <typename T>
10257  struct getter<std::optional<T>> {
10258  static std::optional<T> get(lua_State* L, int index, record& tracking) {
10259  if (!unqualified_check<T>(L, index, no_panic)) {
10260  tracking.use(static_cast<int>(!lua_isnone(L, index)));
10261  return std::nullopt;
10262  }
10263  return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
10264  }
10265  };
10266 
10267 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
10268  template <typename... Tn>
10269  struct check_getter<std::variant<Tn...>> {
10270  typedef std::variant<Tn...> V;
10271  typedef std::variant_size<V> V_size;
10272  typedef std::integral_constant<bool, V_size::value == 0> V_is_empty;
10273 
10274  template <typename Handler>
10275  static optional<V> get_empty(std::true_type, lua_State*, int, Handler&&, record&) {
10276  return nullopt;
10277  }
10278 
10279  template <typename Handler>
10280  static optional<V> get_empty(std::false_type, lua_State* L, int index, Handler&& handler, record&) {
10281  // This should never be reached...
10282  // please check your code and understand what you did to bring yourself here
10283  // maybe file a bug report, or 5
10284  handler(L, index, type::poly, type_of(L, index), "this variant code should never be reached: if it has, you have done something so terribly wrong");
10285  return nullopt;
10286  }
10287 
10288  template <typename Handler>
10289  static optional<V> get_one(std::integral_constant<std::size_t, 0>, lua_State* L, int index, Handler&& handler, record& tracking) {
10290  return get_empty(V_is_empty(), L, index, std::forward<Handler>(handler), tracking);
10291  }
10292 
10293  template <std::size_t I, typename Handler>
10294  static optional<V> get_one(std::integral_constant<std::size_t, I>, lua_State* L, int index, Handler&& handler, record& tracking) {
10295  typedef std::variant_alternative_t<I - 1, V> T;
10296  if (stack::check<T>(L, index, no_panic, tracking)) {
10297  return V(std::in_place_index<I - 1>, stack::get<T>(L, index));
10298  }
10299  return get_one(std::integral_constant<std::size_t, I - 1>(), L, index, std::forward<Handler>(handler), tracking);
10300  }
10301 
10302  template <typename Handler>
10303  static optional<V> get(lua_State* L, int index, Handler&& handler, record& tracking) {
10304  return get_one(std::integral_constant<std::size_t, V_size::value>(), L, index, std::forward<Handler>(handler), tracking);
10305  }
10306  };
10307 #endif // SOL_STD_VARIANT
10308 #endif // SOL_CXX17_FEATURES
10309 }
10310 } // namespace sol::stack
10311 
10312 // end of sol/stack_check_get_unqualified.hpp
10313 
10314 // beginning of sol/stack_check_get_qualified.hpp
10315 
10316 namespace sol {
10317 namespace stack {
10318  template <typename T, typename C>
10319  struct qualified_check_getter : check_getter<meta::unqualified_t<T>, C> {};
10320 }
10321 } // namespace sol::stack
10322 
10323 // end of sol/stack_check_get_qualified.hpp
10324 
10325 // end of sol/stack_check_get.hpp
10326 
10327 // beginning of sol/stack_push.hpp
10328 
10329 #include <limits>
10330 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
10331 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
10332 #endif // Can use variant
10333 #endif // C++17
10334 
10335 namespace sol {
10336 namespace stack {
10337  inline int push_environment_of(lua_State* L, int index = -1) {
10338 #if SOL_LUA_VERSION < 502
10339  // Use lua_getfenv
10340  lua_getfenv(L, index);
10341  return 1;
10342 #else
10343  // Use upvalues as explained in Lua 5.2 and beyond's manual
10344  if (lua_getupvalue(L, index, 1) == nullptr) {
10345  push(L, lua_nil);
10346  return 1;
10347  }
10348 #endif
10349  return 1;
10350  }
10351 
10352  template <typename T>
10353  int push_environment_of(const T& target) {
10354  target.push();
10355  return push_environment_of(target.lua_state(), -1) + 1;
10356  }
10357 
10358  template <typename T>
10359  struct pusher<detail::as_value_tag<T>> {
10360  template <typename F, typename... Args>
10361  static int push_fx(lua_State* L, F&& f, Args&&... args) {
10362  // Basically, we store all user-data like this:
10363  // If it's a movable/copyable value (no std::ref(x)), then we store the pointer to the new
10364  // data in the first sizeof(T*) bytes, and then however many bytes it takes to
10365  // do the actual object. Things that are std::ref or plain T* are stored as
10366  // just the sizeof(T*), and nothing else.
10367  T* obj = detail::usertype_allocate<T>(L);
10368  std::allocator<T> alloc{};
10369  std::allocator_traits<std::allocator<T>>::construct(alloc, obj, std::forward<Args>(args)...);
10370  f();
10371  return 1;
10372  }
10373 
10374  template <typename K, typename... Args>
10375  static int push_keyed(lua_State* L, K&& k, Args&&... args) {
10377  return push_fx(L, fx, std::forward<Args>(args)...);
10378  }
10379 
10380  template <typename... Args>
10381  static int push(lua_State* L, Args&&... args) {
10382  return push_keyed(L, usertype_traits<T>::metatable(), std::forward<Args>(args)...);
10383  }
10384  };
10385 
10386  template <typename T>
10387  struct pusher<detail::as_pointer_tag<T>> {
10389 
10390  template <typename F>
10391  static int push_fx(lua_State* L, F&& f, T* obj) {
10392  if (obj == nullptr)
10393  return stack::push(L, lua_nil);
10394  T** pref = detail::usertype_allocate_pointer<T>(L);
10395  *pref = obj;
10396  f();
10397  return 1;
10398  }
10399 
10400  template <typename K>
10401  static int push_keyed(lua_State* L, K&& k, T* obj) {
10403  return push_fx(L, fx, obj);
10404  }
10405 
10406  static int push(lua_State* L, T* obj) {
10407  return push_keyed(L, usertype_traits<U*>::metatable(), obj);
10408  }
10409  };
10410 
10411  template <>
10412  struct pusher<detail::as_reference_tag> {
10413  template <typename T>
10414  static int push(lua_State* L, T&& obj) {
10415  return stack::push(L, detail::ptr(obj));
10416  }
10417  };
10418 
10419  template <typename T, typename>
10420  struct pusher {
10421  template <typename... Args>
10422  static int push(lua_State* L, Args&&... args) {
10423  return pusher<detail::as_value_tag<T>>{}.push(L, std::forward<Args>(args)...);
10424  }
10425  };
10426 
10427  template <typename T>
10429  template <typename... Args>
10430  static int push(lua_State* L, Args&&... args) {
10431  return pusher<detail::as_pointer_tag<T>>{}.push(L, std::forward<Args>(args)...);
10432  }
10433  };
10434 
10435  template <typename T>
10436  struct pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
10439 
10440  template <typename Arg, meta::enable<std::is_base_of<Real, meta::unqualified_t<Arg>>> = meta::enabler>
10441  static int push(lua_State* L, Arg&& arg) {
10443  return stack::push(L, lua_nil);
10444  }
10445  return push_deep(L, std::forward<Arg>(arg));
10446  }
10447 
10448  template <typename Arg0, typename Arg1, typename... Args>
10449  static int push(lua_State* L, Arg0&& arg0, Arg0&& arg1, Args&&... args) {
10450  return push_deep(L, std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...);
10451  }
10452 
10453  template <typename... Args>
10454  static int push_deep(lua_State* L, Args&&... args) {
10455  P** pref = nullptr;
10456  detail::unique_destructor* fx = nullptr;
10457  detail::unique_tag* id = nullptr;
10458  Real* mem = detail::usertype_unique_allocate<P, Real>(L, pref, fx, id);
10459  *fx = detail::usertype_unique_alloc_destroy<P, Real>;
10460 #if 0
10462 #else
10464 #endif
10465  detail::default_construct::construct(mem, std::forward<Args>(args)...);
10466  *pref = unique_usertype_traits<T>::get(*mem);
10467  if (luaL_newmetatable(L, &usertype_traits<detail::unique_usertype<std::remove_cv_t<P>>>::metatable()[0]) == 1) {
10468  luaL_Reg l[32]{};
10469  int index = 0;
10470  auto prop_fx = [](meta_function) { return true; };
10471  usertype_detail::insert_default_registrations<P>(l, index, prop_fx);
10472  usertype_detail::make_destructor<T>(l, index);
10473  luaL_setfuncs(L, l, 0);
10474  }
10475  lua_setmetatable(L, -2);
10476  return 1;
10477  }
10478  };
10479 
10480  template <typename T>
10481  struct pusher<std::reference_wrapper<T>> {
10482  static int push(lua_State* L, const std::reference_wrapper<T>& t) {
10483  return stack::push(L, std::addressof(detail::deref(t.get())));
10484  }
10485  };
10486 
10487  template <typename T>
10488  struct pusher<T, std::enable_if_t<std::is_floating_point<T>::value>> {
10489  static int push(lua_State* L, const T& value) {
10490  lua_pushnumber(L, value);
10491  return 1;
10492  }
10493  };
10494 
10495  template <typename T>
10496  struct pusher<T, std::enable_if_t<std::is_integral<T>::value>> {
10497  static int push(lua_State* L, const T& value) {
10498 #if SOL_LUA_VERSION >= 503
10499  static auto integer_value_fits = [](T const& value) {
10500  if (sizeof(T) < sizeof(lua_Integer) || (std::is_signed<T>::value && sizeof(T) == sizeof(lua_Integer))) {
10501  return true;
10502  }
10503  auto u_min = static_cast<std::intmax_t>((std::numeric_limits<lua_Integer>::min)());
10504  auto u_max = static_cast<std::uintmax_t>((std::numeric_limits<lua_Integer>::max)());
10505  auto t_min = static_cast<std::intmax_t>((std::numeric_limits<T>::min)());
10506  auto t_max = static_cast<std::uintmax_t>((std::numeric_limits<T>::max)());
10507  return (u_min <= t_min || value >= static_cast<T>(u_min)) && (u_max >= t_max || value <= static_cast<T>(u_max));
10508  };
10509  if (integer_value_fits(value)) {
10510  lua_pushinteger(L, static_cast<lua_Integer>(value));
10511  return 1;
10512  }
10513 #endif // Lua 5.3 and above
10514 #if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
10515  if (static_cast<T>(llround(static_cast<lua_Number>(value))) != value) {
10516 #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
10517  // Is this really worth it?
10518  assert(false && "integer value will be misrepresented in lua");
10519  lua_pushnumber(L, static_cast<lua_Number>(value));
10520  return 1;
10521 #else
10522  throw error(detail::direct_error, "integer value will be misrepresented in lua");
10523 #endif // No Exceptions
10524  }
10525 #endif // Safe Numerics and Number Precision Check
10526  lua_pushnumber(L, static_cast<lua_Number>(value));
10527  return 1;
10528  }
10529  };
10530 
10531  template <typename T>
10532  struct pusher<T, std::enable_if_t<std::is_enum<T>::value>> {
10533  static int push(lua_State* L, const T& value) {
10534  if (std::is_same<char, std::underlying_type_t<T>>::value) {
10535  return stack::push(L, static_cast<int>(value));
10536  }
10537  return stack::push(L, static_cast<std::underlying_type_t<T>>(value));
10538  }
10539  };
10540 
10541  template <typename T>
10542  struct pusher<detail::as_table_tag<T>> {
10543  static int push(lua_State* L, const T& tablecont) {
10545  return push(has_kvp(), std::false_type(), L, tablecont);
10546  }
10547 
10548  static int push(std::true_type, lua_State* L, const T& tablecont) {
10550  return push(has_kvp(), std::true_type(), L, tablecont);
10551  }
10552 
10553  static int push(std::false_type, lua_State* L, const T& tablecont) {
10555  return push(has_kvp(), std::false_type(), L, tablecont);
10556  }
10557 
10558  template <bool is_nested>
10559  static int push(std::true_type, std::integral_constant<bool, is_nested>, lua_State* L, const T& tablecont) {
10560  auto& cont = detail::deref(detail::unwrap(tablecont));
10561  lua_createtable(L, static_cast<int>(cont.size()), 0);
10562  int tableindex = lua_gettop(L);
10563  for (const auto& pair : cont) {
10564  if (is_nested) {
10565  set_field(L, pair.first, as_nested_ref(pair.second), tableindex);
10566  }
10567  else {
10568  set_field(L, pair.first, pair.second, tableindex);
10569  }
10570  }
10571  return 1;
10572  }
10573 
10574  template <bool is_nested>
10575  static int push(std::false_type, std::integral_constant<bool, is_nested>, lua_State* L, const T& tablecont) {
10576  auto& cont = detail::deref(detail::unwrap(tablecont));
10577  lua_createtable(L, stack_detail::get_size_hint(cont), 0);
10578  int tableindex = lua_gettop(L);
10579  std::size_t index = 1;
10580  for (const auto& i : cont) {
10581 #if SOL_LUA_VERSION >= 503
10582  int p = is_nested ? stack::push(L, as_nested_ref(i)) : stack::push(L, i);
10583  for (int pi = 0; pi < p; ++pi) {
10584  lua_seti(L, tableindex, static_cast<lua_Integer>(index++));
10585  }
10586 #else
10587  lua_pushinteger(L, static_cast<lua_Integer>(index));
10588  int p = is_nested ? stack::push(L, as_nested_ref(i)) : stack::push(L, i);
10589  if (p == 1) {
10590  ++index;
10591  lua_settable(L, tableindex);
10592  }
10593  else {
10594  int firstindex = tableindex + 1 + 1;
10595  for (int pi = 0; pi < p; ++pi) {
10596  stack::push(L, index);
10597  lua_pushvalue(L, firstindex);
10598  lua_settable(L, tableindex);
10599  ++index;
10600  ++firstindex;
10601  }
10602  lua_pop(L, 1 + p);
10603  }
10604 #endif // Lua Version 5.3 and others
10605  }
10606  // TODO: figure out a better way to do this...?
10607  //set_field(L, -1, cont.size());
10608  return 1;
10609  }
10610  };
10611 
10612  template <typename T>
10613  struct pusher<as_table_t<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
10614  static int push(lua_State* L, const T& tablecont) {
10615  return stack::push<detail::as_table_tag<T>>(L, tablecont);
10616  }
10617  };
10618 
10619  template <typename T>
10620  struct pusher<as_table_t<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
10621  static int push(lua_State* L, const T& v) {
10622  return stack::push(L, v);
10623  }
10624  };
10625 
10626  template <typename T>
10627  struct pusher<nested<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
10628  static int push(lua_State* L, const T& tablecont) {
10630  // silence annoying VC++ warning
10631  (void)p;
10632  return p.push(std::true_type(), L, tablecont);
10633  }
10634  };
10635 
10636  template <typename T>
10637  struct pusher<nested<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
10638  static int push(lua_State* L, const T& tablecont) {
10640  // silence annoying VC++ warning
10641  (void)p;
10642  return p.push(L, tablecont);
10643  }
10644  };
10645 
10646  template <typename T>
10647  struct pusher<std::initializer_list<T>> {
10648  static int push(lua_State* L, const std::initializer_list<T>& il) {
10650  // silence annoying VC++ warning
10651  (void)p;
10652  return p.push(L, il);
10653  }
10654  };
10655 
10656  template <typename T>
10657  struct pusher<T, std::enable_if_t<is_lua_reference<T>::value>> {
10658  static int push(lua_State* L, const T& ref) {
10659  return ref.push(L);
10660  }
10661 
10662  static int push(lua_State* L, T&& ref) {
10663  return ref.push(L);
10664  }
10665  };
10666 
10667  template <>
10668  struct pusher<bool> {
10669  static int push(lua_State* L, bool b) {
10670  lua_pushboolean(L, b);
10671  return 1;
10672  }
10673  };
10674 
10675  template <>
10676  struct pusher<lua_nil_t> {
10677  static int push(lua_State* L, lua_nil_t) {
10678  lua_pushnil(L);
10679  return 1;
10680  }
10681  };
10682 
10683  template <>
10685  static int push(lua_State*, stack_count st) {
10686  return st.count;
10687  }
10688  };
10689 
10690  template <>
10692  static int push(lua_State* L, metatable_t) {
10693  lua_pushlstring(L, "__mt", 4);
10694  return 1;
10695  }
10696  };
10697 
10698  template <>
10699  struct pusher<std::remove_pointer_t<lua_CFunction>> {
10700  static int push(lua_State* L, lua_CFunction func, int n = 0) {
10701  lua_pushcclosure(L, func, n);
10702  return 1;
10703  }
10704  };
10705 
10706  template <>
10707  struct pusher<lua_CFunction> {
10708  static int push(lua_State* L, lua_CFunction func, int n = 0) {
10709  lua_pushcclosure(L, func, n);
10710  return 1;
10711  }
10712  };
10713 
10714 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
10715  template <>
10716  struct pusher<std::remove_pointer_t<detail::lua_CFunction_noexcept>> {
10717  static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) {
10718  lua_pushcclosure(L, func, n);
10719  return 1;
10720  }
10721  };
10722 
10723  template <>
10724  struct pusher<detail::lua_CFunction_noexcept> {
10725  static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) {
10726  lua_pushcclosure(L, func, n);
10727  return 1;
10728  }
10729  };
10730 #endif // noexcept function type
10731 
10732  template <>
10733  struct pusher<c_closure> {
10734  static int push(lua_State* L, c_closure cc) {
10735  lua_pushcclosure(L, cc.c_function, cc.upvalues);
10736  return 1;
10737  }
10738  };
10739 
10740  template <typename Arg, typename... Args>
10741  struct pusher<closure<Arg, Args...>> {
10742  template <std::size_t... I, typename T>
10743  static int push(std::index_sequence<I...>, lua_State* L, T&& c) {
10744  int pushcount = multi_push(L, detail::forward_get<I>(c.upvalues)...);
10745  return stack::push(L, c_closure(c.c_function, pushcount));
10746  }
10747 
10748  template <typename T>
10749  static int push(lua_State* L, T&& c) {
10750  return push(std::make_index_sequence<1 + sizeof...(Args)>(), L, std::forward<T>(c));
10751  }
10752  };
10753 
10754  template <>
10755  struct pusher<void*> {
10756  static int push(lua_State* L, void* userdata) {
10757  lua_pushlightuserdata(L, userdata);
10758  return 1;
10759  }
10760  };
10761 
10762  template <>
10763  struct pusher<const void*> {
10764  static int push(lua_State* L, const void* userdata) {
10765  lua_pushlightuserdata(L, const_cast<void*>(userdata));
10766  return 1;
10767  }
10768  };
10769 
10770  template <>
10772  static int push(lua_State* L, lightuserdata_value userdata) {
10773  lua_pushlightuserdata(L, userdata);
10774  return 1;
10775  }
10776  };
10777 
10778  template <typename T>
10779  struct pusher<light<T>> {
10780  static int push(lua_State* L, light<T> l) {
10781  lua_pushlightuserdata(L, static_cast<void*>(l.value));
10782  return 1;
10783  }
10784  };
10785 
10786  template <typename T>
10787  struct pusher<user<T>> {
10788  template <bool with_meta = true, typename Key, typename... Args>
10789  static int push_with(lua_State* L, Key&& name, Args&&... args) {
10790  // A dumb pusher
10791  T* data = detail::user_allocate<T>(L);
10792  std::allocator<T> alloc{};
10793  std::allocator_traits<std::allocator<T>>::construct(alloc, data, std::forward<Args>(args)...);
10794  if (with_meta) {
10795  // Make sure we have a plain GC set for this data
10796  if (luaL_newmetatable(L, name) != 0) {
10797  lua_CFunction cdel = detail::user_alloc_destruct<T>;
10798  lua_pushcclosure(L, cdel, 0);
10799  lua_setfield(L, -2, "__gc");
10800  }
10801  lua_setmetatable(L, -2);
10802  }
10803  return 1;
10804  }
10805 
10807  static int push(lua_State* L, Arg&& arg, Args&&... args) {
10808  const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable()[0];
10809  return push_with(L, name, std::forward<Arg>(arg), std::forward<Args>(args)...);
10810  }
10811 
10812  template <typename... Args>
10813  static int push(lua_State* L, no_metatable_t, Args&&... args) {
10814  const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable()[0];
10815  return push_with<false>(L, name, std::forward<Args>(args)...);
10816  }
10817 
10818  template <typename Key, typename... Args>
10819  static int push(lua_State* L, metatable_t, Key&& key, Args&&... args) {
10820  const auto name = &key[0];
10821  return push_with<true>(L, name, std::forward<Args>(args)...);
10822  }
10823 
10824  static int push(lua_State* L, const user<T>& u) {
10825  const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable()[0];
10826  return push_with(L, name, u.value);
10827  }
10828 
10829  static int push(lua_State* L, user<T>&& u) {
10830  const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable()[0];
10831  return push_with(L, name, std::move(u.value));
10832  }
10833 
10834  static int push(lua_State* L, no_metatable_t, const user<T>& u) {
10835  const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable()[0];
10836  return push_with<false>(L, name, u.value);
10837  }
10838 
10839  static int push(lua_State* L, no_metatable_t, user<T>&& u) {
10840  const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable()[0];
10841  return push_with<false>(L, name, std::move(u.value));
10842  }
10843  };
10844 
10845  template <>
10847  static int push(lua_State* L, userdata_value data) {
10848  void** ud = detail::usertype_allocate_pointer<void>(L);
10849  *ud = data.value;
10850  return 1;
10851  }
10852  };
10853 
10854  template <>
10855  struct pusher<const char*> {
10856  static int push_sized(lua_State* L, const char* str, std::size_t len) {
10857  lua_pushlstring(L, str, len);
10858  return 1;
10859  }
10860 
10861  static int push(lua_State* L, const char* str) {
10862  if (str == nullptr)
10863  return stack::push(L, lua_nil);
10864  return push_sized(L, str, std::char_traits<char>::length(str));
10865  }
10866 
10867  static int push(lua_State* L, const char* strb, const char* stre) {
10868  return push_sized(L, strb, stre - strb);
10869  }
10870 
10871  static int push(lua_State* L, const char* str, std::size_t len) {
10872  return push_sized(L, str, len);
10873  }
10874  };
10875 
10876  template <>
10877  struct pusher<char*> {
10878  static int push_sized(lua_State* L, const char* str, std::size_t len) {
10879  pusher<const char*> p{};
10880  (void)p;
10881  return p.push_sized(L, str, len);
10882  }
10883 
10884  static int push(lua_State* L, const char* str) {
10885  pusher<const char*> p{};
10886  (void)p;
10887  return p.push(L, str);
10888  }
10889 
10890  static int push(lua_State* L, const char* strb, const char* stre) {
10891  pusher<const char*> p{};
10892  (void)p;
10893  return p.push(L, strb, stre);
10894  }
10895 
10896  static int push(lua_State* L, const char* str, std::size_t len) {
10897  pusher<const char*> p{};
10898  (void)p;
10899  return p.push(L, str, len);
10900  }
10901  };
10902 
10903  template <size_t N>
10904  struct pusher<char[N]> {
10905  static int push(lua_State* L, const char (&str)[N]) {
10906  lua_pushlstring(L, str, std::char_traits<char>::length(str));
10907  return 1;
10908  }
10909 
10910  static int push(lua_State* L, const char (&str)[N], std::size_t sz) {
10911  lua_pushlstring(L, str, sz);
10912  return 1;
10913  }
10914  };
10915 
10916  template <>
10917  struct pusher<char> {
10918  static int push(lua_State* L, char c) {
10919  const char str[2] = { c, '\0' };
10920  return stack::push(L, str, 1);
10921  }
10922  };
10923 
10924  template <typename Traits, typename Al>
10925  struct pusher<std::basic_string<char, Traits, Al>> {
10926  static int push(lua_State* L, const std::basic_string<char, Traits, Al>& str) {
10927  lua_pushlstring(L, str.c_str(), str.size());
10928  return 1;
10929  }
10930 
10931  static int push(lua_State* L, const std::basic_string<char, Traits, Al>& str, std::size_t sz) {
10932  lua_pushlstring(L, str.c_str(), sz);
10933  return 1;
10934  }
10935  };
10936 
10937  template <typename Ch, typename Traits>
10938  struct pusher<basic_string_view<Ch, Traits>> {
10939  static int push(lua_State* L, const basic_string_view<Ch, Traits>& sv) {
10940  return stack::push(L, sv.data(), sv.length());
10941  }
10942 
10943  static int push(lua_State* L, const basic_string_view<Ch, Traits>& sv, std::size_t n) {
10944  return stack::push(L, sv.data(), n);
10945  }
10946  };
10947 
10948  template <>
10950  static int push(lua_State* L, meta_function m) {
10951  const std::string& str = to_string(m);
10952  lua_pushlstring(L, str.c_str(), str.size());
10953  return 1;
10954  }
10955  };
10956 
10957  template <>
10959  static int push(lua_State* L, absolute_index ai) {
10960  lua_pushvalue(L, ai);
10961  return 1;
10962  }
10963  };
10964 
10965  template <>
10966  struct pusher<raw_index> {
10967  static int push(lua_State* L, raw_index ri) {
10968  lua_pushvalue(L, ri);
10969  return 1;
10970  }
10971  };
10972 
10973  template <>
10974  struct pusher<ref_index> {
10975  static int push(lua_State* L, ref_index ri) {
10976  lua_rawgeti(L, LUA_REGISTRYINDEX, ri);
10977  return 1;
10978  }
10979  };
10980 
10981  template <>
10982  struct pusher<const wchar_t*> {
10983  static int push(lua_State* L, const wchar_t* wstr) {
10984  return push(L, wstr, std::char_traits<wchar_t>::length(wstr));
10985  }
10986 
10987  static int push(lua_State* L, const wchar_t* wstr, std::size_t sz) {
10988  return push(L, wstr, wstr + sz);
10989  }
10990 
10991  static int push(lua_State* L, const wchar_t* strb, const wchar_t* stre) {
10992  if (sizeof(wchar_t) == 2) {
10993  const char16_t* sb = reinterpret_cast<const char16_t*>(strb);
10994  const char16_t* se = reinterpret_cast<const char16_t*>(stre);
10995  return stack::push(L, sb, se);
10996  }
10997  const char32_t* sb = reinterpret_cast<const char32_t*>(strb);
10998  const char32_t* se = reinterpret_cast<const char32_t*>(stre);
10999  return stack::push(L, sb, se);
11000  }
11001  };
11002 
11003  template <>
11004  struct pusher<wchar_t*> {
11005  static int push(lua_State* L, const wchar_t* str) {
11007  (void)p;
11008  return p.push(L, str);
11009  }
11010 
11011  static int push(lua_State* L, const wchar_t* strb, const wchar_t* stre) {
11013  (void)p;
11014  return p.push(L, strb, stre);
11015  }
11016 
11017  static int push(lua_State* L, const wchar_t* str, std::size_t len) {
11019  (void)p;
11020  return p.push(L, str, len);
11021  }
11022  };
11023 
11024  template <>
11025  struct pusher<const char16_t*> {
11026  static int convert_into(lua_State* L, char* start, std::size_t, const char16_t* strb, const char16_t* stre) {
11027  char* target = start;
11028  char32_t cp = 0;
11029  for (const char16_t* strtarget = strb; strtarget < stre;) {
11030  auto dr = unicode::utf16_to_code_point(strtarget, stre);
11031  if (dr.error != unicode::error_code::ok) {
11033  }
11034  else {
11035  cp = dr.codepoint;
11036  }
11037  auto er = unicode::code_point_to_utf8(cp);
11038  const char* utf8data = er.code_units.data();
11039  std::memcpy(target, utf8data, er.code_units_size);
11040  target += er.code_units_size;
11041  strtarget = dr.next;
11042  }
11043 
11044  return stack::push(L, start, target);
11045  }
11046 
11047  static int push(lua_State* L, const char16_t* u16str) {
11048  return push(L, u16str, std::char_traits<char16_t>::length(u16str));
11049  }
11050 
11051  static int push(lua_State* L, const char16_t* u16str, std::size_t sz) {
11052  return push(L, u16str, u16str + sz);
11053  }
11054 
11055  static int push(lua_State* L, const char16_t* strb, const char16_t* stre) {
11056  // TODO: use new unicode methods
11057  // TODO: use new unicode methods
11059  // if our max string space is small enough, use SBO
11060  // right off the bat
11061  std::size_t max_possible_code_units = (stre - strb) * 4;
11062  if (max_possible_code_units <= SOL_STACK_STRING_OPTIMIZATION_SIZE) {
11063  return convert_into(L, sbo, max_possible_code_units, strb, stre);
11064  }
11065  // otherwise, we must manually count/check size
11066  std::size_t needed_size = 0;
11067  for (const char16_t* strtarget = strb; strtarget < stre;) {
11068  auto dr = unicode::utf16_to_code_point(strtarget, stre);
11069  auto er = unicode::code_point_to_utf8(dr.codepoint);
11070  needed_size += er.code_units_size;
11071  strtarget = dr.next;
11072  }
11073  if (needed_size < SOL_STACK_STRING_OPTIMIZATION_SIZE) {
11074  return convert_into(L, sbo, needed_size, strb, stre);
11075  }
11076  std::string u8str("", 0);
11077  u8str.resize(needed_size);
11078  char* target = &u8str[0];
11079  return convert_into(L, target, needed_size, strb, stre);
11080  }
11081  };
11082 
11083  template <>
11084  struct pusher<char16_t*> {
11085  static int push(lua_State* L, const char16_t* str) {
11087  (void)p;
11088  return p.push(L, str);
11089  }
11090 
11091  static int push(lua_State* L, const char16_t* strb, const char16_t* stre) {
11093  (void)p;
11094  return p.push(L, strb, stre);
11095  }
11096 
11097  static int push(lua_State* L, const char16_t* str, std::size_t len) {
11099  (void)p;
11100  return p.push(L, str, len);
11101  }
11102  };
11103 
11104  template <>
11105  struct pusher<const char32_t*> {
11106  static int convert_into(lua_State* L, char* start, std::size_t, const char32_t* strb, const char32_t* stre) {
11107  char* target = start;
11108  char32_t cp = 0;
11109  for (const char32_t* strtarget = strb; strtarget < stre;) {
11110  auto dr = unicode::utf32_to_code_point(strtarget, stre);
11111  if (dr.error != unicode::error_code::ok) {
11113  }
11114  else {
11115  cp = dr.codepoint;
11116  }
11117  auto er = unicode::code_point_to_utf8(cp);
11118  const char* data = er.code_units.data();
11119  std::memcpy(target, data, er.code_units_size);
11120  target += er.code_units_size;
11121  strtarget = dr.next;
11122  }
11123  return stack::push(L, start, target);
11124  }
11125 
11126  static int push(lua_State* L, const char32_t* u32str) {
11127  return push(L, u32str, u32str + std::char_traits<char32_t>::length(u32str));
11128  }
11129 
11130  static int push(lua_State* L, const char32_t* u32str, std::size_t sz) {
11131  return push(L, u32str, u32str + sz);
11132  }
11133 
11134  static int push(lua_State* L, const char32_t* strb, const char32_t* stre) {
11135  // TODO: use new unicode methods
11137  // if our max string space is small enough, use SBO
11138  // right off the bat
11139  std::size_t max_possible_code_units = (stre - strb) * 4;
11140  if (max_possible_code_units <= SOL_STACK_STRING_OPTIMIZATION_SIZE) {
11141  return convert_into(L, sbo, max_possible_code_units, strb, stre);
11142  }
11143  // otherwise, we must manually count/check size
11144  std::size_t needed_size = 0;
11145  for (const char32_t* strtarget = strb; strtarget < stre;) {
11146  auto dr = unicode::utf32_to_code_point(strtarget, stre);
11147  auto er = unicode::code_point_to_utf8(dr.codepoint);
11148  needed_size += er.code_units_size;
11149  strtarget = dr.next;
11150  }
11151  if (needed_size < SOL_STACK_STRING_OPTIMIZATION_SIZE) {
11152  return convert_into(L, sbo, needed_size, strb, stre);
11153  }
11154  std::string u8str("", 0);
11155  u8str.resize(needed_size);
11156  char* target = &u8str[0];
11157  return convert_into(L, target, needed_size, strb, stre);
11158  }
11159  };
11160 
11161  template <>
11162  struct pusher<char32_t*> {
11163  static int push(lua_State* L, const char32_t* str) {
11165  (void)p;
11166  return p.push(L, str);
11167  }
11168 
11169  static int push(lua_State* L, const char32_t* strb, const char32_t* stre) {
11171  (void)p;
11172  return p.push(L, strb, stre);
11173  }
11174 
11175  static int push(lua_State* L, const char32_t* str, std::size_t len) {
11177  (void)p;
11178  return p.push(L, str, len);
11179  }
11180  };
11181 
11182  template <size_t N>
11183  struct pusher<wchar_t[N]> {
11184  static int push(lua_State* L, const wchar_t (&str)[N]) {
11185  return push(L, str, std::char_traits<wchar_t>::length(str));
11186  }
11187 
11188  static int push(lua_State* L, const wchar_t (&str)[N], std::size_t sz) {
11189  return stack::push<const wchar_t*>(L, str, str + sz);
11190  }
11191  };
11192 
11193  template <size_t N>
11194  struct pusher<char16_t[N]> {
11195  static int push(lua_State* L, const char16_t (&str)[N]) {
11196  return push(L, str, std::char_traits<char16_t>::length(str));
11197  }
11198 
11199  static int push(lua_State* L, const char16_t (&str)[N], std::size_t sz) {
11200  return stack::push<const char16_t*>(L, str, str + sz);
11201  }
11202  };
11203 
11204  template <size_t N>
11205  struct pusher<char32_t[N]> {
11206  static int push(lua_State* L, const char32_t (&str)[N]) {
11207  return push(L, str, std::char_traits<char32_t>::length(str));
11208  }
11209 
11210  static int push(lua_State* L, const char32_t (&str)[N], std::size_t sz) {
11211  return stack::push<const char32_t*>(L, str, str + sz);
11212  }
11213  };
11214 
11215  template <>
11216  struct pusher<wchar_t> {
11217  static int push(lua_State* L, wchar_t c) {
11218  const wchar_t str[2] = { c, '\0' };
11219  return stack::push(L, &str[0], 1);
11220  }
11221  };
11222 
11223  template <>
11224  struct pusher<char16_t> {
11225  static int push(lua_State* L, char16_t c) {
11226  const char16_t str[2] = { c, '\0' };
11227  return stack::push(L, &str[0], 1);
11228  }
11229  };
11230 
11231  template <>
11232  struct pusher<char32_t> {
11233  static int push(lua_State* L, char32_t c) {
11234  const char32_t str[2] = { c, '\0' };
11235  return stack::push(L, &str[0], 1);
11236  }
11237  };
11238 
11239  template <typename Ch, typename Traits, typename Al>
11240  struct pusher<std::basic_string<Ch, Traits, Al>, std::enable_if_t<!std::is_same<Ch, char>::value>> {
11241  static int push(lua_State* L, const std::basic_string<Ch, Traits, Al>& wstr) {
11242  return push(L, wstr, wstr.size());
11243  }
11244 
11245  static int push(lua_State* L, const std::basic_string<Ch, Traits, Al>& wstr, std::size_t sz) {
11246  return stack::push(L, wstr.data(), wstr.data() + sz);
11247  }
11248  };
11249 
11250  template <typename... Args>
11251  struct pusher<std::tuple<Args...>> {
11252  template <std::size_t... I, typename T>
11253  static int push(std::index_sequence<I...>, lua_State* L, T&& t) {
11254  int pushcount = 0;
11255  (void)detail::swallow{ 0, (pushcount += stack::push(L, detail::forward_get<I>(t)), 0)... };
11256  return pushcount;
11257  }
11258 
11259  template <typename T>
11260  static int push(lua_State* L, T&& t) {
11261  return push(std::index_sequence_for<Args...>(), L, std::forward<T>(t));
11262  }
11263  };
11264 
11265  template <typename A, typename B>
11266  struct pusher<std::pair<A, B>> {
11267  template <typename T>
11268  static int push(lua_State* L, T&& t) {
11269  int pushcount = stack::push(L, detail::forward_get<0>(t));
11270  pushcount += stack::push(L, detail::forward_get<1>(t));
11271  return pushcount;
11272  }
11273  };
11274 
11275  template <typename O>
11276  struct pusher<optional<O>> {
11277  template <typename T>
11278  static int push(lua_State* L, T&& t) {
11279  if (t == nullopt) {
11280  return stack::push(L, nullopt);
11281  }
11282  return stack::push(L, static_cast<std::conditional_t<std::is_lvalue_reference<T>::value, O&, O&&>>(t.value()));
11283  }
11284  };
11285 
11286  template <>
11287  struct pusher<nullopt_t> {
11288  static int push(lua_State* L, nullopt_t) {
11289  return stack::push(L, lua_nil);
11290  }
11291  };
11292 
11293  template <>
11294  struct pusher<std::nullptr_t> {
11295  static int push(lua_State* L, std::nullptr_t) {
11296  return stack::push(L, lua_nil);
11297  }
11298  };
11299 
11300  template <>
11301  struct pusher<this_state> {
11302  static int push(lua_State*, const this_state&) {
11303  return 0;
11304  }
11305  };
11306 
11307  template <>
11309  static int push(lua_State*, const this_main_state&) {
11310  return 0;
11311  }
11312  };
11313 
11314  template <>
11315  struct pusher<new_table> {
11316  static int push(lua_State* L, const new_table& nt) {
11317  lua_createtable(L, nt.sequence_hint, nt.map_hint);
11318  return 1;
11319  }
11320  };
11321 
11322 #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
11323  template <typename O>
11324  struct pusher<std::optional<O>> {
11325  template <typename T>
11326  static int push(lua_State* L, T&& t) {
11327  if (t == std::nullopt) {
11328  return stack::push(L, nullopt);
11329  }
11330  return stack::push(L, static_cast<std::conditional_t<std::is_lvalue_reference<T>::value, O&, O&&>>(t.value()));
11331  }
11332  };
11333 
11334 #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
11335  namespace stack_detail {
11336 
11337  struct push_function {
11338  lua_State* L;
11339 
11340  push_function(lua_State* L)
11341  : L(L) {
11342  }
11343 
11344  template <typename T>
11345  int operator()(T&& value) const {
11346  return stack::push<T>(L, std::forward<T>(value));
11347  }
11348  };
11349 
11350  } // namespace stack_detail
11351 
11352  template <typename... Tn>
11353  struct pusher<std::variant<Tn...>> {
11354  static int push(lua_State* L, const std::variant<Tn...>& v) {
11355  return std::visit(stack_detail::push_function(L), v);
11356  }
11357 
11358  static int push(lua_State* L, std::variant<Tn...>&& v) {
11359  return std::visit(stack_detail::push_function(L), std::move(v));
11360  }
11361  };
11362 #endif // Variant because Clang is terrible
11363 #endif // C++17 Support
11364 }
11365 } // namespace sol::stack
11366 
11367 // end of sol/stack_push.hpp
11368 
11369 // beginning of sol/stack_pop.hpp
11370 
11371 namespace sol {
11372 namespace stack {
11373  template <typename T, typename>
11374  struct popper {
11375  inline static decltype(auto) pop(lua_State* L) {
11376  record tracking{};
11377 #ifdef __INTEL_COMPILER
11378  auto&& r = get<T>(L, -lua_size<T>::value, tracking);
11379 #else
11380  decltype(auto) r = get<T>(L, -lua_size<T>::value, tracking);
11381 #endif
11382  lua_pop(L, tracking.used);
11383  return r;
11384  }
11385  };
11386 
11387  template <typename T>
11388  struct popper<T, std::enable_if_t<is_stack_based<meta::unqualified_t<T>>::value>> {
11389  static_assert(meta::neg<is_stack_based<meta::unqualified_t<T>>>::value, "You cannot pop something that lives solely on the stack: it will not remain on the stack when popped and thusly will go out of scope!");
11390  };
11391 }
11392 } // namespace sol::stack
11393 
11394 // end of sol/stack_pop.hpp
11395 
11396 // beginning of sol/stack_field.hpp
11397 
11398 namespace sol {
11399 namespace stack {
11400  template <typename T, bool, bool, typename>
11401  struct field_getter {
11402  template <typename Key>
11403  void get(lua_State* L, Key&& key, int tableindex = -2) {
11404  push(L, std::forward<Key>(key));
11405  lua_gettable(L, tableindex);
11406  }
11407  };
11408 
11409  template <typename T, bool global, typename C>
11410  struct field_getter<T, global, true, C> {
11411  template <typename Key>
11412  void get(lua_State* L, Key&& key, int tableindex = -2) {
11413  push(L, std::forward<Key>(key));
11414  lua_rawget(L, tableindex);
11415  }
11416  };
11417 
11418  template <bool b, bool raw, typename C>
11419  struct field_getter<metatable_t, b, raw, C> {
11420  void get(lua_State* L, metatable_t, int tableindex = -1) {
11421  if (lua_getmetatable(L, tableindex) == 0)
11422  push(L, lua_nil);
11423  }
11424  };
11425 
11426  template <bool b, bool raw, typename C>
11427  struct field_getter<env_t, b, raw, C> {
11428  void get(lua_State* L, env_t, int tableindex = -1) {
11429 #if SOL_LUA_VERSION < 502
11430  // Use lua_setfenv
11431  lua_getfenv(L, tableindex);
11432 #else
11433  // Use upvalues as explained in Lua 5.2 and beyond's manual
11434  if (lua_getupvalue(L, tableindex, 1) == nullptr) {
11435  push(L, lua_nil);
11436  }
11437 #endif
11438  }
11439  };
11440 
11441  template <typename T, bool raw>
11442  struct field_getter<T, true, raw, std::enable_if_t<meta::is_c_str<T>::value>> {
11443  template <typename Key>
11444  void get(lua_State* L, Key&& key, int = -1) {
11445  lua_getglobal(L, &key[0]);
11446  }
11447  };
11448 
11449  template <typename T>
11450  struct field_getter<T, false, false, std::enable_if_t<meta::is_c_str<T>::value>> {
11451  template <typename Key>
11452  void get(lua_State* L, Key&& key, int tableindex = -1) {
11453  lua_getfield(L, tableindex, &key[0]);
11454  }
11455  };
11456 
11457 #if SOL_LUA_VERSION >= 503
11458  template <typename T>
11459  struct field_getter<T, false, false, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
11460  template <typename Key>
11461  void get(lua_State* L, Key&& key, int tableindex = -1) {
11462  lua_geti(L, tableindex, static_cast<lua_Integer>(key));
11463  }
11464  };
11465 #endif // Lua 5.3.x
11466 
11467 #if SOL_LUA_VERSION >= 502
11468  template <typename C>
11469  struct field_getter<void*, false, true, C> {
11470  void get(lua_State* L, void* key, int tableindex = -1) {
11471  lua_rawgetp(L, tableindex, key);
11472  }
11473  };
11474 #endif // Lua 5.3.x
11475 
11476  template <typename T>
11477  struct field_getter<T, false, true, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
11478  template <typename Key>
11479  void get(lua_State* L, Key&& key, int tableindex = -1) {
11480  lua_rawgeti(L, tableindex, static_cast<lua_Integer>(key));
11481  }
11482  };
11483 
11484  template <typename... Args, bool b, bool raw, typename C>
11485  struct field_getter<std::tuple<Args...>, b, raw, C> {
11486  template <std::size_t... I, typename Keys>
11487  void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) {
11488  get_field<b, raw>(L, detail::forward_get<0>(keys), tableindex);
11489  void(detail::swallow{(get_field<false, raw>(L, detail::forward_get<I>(keys)), 0)...});
11490  reference saved(L, -1);
11491  lua_pop(L, static_cast<int>(sizeof...(I)));
11492  saved.push();
11493  }
11494 
11495  template <typename Keys>
11496  void get(lua_State* L, Keys&& keys) {
11497  apply(std::make_index_sequence<sizeof...(Args)>(), L, std::forward<Keys>(keys), lua_absindex(L, -1));
11498  }
11499 
11500  template <typename Keys>
11501  void get(lua_State* L, Keys&& keys, int tableindex) {
11502  apply(std::make_index_sequence<sizeof...(Args)>(), L, std::forward<Keys>(keys), tableindex);
11503  }
11504  };
11505 
11506  template <typename A, typename B, bool b, bool raw, typename C>
11507  struct field_getter<std::pair<A, B>, b, raw, C> {
11508  template <typename Keys>
11509  void get(lua_State* L, Keys&& keys, int tableindex) {
11510  get_field<b, raw>(L, detail::forward_get<0>(keys), tableindex);
11511  get_field<false, raw>(L, detail::forward_get<1>(keys));
11512  reference saved(L, -1);
11513  lua_pop(L, static_cast<int>(2));
11514  saved.push();
11515  }
11516 
11517  template <typename Keys>
11518  void get(lua_State* L, Keys&& keys) {
11519  get_field<b, raw>(L, detail::forward_get<0>(keys));
11520  get_field<false, raw>(L, detail::forward_get<1>(keys));
11521  reference saved(L, -1);
11522  lua_pop(L, static_cast<int>(2));
11523  saved.push();
11524  }
11525  };
11526 
11527  template <typename T, bool, bool, typename>
11528  struct field_setter {
11529  template <typename Key, typename Value>
11530  void set(lua_State* L, Key&& key, Value&& value, int tableindex = -3) {
11531  push(L, std::forward<Key>(key));
11532  push(L, std::forward<Value>(value));
11533  lua_settable(L, tableindex);
11534  }
11535  };
11536 
11537  template <typename T, bool b, typename C>
11538  struct field_setter<T, b, true, C> {
11539  template <typename Key, typename Value>
11540  void set(lua_State* L, Key&& key, Value&& value, int tableindex = -3) {
11541  push(L, std::forward<Key>(key));
11542  push(L, std::forward<Value>(value));
11543  lua_rawset(L, tableindex);
11544  }
11545  };
11546 
11547  template <bool b, bool raw, typename C>
11548  struct field_setter<metatable_t, b, raw, C> {
11549  template <typename Value>
11550  void set(lua_State* L, metatable_t, Value&& value, int tableindex = -2) {
11551  push(L, std::forward<Value>(value));
11552  lua_setmetatable(L, tableindex);
11553  }
11554  };
11555 
11556  template <typename T, bool raw>
11557  struct field_setter<T, true, raw, std::enable_if_t<meta::is_c_str<T>::value>> {
11558  template <typename Key, typename Value>
11559  void set(lua_State* L, Key&& key, Value&& value, int = -2) {
11560  push(L, std::forward<Value>(value));
11561  lua_setglobal(L, &key[0]);
11562  }
11563  };
11564 
11565  template <typename T>
11566  struct field_setter<T, false, false, std::enable_if_t<meta::is_c_str<T>::value>> {
11567  template <typename Key, typename Value>
11568  void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
11569  push(L, std::forward<Value>(value));
11570  lua_setfield(L, tableindex, &key[0]);
11571  }
11572  };
11573 
11574 #if SOL_LUA_VERSION >= 503
11575  template <typename T>
11576  struct field_setter<T, false, false, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
11577  template <typename Key, typename Value>
11578  void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
11579  push(L, std::forward<Value>(value));
11580  lua_seti(L, tableindex, static_cast<lua_Integer>(key));
11581  }
11582  };
11583 #endif // Lua 5.3.x
11584 
11585  template <typename T>
11586  struct field_setter<T, false, true, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
11587  template <typename Key, typename Value>
11588  void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
11589  push(L, std::forward<Value>(value));
11590  lua_rawseti(L, tableindex, static_cast<lua_Integer>(key));
11591  }
11592  };
11593 
11594 #if SOL_LUA_VERSION >= 502
11595  template <typename C>
11596  struct field_setter<void*, false, true, C> {
11597  template <typename Key, typename Value>
11598  void set(lua_State* L, void* key, Value&& value, int tableindex = -2) {
11599  push(L, std::forward<Value>(value));
11600  lua_rawsetp(L, tableindex, key);
11601  }
11602  };
11603 #endif // Lua 5.2.x
11604 
11605  template <typename... Args, bool b, bool raw, typename C>
11606  struct field_setter<std::tuple<Args...>, b, raw, C> {
11607  template <bool g, std::size_t I, typename Key, typename Value>
11608  void apply(std::index_sequence<I>, lua_State* L, Key&& keys, Value&& value, int tableindex) {
11609  I < 1 ? set_field<g, raw>(L, detail::forward_get<I>(keys), std::forward<Value>(value), tableindex) : set_field<g, raw>(L, detail::forward_get<I>(keys), std::forward<Value>(value));
11610  }
11611 
11612  template <bool g, std::size_t I0, std::size_t I1, std::size_t... I, typename Keys, typename Value>
11613  void apply(std::index_sequence<I0, I1, I...>, lua_State* L, Keys&& keys, Value&& value, int tableindex) {
11614  I0 < 1 ? get_field<g, raw>(L, detail::forward_get<I0>(keys), tableindex) : get_field<g, raw>(L, detail::forward_get<I0>(keys), -1);
11615  apply<false>(std::index_sequence<I1, I...>(), L, std::forward<Keys>(keys), std::forward<Value>(value), -1);
11616  }
11617 
11618  template <bool g, std::size_t I0, std::size_t... I, typename Keys, typename Value>
11619  void top_apply(std::index_sequence<I0, I...>, lua_State* L, Keys&& keys, Value&& value, int tableindex) {
11620  apply<g>(std::index_sequence<I0, I...>(), L, std::forward<Keys>(keys), std::forward<Value>(value), tableindex);
11621  lua_pop(L, static_cast<int>(sizeof...(I)));
11622  }
11623 
11624  template <typename Keys, typename Value>
11625  void set(lua_State* L, Keys&& keys, Value&& value, int tableindex = -3) {
11626  top_apply<b>(std::make_index_sequence<sizeof...(Args)>(), L, std::forward<Keys>(keys), std::forward<Value>(value), tableindex);
11627  }
11628  };
11629 
11630  template <typename A, typename B, bool b, bool raw, typename C>
11631  struct field_setter<std::pair<A, B>, b, raw, C> {
11632  template <typename Keys, typename Value>
11633  void set(lua_State* L, Keys&& keys, Value&& value, int tableindex = -1) {
11634  get_field<b, raw>(L, detail::forward_get<0>(keys), tableindex);
11635  set_field<false, raw>(L, detail::forward_get<1>(keys), std::forward<Value>(value));
11636  lua_pop(L, 1);
11637  }
11638  };
11639 }
11640 } // namespace sol::stack
11641 
11642 // end of sol/stack_field.hpp
11643 
11644 // beginning of sol/stack_probe.hpp
11645 
11646 namespace sol {
11647 namespace stack {
11648  template <typename T, typename P, bool b, bool raw, typename>
11649  struct probe_field_getter {
11650  template <typename Key>
11651  probe get(lua_State* L, Key&& key, int tableindex = -2) {
11652  if (!b && !maybe_indexable(L, tableindex)) {
11653  return probe(false, 0);
11654  }
11655  get_field<b, raw>(L, std::forward<Key>(key), tableindex);
11656  return probe(check<P>(L), 1);
11657  }
11658  };
11659 
11660  template <typename A, typename B, typename P, bool b, bool raw, typename C>
11661  struct probe_field_getter<std::pair<A, B>, P, b, raw, C> {
11662  template <typename Keys>
11663  probe get(lua_State* L, Keys&& keys, int tableindex = -2) {
11664  if (!b && !maybe_indexable(L, tableindex)) {
11665  return probe(false, 0);
11666  }
11667  get_field<b, raw>(L, std::get<0>(keys), tableindex);
11668  if (!maybe_indexable(L)) {
11669  return probe(false, 1);
11670  }
11671  get_field<false, raw>(L, std::get<1>(keys), tableindex);
11672  return probe(check<P>(L), 2);
11673  }
11674  };
11675 
11676  template <typename... Args, typename P, bool b, bool raw, typename C>
11677  struct probe_field_getter<std::tuple<Args...>, P, b, raw, C> {
11678  template <std::size_t I, typename Keys>
11679  probe apply(std::index_sequence<I>, int sofar, lua_State* L, Keys&& keys, int tableindex) {
11680  get_field < I<1 && b, raw>(L, std::get<I>(keys), tableindex);
11681  return probe(check<P>(L), sofar);
11682  }
11683 
11684  template <std::size_t I, std::size_t I1, std::size_t... In, typename Keys>
11685  probe apply(std::index_sequence<I, I1, In...>, int sofar, lua_State* L, Keys&& keys, int tableindex) {
11686  get_field < I<1 && b, raw>(L, std::get<I>(keys), tableindex);
11687  if (!maybe_indexable(L)) {
11688  return probe(false, sofar);
11689  }
11690  return apply(std::index_sequence<I1, In...>(), sofar + 1, L, std::forward<Keys>(keys), -1);
11691  }
11692 
11693  template <typename Keys>
11694  probe get(lua_State* L, Keys&& keys, int tableindex = -2) {
11695  if (!b && !maybe_indexable(L, tableindex)) {
11696  return probe(false, 0);
11697  }
11698  return apply(std::index_sequence_for<Args...>(), 1, L, std::forward<Keys>(keys), tableindex);
11699  }
11700  };
11701 }
11702 } // namespace sol::stack
11703 
11704 // end of sol/stack_probe.hpp
11705 
11706 namespace sol {
11707  namespace detail {
11708  using typical_chunk_name_t = char[32];
11709 
11711  static const std::string name = "";
11712  return name;
11713  }
11714 
11715  template <std::size_t N>
11716  const char* make_chunk_name(const string_view& code, const std::string& chunkname, char (&basechunkname)[N]) {
11717  if (chunkname.empty()) {
11718  auto it = code.cbegin();
11719  auto e = code.cend();
11720  std::size_t i = 0;
11721  static const std::size_t n = N - 4;
11722  for (i = 0; i < n && it != e; ++i, ++it) {
11723  basechunkname[i] = *it;
11724  }
11725  if (it != e) {
11726  for (std::size_t c = 0; c < 3; ++i, ++c) {
11727  basechunkname[i] = '.';
11728  }
11729  }
11730  basechunkname[i] = '\0';
11731  return &basechunkname[0];
11732  }
11733  else {
11734  return chunkname.c_str();
11735  }
11736  }
11737  } // namespace detail
11738 
11739  namespace stack {
11740  namespace stack_detail {
11741  template <typename T>
11742  inline int push_as_upvalues(lua_State* L, T& item) {
11743  typedef std::decay_t<T> TValue;
11744  static const std::size_t itemsize = sizeof(TValue);
11745  static const std::size_t voidsize = sizeof(void*);
11746  static const std::size_t voidsizem1 = voidsize - 1;
11747  static const std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize;
11748  typedef std::array<void*, data_t_count> data_t;
11749 
11750  data_t data{ {} };
11751  std::memcpy(&data[0], std::addressof(item), itemsize);
11752  int pushcount = 0;
11753  for (auto&& v : data) {
11754  pushcount += push(L, lightuserdata_value(v));
11755  }
11756  return pushcount;
11757  }
11758 
11759  template <typename T>
11760  inline std::pair<T, int> get_as_upvalues(lua_State* L, int index = 2) {
11761  static const std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*);
11762  typedef std::array<void*, data_t_count> data_t;
11763  data_t voiddata{ {} };
11764  for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) {
11765  voiddata[i] = get<lightuserdata_value>(L, upvalue_index(index++));
11766  }
11767  return std::pair<T, int>(*reinterpret_cast<T*>(static_cast<void*>(voiddata.data())), index);
11768  }
11769 
11770  struct evaluator {
11771  template <typename Fx, typename... Args>
11772  static decltype(auto) eval(types<>, std::index_sequence<>, lua_State*, int, record&, Fx&& fx, Args&&... args) {
11773  return std::forward<Fx>(fx)(std::forward<Args>(args)...);
11774  }
11775 
11776  template <typename Fx, typename Arg, typename... Args, std::size_t I, std::size_t... Is, typename... FxArgs>
11777  static decltype(auto) eval(types<Arg, Args...>, std::index_sequence<I, Is...>, lua_State* L, int start, record& tracking, Fx&& fx, FxArgs&&... fxargs) {
11778  return eval(types<Args...>(), std::index_sequence<Is...>(), L, start, tracking, std::forward<Fx>(fx), std::forward<FxArgs>(fxargs)..., stack_detail::unchecked_get<Arg>(L, start + tracking.used, tracking));
11779  }
11780  };
11781 
11782  template <bool checkargs = detail::default_safe_function_calls , std::size_t... I, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value >>
11783  inline decltype(auto) call(types<R>, types<Args...> ta, std::index_sequence<I...> tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
11784 #ifndef _MSC_VER
11785  static_assert(meta::all<meta::is_not_move_only<Args>...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention.");
11786 #endif // This compiler make me so sad
11787  argument_handler<types<R, Args...>> handler{};
11788  multi_check<checkargs, Args...>(L, start, handler);
11789  record tracking{};
11790  return evaluator{}.eval(ta, tai, L, start, tracking, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11791  }
11792 
11793  template <bool checkargs = detail::default_safe_function_calls, std::size_t... I, typename... Args, typename Fx, typename... FxArgs>
11794  inline void call(types<void>, types<Args...> ta, std::index_sequence<I...> tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
11795 #ifndef _MSC_VER
11796  static_assert(meta::all<meta::is_not_move_only<Args>...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention.");
11797 #endif // This compiler make me so fucking sad
11798  argument_handler<types<void, Args...>> handler{};
11799  multi_check<checkargs, Args...>(L, start, handler);
11800  record tracking{};
11801  evaluator{}.eval(ta, tai, L, start, tracking, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11802  }
11803  } // namespace stack_detail
11804 
11805  template <typename T>
11806  int set_ref(lua_State* L, T&& arg, int tableindex = -2) {
11807  push(L, std::forward<T>(arg));
11808  return luaL_ref(L, tableindex);
11809  }
11810 
11811  template <bool check_args = detail::default_safe_function_calls, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
11812  inline decltype(auto) call(types<R> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
11813  typedef std::make_index_sequence<sizeof...(Args)> args_indices;
11814  return stack_detail::call<check_args>(tr, ta, args_indices(), L, start, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11815  }
11816 
11817  template <bool check_args = detail::default_safe_function_calls, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
11818  inline decltype(auto) call(types<R> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
11819  return call<check_args>(tr, ta, L, 1, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11820  }
11821 
11822  template <bool check_args = detail::default_safe_function_calls, typename... Args, typename Fx, typename... FxArgs>
11823  inline void call(types<void> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
11824  typedef std::make_index_sequence<sizeof...(Args)> args_indices;
11825  stack_detail::call<check_args>(tr, ta, args_indices(), L, start, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11826  }
11827 
11828  template <bool check_args = detail::default_safe_function_calls, typename... Args, typename Fx, typename... FxArgs>
11829  inline void call(types<void> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
11830  call<check_args>(tr, ta, L, 1, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11831  }
11832 
11833  template <bool check_args = detail::default_safe_function_calls, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
11834  inline decltype(auto) call_from_top(types<R> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
11835  typedef meta::count_for_pack<lua_size, Args...> expected_count;
11836  return call<check_args>(tr, ta, L, (std::max)(static_cast<int>(lua_gettop(L) - expected_count::value), static_cast<int>(0)), std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11837  }
11838 
11839  template <bool check_args = detail::default_safe_function_calls, typename... Args, typename Fx, typename... FxArgs>
11840  inline void call_from_top(types<void> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
11841  typedef meta::count_for_pack<lua_size, Args...> expected_count;
11842  call<check_args>(tr, ta, L, (std::max)(static_cast<int>(lua_gettop(L) - expected_count::value), static_cast<int>(0)), std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
11843  }
11844 
11845  template <bool check_args = detail::default_safe_function_calls, bool clean_stack = true, typename... Args, typename Fx, typename... FxArgs>
11846  inline int call_into_lua(types<void> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) {
11847  call<check_args>(tr, ta, L, start, std::forward<Fx>(fx), std::forward<FxArgs>(fxargs)...);
11848  if (clean_stack) {
11849  lua_settop(L, 0);
11850  }
11851  return 0;
11852  }
11853 
11854  template <bool check_args = detail::default_safe_function_calls, bool clean_stack = true, typename Ret0, typename... Ret, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<meta::neg<std::is_void<Ret0>>::value>>
11855  inline int call_into_lua(types<Ret0, Ret...>, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) {
11856  decltype(auto) r = call<check_args>(types<meta::return_type_t<Ret0, Ret...>>(), ta, L, start, std::forward<Fx>(fx), std::forward<FxArgs>(fxargs)...);
11859  std::is_same<R, absolute_index>,
11860  std::is_same<R, ref_index>,
11861  std::is_same<R, raw_index>>
11862  is_stack;
11863  if (clean_stack && !is_stack::value) {
11864  lua_settop(L, 0);
11865  }
11866  return push_reference(L, std::forward<decltype(r)>(r));
11867  }
11868 
11869  template <bool check_args = detail::default_safe_function_calls, bool clean_stack = true, typename Fx, typename... FxArgs>
11870  inline int call_lua(lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) {
11871  typedef lua_bind_traits<meta::unqualified_t<Fx>> traits_type;
11872  typedef typename traits_type::args_list args_list;
11873  typedef typename traits_type::returns_list returns_list;
11874  return call_into_lua<check_args, clean_stack>(returns_list(), args_list(), L, start, std::forward<Fx>(fx), std::forward<FxArgs>(fxargs)...);
11875  }
11876 
11877  inline call_syntax get_call_syntax(lua_State* L, const string_view& key, int index) {
11878  if (lua_gettop(L) == 0) {
11879  return call_syntax::dot;
11880  }
11881  luaL_getmetatable(L, key.data());
11882  auto pn = pop_n(L, 1);
11883  if (lua_compare(L, -1, index, LUA_OPEQ) != 1) {
11884  return call_syntax::dot;
11885  }
11886  return call_syntax::colon;
11887  }
11888 
11889  inline void script(lua_State* L, const string_view& code, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
11890  detail::typical_chunk_name_t basechunkname = {};
11891  const char* chunknametarget = detail::make_chunk_name(code, chunkname, basechunkname);
11892  if (luaL_loadbufferx(L, code.data(), code.size(), chunknametarget, to_string(mode).c_str()) || lua_pcall(L, 0, LUA_MULTRET, 0)) {
11893  lua_error(L);
11894  }
11895  }
11896 
11897  inline void script_file(lua_State* L, const std::string& filename, load_mode mode = load_mode::any) {
11898  if (luaL_loadfilex(L, filename.c_str(), to_string(mode).c_str()) || lua_pcall(L, 0, LUA_MULTRET, 0)) {
11899  lua_error(L);
11900  }
11901  }
11902 
11903  inline void luajit_exception_handler(lua_State* L, int (*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) {
11904 #if defined(SOL_LUAJIT) && !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
11905  if (L == nullptr) {
11906  return;
11907  }
11908  lua_pushlightuserdata(L, (void*)handler);
11909  auto pn = pop_n(L, 1);
11910  luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_ON);
11911 #else
11912  (void)L;
11913  (void)handler;
11914 #endif
11915  }
11916 
11917  inline void luajit_exception_off(lua_State* L) {
11918 #if defined(SOL_LUAJIT)
11919  if (L == nullptr) {
11920  return;
11921  }
11922  luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_OFF);
11923 #else
11924  (void)L;
11925 #endif
11926  }
11927  } // namespace stack
11928 } // namespace sol
11929 
11930 // end of sol/stack.hpp
11931 
11932 // beginning of sol/unsafe_function.hpp
11933 
11934 // beginning of sol/function_result.hpp
11935 
11936 // beginning of sol/protected_function_result.hpp
11937 
11938 // beginning of sol/proxy_base.hpp
11939 
11940 namespace sol {
11941  struct proxy_base_tag {};
11942 
11943  template <typename Super>
11944  struct proxy_base : proxy_base_tag {
11945  operator std::string() const {
11946  const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
11947  return super.template get<std::string>();
11948  }
11949 
11950  template <typename T, meta::enable<meta::neg<meta::is_string_constructible<T>>, is_proxy_primitive<meta::unqualified_t<T>>> = meta::enabler>
11951  operator T() const {
11952  const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
11953  return super.template get<T>();
11954  }
11955 
11956  template <typename T, meta::enable<meta::neg<meta::is_string_constructible<T>>, meta::neg<is_proxy_primitive<meta::unqualified_t<T>>>> = meta::enabler>
11957  operator T&() const {
11958  const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
11959  return super.template get<T&>();
11960  }
11961 
11962  lua_State* lua_state() const {
11963  const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
11964  return super.lua_state();
11965  }
11966  };
11967 } // namespace sol
11968 
11969 // end of sol/proxy_base.hpp
11970 
11971 // beginning of sol/stack_iterator.hpp
11972 
11973 namespace sol {
11974  template <typename proxy_t, bool is_const>
11976  typedef std::conditional_t<is_const, const proxy_t, proxy_t> reference;
11977  typedef std::conditional_t<is_const, const proxy_t*, proxy_t*> pointer;
11978  typedef proxy_t value_type;
11979  typedef std::ptrdiff_t difference_type;
11980  typedef std::random_access_iterator_tag iterator_category;
11981  lua_State* L;
11982  int index;
11984  proxy_t sp;
11985 
11987  : L(nullptr), index((std::numeric_limits<int>::max)()), stacktop((std::numeric_limits<int>::max)()), sp() {
11988  }
11990  : L(r.L), index(r.index), stacktop(r.stacktop), sp(r.sp) {
11991  }
11992  stack_iterator(lua_State* luastate, int idx, int topidx)
11993  : L(luastate), index(idx), stacktop(topidx), sp(luastate, idx) {
11994  }
11995 
11996  reference operator*() {
11997  return proxy_t(L, index);
11998  }
11999 
12000  reference operator*() const {
12001  return proxy_t(L, index);
12002  }
12003 
12004  pointer operator->() {
12005  sp = proxy_t(L, index);
12006  return &sp;
12007  }
12008 
12009  pointer operator->() const {
12010  const_cast<proxy_t&>(sp) = proxy_t(L, index);
12011  return &sp;
12012  }
12013 
12015  ++index;
12016  return *this;
12017  }
12018 
12020  auto r = *this;
12021  this->operator++();
12022  return r;
12023  }
12024 
12026  --index;
12027  return *this;
12028  }
12029 
12031  auto r = *this;
12032  this->operator--();
12033  return r;
12034  }
12035 
12036  stack_iterator& operator+=(difference_type idx) {
12037  index += static_cast<int>(idx);
12038  return *this;
12039  }
12040 
12041  stack_iterator& operator-=(difference_type idx) {
12042  index -= static_cast<int>(idx);
12043  return *this;
12044  }
12045 
12046  difference_type operator-(const stack_iterator& r) const {
12047  return index - r.index;
12048  }
12049 
12050  stack_iterator operator+(difference_type idx) const {
12051  stack_iterator r = *this;
12052  r += idx;
12053  return r;
12054  }
12055 
12056  reference operator[](difference_type idx) const {
12057  return proxy_t(L, index + static_cast<int>(idx));
12058  }
12059 
12060  bool operator==(const stack_iterator& r) const {
12061  if (stacktop == (std::numeric_limits<int>::max)()) {
12062  return r.index == r.stacktop;
12063  }
12064  else if (r.stacktop == (std::numeric_limits<int>::max)()) {
12065  return index == stacktop;
12066  }
12067  return index == r.index;
12068  }
12069 
12070  bool operator!=(const stack_iterator& r) const {
12071  return !(this->operator==(r));
12072  }
12073 
12074  bool operator<(const stack_iterator& r) const {
12075  return index < r.index;
12076  }
12077 
12078  bool operator>(const stack_iterator& r) const {
12079  return index > r.index;
12080  }
12081 
12082  bool operator<=(const stack_iterator& r) const {
12083  return index <= r.index;
12084  }
12085 
12086  bool operator>=(const stack_iterator& r) const {
12087  return index >= r.index;
12088  }
12089  };
12090 
12091  template <typename proxy_t, bool is_const>
12093  return r + n;
12094  }
12095 } // namespace sol
12096 
12097 // end of sol/stack_iterator.hpp
12098 
12099 // beginning of sol/stack_proxy.hpp
12100 
12101 // beginning of sol/stack_proxy_base.hpp
12102 
12103 namespace sol {
12104  struct stack_proxy_base : public proxy_base<stack_proxy_base> {
12105  private:
12106  lua_State* L;
12107  int index;
12108 
12109  public:
12111  : L(nullptr), index(0) {
12112  }
12113  stack_proxy_base(lua_State* L, int index)
12114  : L(L), index(index) {
12115  }
12116 
12117  template <typename T>
12118  decltype(auto) get() const {
12119  return stack::get<T>(L, stack_index());
12120  }
12121 
12122  template <typename T>
12123  bool is() const {
12124  return stack::check<T>(L, stack_index());
12125  }
12126 
12127  template <typename T>
12128  decltype(auto) as() const {
12129  return get<T>();
12130  }
12131 
12132  type get_type() const noexcept {
12133  return type_of(lua_state(), stack_index());
12134  }
12135 
12136  int push() const {
12137  return push(L);
12138  }
12139 
12140  int push(lua_State* Ls) const {
12141  lua_pushvalue(Ls, index);
12142  return 1;
12143  }
12144 
12145  lua_State* lua_state() const {
12146  return L;
12147  }
12148  int stack_index() const {
12149  return index;
12150  }
12151  };
12152 
12153  namespace stack {
12154  template <>
12156  static stack_proxy_base get(lua_State* L, int index = -1) {
12157  return stack_proxy_base(L, index);
12158  }
12159  };
12160 
12161  template <>
12163  static int push(lua_State*, const stack_proxy_base& ref) {
12164  return ref.push();
12165  }
12166  };
12167  } // namespace stack
12168 
12169 } // namespace sol
12170 
12171 // end of sol/stack_proxy_base.hpp
12172 
12173 namespace sol {
12174  struct stack_proxy : public stack_proxy_base {
12175  public:
12177  : stack_proxy_base() {
12178  }
12179  stack_proxy(lua_State* L, int index)
12180  : stack_proxy_base(L, index) {
12181  }
12182 
12183  template <typename... Ret, typename... Args>
12184  decltype(auto) call(Args&&... args);
12185 
12186  template <typename... Args>
12187  decltype(auto) operator()(Args&&... args) {
12188  return call<>(std::forward<Args>(args)...);
12189  }
12190  };
12191 
12192  namespace stack {
12193  template <>
12195  static stack_proxy get(lua_State* L, int index = -1) {
12196  return stack_proxy(L, index);
12197  }
12198  };
12199 
12200  template <>
12202  static int push(lua_State*, const stack_proxy& ref) {
12203  return ref.push();
12204  }
12205  };
12206  } // namespace stack
12207 } // namespace sol
12208 
12209 // end of sol/stack_proxy.hpp
12210 
12211 namespace sol {
12212  struct protected_function_result : public proxy_base<protected_function_result> {
12213  private:
12214  lua_State* L;
12215  int index;
12219 
12220  template <typename T>
12221  decltype(auto) tagged_get(types<optional<T>>, int index_offset) const {
12222  typedef decltype(stack::get<optional<T>>(L, index)) ret_t;
12223  int target = index + index_offset;
12224  if (!valid()) {
12225  return ret_t(nullopt);
12226  }
12227  return stack::get<optional<T>>(L, target);
12228  }
12229 
12230  template <typename T>
12231  decltype(auto) tagged_get(types<T>, int index_offset) const {
12232  int target = index + index_offset;
12233 #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES
12234  if (!valid()) {
12235  type t = type_of(L, target);
12236  type_panic_c_str(L, target, t, type::none, "bad get from protected_function_result (is not an error)");
12237  }
12238 #endif // Check Argument Safety
12239  return stack::get<T>(L, target);
12240  }
12241 
12242  optional<error> tagged_get(types<optional<error>>, int index_offset) const {
12243  int target = index + index_offset;
12244  if (valid()) {
12245  return nullopt;
12246  }
12247  return error(detail::direct_error, stack::get<std::string>(L, target));
12248  }
12249 
12250  error tagged_get(types<error>, int index_offset) const {
12251  int target = index + index_offset;
12252 #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES
12253  if (valid()) {
12254  type t = type_of(L, target);
12255  type_panic_c_str(L, target, t, type::none, "bad get from protected_function_result (is an error)");
12256  }
12257 #endif // Check Argument Safety
12258  return error(detail::direct_error, stack::get<std::string>(L, target));
12259  }
12260 
12261  public:
12265  typedef std::ptrdiff_t difference_type;
12266  typedef std::size_t size_type;
12269  typedef std::reverse_iterator<iterator> reverse_iterator;
12270  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
12271 
12272  protected_function_result() = default;
12273  protected_function_result(lua_State* Ls, int idx = -1, int retnum = 0, int popped = 0, call_status pferr = call_status::ok) noexcept
12274  : L(Ls), index(idx), returncount(retnum), popcount(popped), err(pferr) {
12275  }
12277  protected_function_result& operator=(const protected_function_result&) = default;
12279  : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) {
12280  // Must be manual, otherwise destructor will screw us
12281  // return count being 0 is enough to keep things clean
12282  // but we will be thorough
12283  o.abandon();
12284  }
12286  L = o.L;
12287  index = o.index;
12288  returncount = o.returncount;
12289  popcount = o.popcount;
12290  err = o.err;
12291  // Must be manual, otherwise destructor will screw us
12292  // return count being 0 is enough to keep things clean
12293  // but we will be thorough
12294  o.abandon();
12295  return *this;
12296  }
12297 
12299  protected_function_result& operator=(const unsafe_function_result& o) = delete;
12301  protected_function_result& operator=(unsafe_function_result&& o) noexcept;
12302 
12303  call_status status() const noexcept {
12304  return err;
12305  }
12306 
12307  bool valid() const noexcept {
12308  return status() == call_status::ok || status() == call_status::yielded;
12309  }
12310 
12311  template <typename T>
12312  decltype(auto) get(int index_offset = 0) const {
12313  return tagged_get(types<meta::unqualified_t<T>>(), index_offset);
12314  }
12315 
12316  type get_type(difference_type index_offset = 0) const noexcept {
12317  return type_of(L, index + static_cast<int>(index_offset));
12318  }
12319 
12320  stack_proxy operator[](difference_type index_offset) const {
12321  return stack_proxy(L, index + static_cast<int>(index_offset));
12322  }
12323 
12324  iterator begin() {
12325  return iterator(L, index, stack_index() + return_count());
12326  }
12327  iterator end() {
12328  return iterator(L, stack_index() + return_count(), stack_index() + return_count());
12329  }
12330  const_iterator begin() const {
12331  return const_iterator(L, index, stack_index() + return_count());
12332  }
12333  const_iterator end() const {
12334  return const_iterator(L, stack_index() + return_count(), stack_index() + return_count());
12335  }
12336  const_iterator cbegin() const {
12337  return begin();
12338  }
12339  const_iterator cend() const {
12340  return end();
12341  }
12342 
12343  reverse_iterator rbegin() {
12344  return std::reverse_iterator<iterator>(begin());
12345  }
12346  reverse_iterator rend() {
12347  return std::reverse_iterator<iterator>(end());
12348  }
12349  const_reverse_iterator rbegin() const {
12350  return std::reverse_iterator<const_iterator>(begin());
12351  }
12352  const_reverse_iterator rend() const {
12353  return std::reverse_iterator<const_iterator>(end());
12354  }
12355  const_reverse_iterator crbegin() const {
12356  return std::reverse_iterator<const_iterator>(cbegin());
12357  }
12358  const_reverse_iterator crend() const {
12359  return std::reverse_iterator<const_iterator>(cend());
12360  }
12361 
12362  lua_State* lua_state() const noexcept {
12363  return L;
12364  };
12365  int stack_index() const noexcept {
12366  return index;
12367  };
12368  int return_count() const noexcept {
12369  return returncount;
12370  };
12371  int pop_count() const noexcept {
12372  return popcount;
12373  };
12374  void abandon() noexcept {
12375  //L = nullptr;
12376  index = 0;
12377  returncount = 0;
12378  popcount = 0;
12379  err = call_status::runtime;
12380  }
12382  stack::remove(L, index, popcount);
12383  }
12384  };
12385 
12386  namespace stack {
12387  template <>
12389  static int push(lua_State* L, const protected_function_result& pfr) {
12390  int p = 0;
12391  for (int i = 0; i < pfr.pop_count(); ++i) {
12392  lua_pushvalue(L, i + pfr.stack_index());
12393  ++p;
12394  }
12395  return p;
12396  }
12397  };
12398  } // namespace stack
12399 } // namespace sol
12400 
12401 // end of sol/protected_function_result.hpp
12402 
12403 // beginning of sol/unsafe_function_result.hpp
12404 
12405 namespace sol {
12406  struct unsafe_function_result : public proxy_base<unsafe_function_result> {
12407  private:
12408  lua_State* L;
12409  int index;
12411 
12412  public:
12416  typedef std::ptrdiff_t difference_type;
12417  typedef std::size_t size_type;
12420  typedef std::reverse_iterator<iterator> reverse_iterator;
12421  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
12422 
12423  unsafe_function_result() = default;
12424  unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0)
12425  : L(Ls), index(idx), returncount(retnum) {
12426  }
12428  unsafe_function_result& operator=(const unsafe_function_result&) = default;
12430  : L(o.L), index(o.index), returncount(o.returncount) {
12431  // Must be manual, otherwise destructor will screw us
12432  // return count being 0 is enough to keep things clean
12433  // but will be thorough
12434  o.abandon();
12435  }
12437  L = o.L;
12438  index = o.index;
12439  returncount = o.returncount;
12440  // Must be manual, otherwise destructor will screw us
12441  // return count being 0 is enough to keep things clean
12442  // but will be thorough
12443  o.abandon();
12444  return *this;
12445  }
12446 
12448  unsafe_function_result& operator=(const protected_function_result& o) = delete;
12450  unsafe_function_result& operator=(protected_function_result&& o) noexcept;
12451 
12452  template <typename T>
12453  decltype(auto) get(difference_type index_offset = 0) const {
12454  return stack::get<T>(L, index + static_cast<int>(index_offset));
12455  }
12456 
12457  type get_type(difference_type index_offset = 0) const noexcept {
12458  return type_of(L, index + static_cast<int>(index_offset));
12459  }
12460 
12461  stack_proxy operator[](difference_type index_offset) const {
12462  return stack_proxy(L, index + static_cast<int>(index_offset));
12463  }
12464 
12465  iterator begin() {
12466  return iterator(L, index, stack_index() + return_count());
12467  }
12468  iterator end() {
12469  return iterator(L, stack_index() + return_count(), stack_index() + return_count());
12470  }
12471  const_iterator begin() const {
12472  return const_iterator(L, index, stack_index() + return_count());
12473  }
12474  const_iterator end() const {
12475  return const_iterator(L, stack_index() + return_count(), stack_index() + return_count());
12476  }
12477  const_iterator cbegin() const {
12478  return begin();
12479  }
12480  const_iterator cend() const {
12481  return end();
12482  }
12483 
12484  reverse_iterator rbegin() {
12485  return std::reverse_iterator<iterator>(begin());
12486  }
12487  reverse_iterator rend() {
12488  return std::reverse_iterator<iterator>(end());
12489  }
12490  const_reverse_iterator rbegin() const {
12491  return std::reverse_iterator<const_iterator>(begin());
12492  }
12493  const_reverse_iterator rend() const {
12494  return std::reverse_iterator<const_iterator>(end());
12495  }
12496  const_reverse_iterator crbegin() const {
12497  return std::reverse_iterator<const_iterator>(cbegin());
12498  }
12499  const_reverse_iterator crend() const {
12500  return std::reverse_iterator<const_iterator>(cend());
12501  }
12502 
12503  call_status status() const noexcept {
12504  return call_status::ok;
12505  }
12506 
12507  bool valid() const noexcept {
12508  return status() == call_status::ok || status() == call_status::yielded;
12509  }
12510 
12511  lua_State* lua_state() const {
12512  return L;
12513  };
12514  int stack_index() const {
12515  return index;
12516  };
12517  int return_count() const {
12518  return returncount;
12519  };
12520  void abandon() noexcept {
12521  //L = nullptr;
12522  index = 0;
12523  returncount = 0;
12524  }
12526  lua_pop(L, returncount);
12527  }
12528  };
12529 
12530  namespace stack {
12531  template <>
12533  static int push(lua_State* L, const unsafe_function_result& fr) {
12534  int p = 0;
12535  for (int i = 0; i < fr.return_count(); ++i) {
12536  lua_pushvalue(L, i + fr.stack_index());
12537  ++p;
12538  }
12539  return p;
12540  }
12541  };
12542  } // namespace stack
12543 } // namespace sol
12544 
12545 // end of sol/unsafe_function_result.hpp
12546 
12547 namespace sol {
12548 
12549  namespace detail {
12550  template <>
12551  struct is_speshul<unsafe_function_result> : std::true_type {};
12552  template <>
12553  struct is_speshul<protected_function_result> : std::true_type {};
12554 
12555  template <std::size_t I, typename... Args, typename T>
12556  stack_proxy get(types<Args...>, index_value<0>, index_value<I>, const T& fr) {
12557  return stack_proxy(fr.lua_state(), static_cast<int>(fr.stack_index() + I));
12558  }
12559 
12560  template <std::size_t I, std::size_t N, typename Arg, typename... Args, typename T, meta::enable<meta::boolean<(N > 0)>> = meta::enabler>
12561  stack_proxy get(types<Arg, Args...>, index_value<N>, index_value<I>, const T& fr) {
12562  return get(types<Args...>(), index_value<N - 1>(), index_value<I + lua_size<Arg>::value>(), fr);
12563  }
12564  } // namespace detail
12565 
12566  template <>
12567  struct tie_size<unsafe_function_result> : std::integral_constant<std::size_t, SIZE_MAX> {};
12568 
12569  template <>
12570  struct tie_size<protected_function_result> : std::integral_constant<std::size_t, SIZE_MAX> {};
12571 
12572  template <std::size_t I>
12573  stack_proxy get(const unsafe_function_result& fr) {
12574  return stack_proxy(fr.lua_state(), static_cast<int>(fr.stack_index() + I));
12575  }
12576 
12577  template <std::size_t I, typename... Args>
12578  stack_proxy get(types<Args...> t, const unsafe_function_result& fr) {
12579  return detail::get(t, index_value<I>(), index_value<0>(), fr);
12580  }
12581 
12582  template <std::size_t I>
12583  stack_proxy get(const protected_function_result& fr) {
12584  return stack_proxy(fr.lua_state(), static_cast<int>(fr.stack_index() + I));
12585  }
12586 
12587  template <std::size_t I, typename... Args>
12588  stack_proxy get(types<Args...> t, const protected_function_result& fr) {
12589  return detail::get(t, index_value<I>(), index_value<0>(), fr);
12590  }
12591 } // namespace sol
12592 
12593 // end of sol/function_result.hpp
12594 
12595 // beginning of sol/function_types.hpp
12596 
12597 // beginning of sol/function_types_core.hpp
12598 
12599 // beginning of sol/wrapper.hpp
12600 
12601 namespace sol {
12602 
12603  namespace detail {
12604  template <typename T>
12605  using array_return_type = std::conditional_t<std::is_array<T>::value, std::add_lvalue_reference_t<T>, T>;
12606  }
12607 
12608  template <typename F, typename = void>
12609  struct wrapper {
12614 
12615  template <typename... Args>
12616  static decltype(auto) call(F& f, Args&&... args) {
12617  return f(std::forward<Args>(args)...);
12618  }
12619 
12620  struct caller {
12621  template <typename... Args>
12622  decltype(auto) operator()(F& fx, Args&&... args) const {
12623  return call(fx, std::forward<Args>(args)...);
12624  }
12625  };
12626  };
12627 
12628  template <typename F>
12629  struct wrapper<F, std::enable_if_t<std::is_function<std::remove_pointer_t<meta::unqualified_t<F>>>::value>> {
12634 
12635  template <F fx, typename... Args>
12636  static decltype(auto) invoke(Args&&... args) {
12637  return fx(std::forward<Args>(args)...);
12638  }
12639 
12640  template <typename... Args>
12641  static decltype(auto) call(F& fx, Args&&... args) {
12642  return fx(std::forward<Args>(args)...);
12643  }
12644 
12645  struct caller {
12646  template <typename... Args>
12647  decltype(auto) operator()(F& fx, Args&&... args) const {
12648  return call(fx, std::forward<Args>(args)...);
12649  }
12650  };
12651 
12652  template <F fx>
12653  struct invoker {
12654  template <typename... Args>
12655  decltype(auto) operator()(Args&&... args) const {
12656  return invoke<fx>(std::forward<Args>(args)...);
12657  }
12658  };
12659  };
12660 
12661  template <typename F>
12662  struct wrapper<F, std::enable_if_t<std::is_member_object_pointer<meta::unqualified_t<F>>::value>> {
12669 
12670  template <F fx>
12671  static auto call(object_type& mem) -> detail::array_return_type<decltype(mem.*fx)> {
12672  return mem.*fx;
12673  }
12674 
12675  template <F fx, typename Arg, typename... Args>
12676  static decltype(auto) invoke(object_type& mem, Arg&& arg, Args&&...) {
12677  return mem.*fx = std::forward<Arg>(arg);
12678  }
12679 
12680  template <typename Fx>
12681  static auto call(Fx&& fx, object_type& mem) -> detail::array_return_type<decltype(mem.*fx)> {
12682  return mem.*fx;
12683  }
12684 
12685  template <typename Fx, typename Arg, typename... Args>
12686  static void call(Fx&& fx, object_type& mem, Arg&& arg, Args&&...) {
12687  (mem.*fx) = std::forward<Arg>(arg);
12688  }
12689 
12690  struct caller {
12691  template <typename Fx, typename... Args>
12692  decltype(auto) operator()(Fx&& fx, object_type& mem, Args&&... args) const {
12693  return call(std::forward<Fx>(fx), mem, std::forward<Args>(args)...);
12694  }
12695  };
12696 
12697  template <F fx>
12698  struct invoker {
12699  template <typename... Args>
12700  decltype(auto) operator()(Args&&... args) const {
12701  return invoke<fx>(std::forward<Args>(args)...);
12702  }
12703  };
12704  };
12705 
12706  template <typename F, typename R, typename O, typename... FArgs>
12708  typedef O object_type;
12711  typedef types<object_type&, FArgs...> free_args_list;
12713 
12714  template <F fx, typename... Args>
12715  static R invoke(O& mem, Args&&... args) {
12716  return (mem.*fx)(std::forward<Args>(args)...);
12717  }
12718 
12719  template <typename Fx, typename... Args>
12720  static R call(Fx&& fx, O& mem, Args&&... args) {
12721  return (mem.*fx)(std::forward<Args>(args)...);
12722  }
12723 
12724  struct caller {
12725  template <typename Fx, typename... Args>
12726  decltype(auto) operator()(Fx&& fx, O& mem, Args&&... args) const {
12727  return call(std::forward<Fx>(fx), mem, std::forward<Args>(args)...);
12728  }
12729  };
12730 
12731  template <F fx>
12732  struct invoker {
12733  template <typename... Args>
12734  decltype(auto) operator()(O& mem, Args&&... args) const {
12735  return invoke<fx>(mem, std::forward<Args>(args)...);
12736  }
12737  };
12738  };
12739 
12740  template <typename R, typename O, typename... Args>
12741  struct wrapper<R (O::*)(Args...)> : public member_function_wrapper<R (O::*)(Args...), R, O, Args...> {
12742  };
12743 
12744  template <typename R, typename O, typename... Args>
12745  struct wrapper<R (O::*)(Args...) const> : public member_function_wrapper<R (O::*)(Args...) const, R, O, Args...> {
12746  };
12747 
12748  template <typename R, typename O, typename... Args>
12749  struct wrapper<R (O::*)(Args...) const volatile> : public member_function_wrapper<R (O::*)(Args...) const volatile, R, O, Args...> {
12750  };
12751 
12752  template <typename R, typename O, typename... Args>
12753  struct wrapper<R (O::*)(Args...)&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> {
12754  };
12755 
12756  template <typename R, typename O, typename... Args>
12757  struct wrapper<R (O::*)(Args...) const&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> {
12758  };
12759 
12760  template <typename R, typename O, typename... Args>
12761  struct wrapper<R (O::*)(Args...) const volatile&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> {
12762  };
12763 
12764  template <typename R, typename O, typename... Args>
12765  struct wrapper<R (O::*)(Args..., ...)&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> {
12766  };
12767 
12768  template <typename R, typename O, typename... Args>
12769  struct wrapper<R (O::*)(Args..., ...) const&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> {
12770  };
12771 
12772  template <typename R, typename O, typename... Args>
12773  struct wrapper<R (O::*)(Args..., ...) const volatile&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> {
12774  };
12775 
12776  template <typename R, typename O, typename... Args>
12777  struct wrapper<R (O::*)(Args...) &&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> {
12778  };
12779 
12780  template <typename R, typename O, typename... Args>
12781  struct wrapper<R (O::*)(Args...) const&&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> {
12782  };
12783 
12784  template <typename R, typename O, typename... Args>
12785  struct wrapper<R (O::*)(Args...) const volatile&&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> {
12786  };
12787 
12788  template <typename R, typename O, typename... Args>
12789  struct wrapper<R (O::*)(Args..., ...) &&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> {
12790  };
12791 
12792  template <typename R, typename O, typename... Args>
12793  struct wrapper<R (O::*)(Args..., ...) const&&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> {
12794  };
12795 
12796  template <typename R, typename O, typename... Args>
12797  struct wrapper<R (O::*)(Args..., ...) const volatile&&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> {
12798  };
12799 
12800 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
12801  //noexcept has become a part of a function's type
12802 
12803  template <typename R, typename O, typename... Args>
12804  struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> {
12805  };
12806 
12807  template <typename R, typename O, typename... Args>
12808  struct wrapper<R (O::*)(Args...) const noexcept> : public member_function_wrapper<R (O::*)(Args...) const noexcept, R, O, Args...> {
12809  };
12810 
12811  template <typename R, typename O, typename... Args>
12812  struct wrapper<R (O::*)(Args...) const volatile noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile noexcept, R, O, Args...> {
12813  };
12814 
12815  template <typename R, typename O, typename... Args>
12816  struct wrapper<R (O::*)(Args...) & noexcept> : public member_function_wrapper<R (O::*)(Args...) & noexcept, R, O, Args...> {
12817  };
12818 
12819  template <typename R, typename O, typename... Args>
12820  struct wrapper<R (O::*)(Args...) const& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> {
12821  };
12822 
12823  template <typename R, typename O, typename... Args>
12824  struct wrapper<R (O::*)(Args...) const volatile& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> {
12825  };
12826 
12827  template <typename R, typename O, typename... Args>
12828  struct wrapper<R (O::*)(Args..., ...) & noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) & noexcept, R, O, Args...> {
12829  };
12830 
12831  template <typename R, typename O, typename... Args>
12832  struct wrapper<R (O::*)(Args..., ...) const& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> {
12833  };
12834 
12835  template <typename R, typename O, typename... Args>
12836  struct wrapper<R (O::*)(Args..., ...) const volatile& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> {
12837  };
12838 
12839  template <typename R, typename O, typename... Args>
12840  struct wrapper<R (O::*)(Args...) && noexcept> : public member_function_wrapper<R (O::*)(Args...) & noexcept, R, O, Args...> {
12841  };
12842 
12843  template <typename R, typename O, typename... Args>
12844  struct wrapper<R (O::*)(Args...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> {
12845  };
12846 
12847  template <typename R, typename O, typename... Args>
12848  struct wrapper<R (O::*)(Args...) const volatile&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> {
12849  };
12850 
12851  template <typename R, typename O, typename... Args>
12852  struct wrapper<R (O::*)(Args..., ...) && noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) & noexcept, R, O, Args...> {
12853  };
12854 
12855  template <typename R, typename O, typename... Args>
12856  struct wrapper<R (O::*)(Args..., ...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> {
12857  };
12858 
12859  template <typename R, typename O, typename... Args>
12860  struct wrapper<R (O::*)(Args..., ...) const volatile&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> {
12861  };
12862 
12863 #endif // noexcept is part of a function's type
12864 
12865 } // namespace sol
12866 
12867 // end of sol/wrapper.hpp
12868 
12869 namespace sol {
12870 namespace function_detail {
12871  template <typename Fx, int start = 1, bool is_yielding = false>
12872  inline int call(lua_State* L) {
12873  Fx& fx = stack::get<user<Fx>>(L, upvalue_index(start));
12874  int nr = fx(L);
12875  if (is_yielding) {
12876  return lua_yield(L, nr);
12877  }
12878  else {
12879  return nr;
12880  }
12881  }
12882 }
12883 } // namespace sol::function_detail
12884 
12885 // end of sol/function_types_core.hpp
12886 
12887 // beginning of sol/function_types_templated.hpp
12888 
12889 // beginning of sol/call.hpp
12890 
12891 // beginning of sol/protect.hpp
12892 
12893 namespace sol {
12894 
12895  template <typename T>
12896  struct protect_t {
12898 
12899  template <typename Arg, typename... Args, meta::disable<std::is_same<protect_t, meta::unqualified_t<Arg>>> = meta::enabler>
12900  protect_t(Arg&& arg, Args&&... args)
12901  : value(std::forward<Arg>(arg), std::forward<Args>(args)...) {
12902  }
12903 
12904  protect_t(const protect_t&) = default;
12905  protect_t(protect_t&&) = default;
12906  protect_t& operator=(const protect_t&) = default;
12907  protect_t& operator=(protect_t&&) = default;
12908  };
12909 
12910  template <typename T>
12911  auto protect(T&& value) {
12912  return protect_t<std::decay_t<T>>(std::forward<T>(value));
12913  }
12914 
12915 } // namespace sol
12916 
12917 // end of sol/protect.hpp
12918 
12919 // beginning of sol/property.hpp
12920 
12921 namespace sol {
12922 
12923  struct no_prop {};
12924 
12925  template <typename R, typename W>
12927  typedef std::integral_constant<bool, !std::is_void<R>::value> can_read;
12928  typedef std::integral_constant<bool, !std::is_void<W>::value> can_write;
12929  typedef std::conditional_t<can_read::value, R, no_prop> Read;
12930  typedef std::conditional_t<can_write::value, W, no_prop> Write;
12931  Read read;
12932  Write write;
12933 
12934  template <typename Rx, typename Wx>
12935  property_wrapper(Rx&& r, Wx&& w)
12936  : read(std::forward<Rx>(r)), write(std::forward<Wx>(w)) {
12937  }
12938  };
12939 
12940  namespace property_detail {
12941  template <typename R, typename W>
12942  inline decltype(auto) property(std::true_type, R&& read, W&& write) {
12943  return property_wrapper<std::decay_t<R>, std::decay_t<W>>(std::forward<R>(read), std::forward<W>(write));
12944  }
12945  template <typename W, typename R>
12946  inline decltype(auto) property(std::false_type, W&& write, R&& read) {
12947  return property_wrapper<std::decay_t<R>, std::decay_t<W>>(std::forward<R>(read), std::forward<W>(write));
12948  }
12949  template <typename R>
12950  inline decltype(auto) property(std::true_type, R&& read) {
12951  return property_wrapper<std::decay_t<R>, void>(std::forward<R>(read), no_prop());
12952  }
12953  template <typename W>
12954  inline decltype(auto) property(std::false_type, W&& write) {
12955  return property_wrapper<void, std::decay_t<W>>(no_prop(), std::forward<W>(write));
12956  }
12957  } // namespace property_detail
12958 
12959  template <typename F, typename G>
12960  inline decltype(auto) property(F&& f, G&& g) {
12961  typedef lua_bind_traits<meta::unqualified_t<F>> left_traits;
12962  typedef lua_bind_traits<meta::unqualified_t<G>> right_traits;
12963  return property_detail::property(meta::boolean<(left_traits::free_arity < right_traits::free_arity)>(), std::forward<F>(f), std::forward<G>(g));
12964  }
12965 
12966  template <typename F>
12967  inline decltype(auto) property(F&& f) {
12968  typedef lua_bind_traits<meta::unqualified_t<F>> left_traits;
12969  return property_detail::property(meta::boolean<(left_traits::free_arity < 2)>(), std::forward<F>(f));
12970  }
12971 
12972  template <typename F>
12973  inline decltype(auto) readonly_property(F&& f) {
12974  return property_detail::property(std::true_type(), std::forward<F>(f));
12975  }
12976 
12977  template <typename F>
12978  inline decltype(auto) writeonly_property(F&& f) {
12979  return property_detail::property(std::false_type(), std::forward<F>(f));
12980  }
12981 
12982  template <typename T>
12984  T v;
12985 
12987  : v(std::move(v)) {
12988  }
12989 
12990  operator T&() {
12991  return v;
12992  }
12993  operator const T&() const {
12994  return v;
12995  }
12996  };
12997 
12998  // Allow someone to make a member variable readonly (const)
12999  template <typename R, typename T>
13000  inline auto readonly(R T::*v) {
13002  }
13003 
13004  template <typename T>
13005  struct var_wrapper {
13007  template <typename... Args>
13008  var_wrapper(Args&&... args)
13009  : value(std::forward<Args>(args)...) {
13010  }
13011  var_wrapper(const var_wrapper&) = default;
13012  var_wrapper(var_wrapper&&) = default;
13013  var_wrapper& operator=(const var_wrapper&) = default;
13014  var_wrapper& operator=(var_wrapper&&) = default;
13015  };
13016 
13017  template <typename V>
13018  inline auto var(V&& v) {
13019  typedef meta::unqualified_t<V> T;
13020  return var_wrapper<T>(std::forward<V>(v));
13021  }
13022 
13023  namespace meta {
13024  template <typename T>
13025  struct is_member_object : std::is_member_object_pointer<T> {};
13026 
13027  template <typename T>
13028  struct is_member_object<readonly_wrapper<T>> : std::true_type {};
13029  } // namespace meta
13030 
13031 } // namespace sol
13032 
13033 // end of sol/property.hpp
13034 
13035 namespace sol {
13036  namespace usertype_detail {
13037 
13038  } // namespace usertype_detail
13039 
13040  namespace filter_detail {
13041  template <int I, int... In>
13042  inline void handle_filter(static_stack_dependencies<I, In...>, lua_State* L, int&) {
13043  if (sizeof...(In) == 0) {
13044  return;
13045  }
13046  absolute_index ai(L, I);
13047  if (type_of(L, ai) != type::userdata) {
13048  return;
13049  }
13050  lua_createtable(L, static_cast<int>(sizeof...(In)), 0);
13051  stack_reference deps(L, -1);
13052  auto per_dep = [&L, &deps](int i) {
13053  lua_pushvalue(L, i);
13054  luaL_ref(L, deps.stack_index());
13055  };
13056  (void)per_dep;
13057  (void)detail::swallow{ int(), (per_dep(In), int())... };
13058  lua_setuservalue(L, ai);
13059  }
13060 
13061  template <int... In>
13062  inline void handle_filter(returns_self_with<In...>, lua_State* L, int& pushed) {
13063  pushed = stack::push(L, raw_index(1));
13065  }
13066 
13067  inline void handle_filter(const stack_dependencies& sdeps, lua_State* L, int&) {
13068  absolute_index ai(L, sdeps.target);
13069  if (type_of(L, ai) != type::userdata) {
13070  return;
13071  }
13072  lua_createtable(L, static_cast<int>(sdeps.size()), 0);
13073  stack_reference deps(L, -1);
13074  for (std::size_t i = 0; i < sdeps.size(); ++i) {
13075  lua_pushvalue(L, sdeps.stack_indices[i]);
13076  luaL_ref(L, deps.stack_index());
13077  }
13078  lua_setuservalue(L, ai);
13079  }
13080 
13081  template <typename P, meta::disable<std::is_base_of<detail::filter_base_tag, meta::unqualified_t<P>>> = meta::enabler>
13082  inline void handle_filter(P&& p, lua_State* L, int& pushed) {
13083  pushed = std::forward<P>(p)(L, pushed);
13084  }
13085  } // namespace filter_detail
13086 
13087  namespace function_detail {
13088  inline int no_construction_error(lua_State* L) {
13089  return luaL_error(L, "sol: cannot call this constructor (tagged as non-constructible)");
13090  }
13091  } // namespace function_detail
13092 
13093  namespace call_detail {
13094 
13095  template <typename R, typename W>
13096  inline auto& pick(std::true_type, property_wrapper<R, W>& f) {
13097  return f.read;
13098  }
13099 
13100  template <typename R, typename W>
13101  inline auto& pick(std::false_type, property_wrapper<R, W>& f) {
13102  return f.write;
13103  }
13104 
13105  template <typename T, typename List>
13106  struct void_call : void_call<T, meta::function_args_t<List>> {};
13107 
13108  template <typename T, typename... Args>
13109  struct void_call<T, types<Args...>> {
13110  static void call(Args...) {
13111  }
13112  };
13113 
13114  template <typename T, bool checked, bool clean_stack>
13116  T* obj;
13117 
13119  : obj(o) {
13120  }
13121 
13122  template <typename Fx, std::size_t I, typename... R, typename... Args>
13123  int operator()(types<Fx>, index_value<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) const {
13125  return stack::call_into_lua<checked, clean_stack>(r, a, L, start, func, obj);
13126  }
13127  };
13128 
13129  namespace overload_detail {
13130  template <std::size_t... M, typename Match, typename... Args>
13131  inline int overload_match_arity(types<>, std::index_sequence<>, std::index_sequence<M...>, Match&&, lua_State* L, int, int, Args&&...) {
13132  return luaL_error(L, "sol: no matching function call takes this number of arguments and the specified types");
13133  }
13134 
13135  template <typename Fx, typename... Fxs, std::size_t I, std::size_t... In, std::size_t... M, typename Match, typename... Args>
13136  inline int overload_match_arity(types<Fx, Fxs...>, std::index_sequence<I, In...>, std::index_sequence<M...>, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
13139  typedef typename traits::free_args_list args_list;
13140  // compile-time eliminate any functions that we know ahead of time are of improper arity
13141  if (!traits::runtime_variadics_t::value && meta::find_in_pack_v<index_value<traits::free_arity>, index_value<M>...>::value) {
13142  return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13143  }
13144  if (!traits::runtime_variadics_t::value && traits::free_arity != fxarity) {
13145  return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<traits::free_arity, M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13146  }
13147  stack::record tracking{};
13148  if (!stack::stack_detail::check_types<true>{}.check(args_list(), L, start, no_panic, tracking)) {
13149  return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13150  }
13151  return matchfx(types<Fx>(), index_value<I>(), return_types(), args_list(), L, fxarity, start, std::forward<Args>(args)...);
13152  }
13153 
13154  template <std::size_t... M, typename Match, typename... Args>
13155  inline int overload_match_arity_single(types<>, std::index_sequence<>, std::index_sequence<M...>, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
13156  return overload_match_arity(types<>(), std::index_sequence<>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13157  }
13158 
13159  template <typename Fx, std::size_t I, std::size_t... M, typename Match, typename... Args>
13160  inline int overload_match_arity_single(types<Fx>, std::index_sequence<I>, std::index_sequence<M...>, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
13163  typedef typename traits::free_args_list args_list;
13164  // compile-time eliminate any functions that we know ahead of time are of improper arity
13165  if (!traits::runtime_variadics_t::value && meta::find_in_pack_v<index_value<traits::free_arity>, index_value<M>...>::value) {
13166  return overload_match_arity(types<>(), std::index_sequence<>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13167  }
13168  if (!traits::runtime_variadics_t::value && traits::free_arity != fxarity) {
13169  return overload_match_arity(types<>(), std::index_sequence<>(), std::index_sequence<traits::free_arity, M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13170  }
13171  return matchfx(types<Fx>(), index_value<I>(), return_types(), args_list(), L, fxarity, start, std::forward<Args>(args)...);
13172  }
13173 
13174  template <typename Fx, typename Fx1, typename... Fxs, std::size_t I, std::size_t I1, std::size_t... In, std::size_t... M, typename Match, typename... Args>
13175  inline int overload_match_arity_single(types<Fx, Fx1, Fxs...>, std::index_sequence<I, I1, In...>, std::index_sequence<M...>, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
13178  typedef typename traits::free_args_list args_list;
13179  // compile-time eliminate any functions that we know ahead of time are of improper arity
13180  if (!traits::runtime_variadics_t::value && meta::find_in_pack_v<index_value<traits::free_arity>, index_value<M>...>::value) {
13181  return overload_match_arity(types<Fx1, Fxs...>(), std::index_sequence<I1, In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13182  }
13183  if (!traits::runtime_variadics_t::value && traits::free_arity != fxarity) {
13184  return overload_match_arity(types<Fx1, Fxs...>(), std::index_sequence<I1, In...>(), std::index_sequence<traits::free_arity, M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13185  }
13186  stack::record tracking{};
13187  if (!stack::stack_detail::check_types<true>{}.check(args_list(), L, start, no_panic, tracking)) {
13188  return overload_match_arity(types<Fx1, Fxs...>(), std::index_sequence<I1, In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13189  }
13190  return matchfx(types<Fx>(), index_value<I>(), return_types(), args_list(), L, fxarity, start, std::forward<Args>(args)...);
13191  }
13192  } // namespace overload_detail
13193 
13194  template <typename... Functions, typename Match, typename... Args>
13195  inline int overload_match_arity(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
13196  return overload_detail::overload_match_arity_single(types<Functions...>(), std::make_index_sequence<sizeof...(Functions)>(), std::index_sequence<>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13197  }
13198 
13199  template <typename... Functions, typename Match, typename... Args>
13200  inline int overload_match(Match&& matchfx, lua_State* L, int start, Args&&... args) {
13201  int fxarity = lua_gettop(L) - (start - 1);
13202  return overload_match_arity<Functions...>(std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13203  }
13204 
13205  template <typename T, typename... TypeLists, typename Match, typename... Args>
13206  inline int construct_match(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
13207  // use same overload resolution matching as all other parts of the framework
13208  return overload_match_arity<decltype(void_call<T, TypeLists>::call)...>(std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
13209  }
13210 
13211  template <typename T, bool checked, bool clean_stack, typename... TypeLists>
13212  inline int construct_trampolined(lua_State* L) {
13213  static const auto& meta = usertype_traits<T>::metatable();
13214  int argcount = lua_gettop(L);
13216  argcount -= static_cast<int>(syntax);
13217 
13218  T* obj = detail::usertype_allocate<T>(L);
13219  reference userdataref(L, -1);
13220  userdataref.pop();
13221 
13222  construct_match<T, TypeLists...>(constructor_match<T, checked, clean_stack>(obj), L, argcount, 1 + static_cast<int>(syntax));
13223 
13224  userdataref.push();
13226  umf();
13227 
13228  return 1;
13229  }
13230 
13231  template <typename T, bool checked, bool clean_stack, typename... TypeLists>
13232  inline int construct(lua_State* L) {
13233  return detail::static_trampoline<&construct_trampolined<T, checked, clean_stack, TypeLists...>>(L);
13234  }
13235 
13236  template <typename F, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename = void>
13239 
13240  template <typename Fx, typename... Args>
13241  static int convertible_call(std::true_type, lua_State* L, Fx&& f, Args&&... args) {
13242  typedef typename wrap::traits_type traits_type;
13243  typedef typename traits_type::function_pointer_type fp_t;
13244  fp_t fx = f;
13246  }
13247 
13248  template <typename Fx, typename... Args>
13249  static int convertible_call(std::false_type, lua_State* L, Fx&& f, Args&&... args) {
13250  typedef typename wrap::returns_list returns_list;
13251  typedef typename wrap::free_args_list args_list;
13252  typedef typename wrap::caller caller;
13253  return stack::call_into_lua<checked, clean_stack>(returns_list(), args_list(), L, boost + 1, caller(), std::forward<Fx>(f), std::forward<Args>(args)...);
13254  }
13255 
13256  template <typename Fx, typename... Args>
13257  static int call(lua_State* L, Fx&& f, Args&&... args) {
13258  typedef typename wrap::traits_type traits_type;
13259  typedef typename traits_type::function_pointer_type fp_t;
13260  return convertible_call(std::conditional_t<std::is_class<meta::unqualified_t<F>>::value, std::is_convertible<std::decay_t<Fx>, fp_t>, std::false_type>(), L, std::forward<Fx>(f), std::forward<Args>(args)...);
13261  }
13262  };
13263 
13264  template <typename T, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13265  struct agnostic_lua_call_wrapper<var_wrapper<T>, true, is_variable, checked, boost, clean_stack, C> {
13266  template <typename F>
13267  static int call(lua_State* L, F&& f) {
13268  typedef is_stack_based<meta::unqualified_t<decltype(detail::unwrap(f.value))>> is_stack;
13269  if (clean_stack && !is_stack::value) {
13270  lua_settop(L, 0);
13271  }
13272  return stack::push_reference(L, detail::unwrap(f.value));
13273  }
13274  };
13275 
13276  template <typename T, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13277  struct agnostic_lua_call_wrapper<var_wrapper<T>, false, is_variable, checked, boost, clean_stack, C> {
13278  template <typename V>
13279  static int call_assign(std::true_type, lua_State* L, V&& f) {
13280  detail::unwrap(f.value) = stack::unqualified_get<meta::unwrapped_t<T>>(L, boost + (is_variable ? 3 : 1));
13281  if (clean_stack) {
13282  lua_settop(L, 0);
13283  }
13284  return 0;
13285  }
13286 
13287  template <typename... Args>
13288  static int call_assign(std::false_type, lua_State* L, Args&&...) {
13289  return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available");
13290  }
13291 
13292  template <typename... Args>
13293  static int call_const(std::false_type, lua_State* L, Args&&... args) {
13294  typedef meta::unwrapped_t<T> R;
13295  return call_assign(std::is_assignable<std::add_lvalue_reference_t<meta::unqualified_t<R>>, R>(), L, std::forward<Args>(args)...);
13296  }
13297 
13298  template <typename... Args>
13299  static int call_const(std::true_type, lua_State* L, Args&&...) {
13300  return luaL_error(L, "sol: cannot write to a readonly (const) variable");
13301  }
13302 
13303  template <typename V>
13304  static int call(lua_State* L, V&& f) {
13305  return call_const(std::is_const<meta::unwrapped_t<T>>(), L, f);
13306  }
13307  };
13308 
13309  template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13310  struct agnostic_lua_call_wrapper<lua_CFunction_ref, is_index, is_variable, checked, boost, clean_stack, C> {
13311  static int call(lua_State* L, lua_CFunction_ref f) {
13312  return f(L);
13313  }
13314  };
13315 
13316  template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13317  struct agnostic_lua_call_wrapper<lua_CFunction, is_index, is_variable, checked, boost, clean_stack, C> {
13318  static int call(lua_State* L, lua_CFunction f) {
13319  return f(L);
13320  }
13321  };
13322 
13323 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
13324  template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13325  struct agnostic_lua_call_wrapper<detail::lua_CFunction_noexcept, is_index, is_variable, checked, boost, clean_stack, C> {
13326  static int call(lua_State* L, detail::lua_CFunction_noexcept f) {
13327  return f(L);
13328  }
13329  };
13330 #endif // noexcept function types
13331 
13332  template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13333  struct agnostic_lua_call_wrapper<no_prop, is_index, is_variable, checked, boost, clean_stack, C> {
13334  static int call(lua_State* L, const no_prop&) {
13335  return luaL_error(L, is_index ? "sol: cannot read from a writeonly property" : "sol: cannot write to a readonly property");
13336  }
13337  };
13338 
13339  template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13340  struct agnostic_lua_call_wrapper<no_construction, is_index, is_variable, checked, boost, clean_stack, C> {
13341  static int call(lua_State* L, const no_construction&) {
13343  }
13344  };
13345 
13346  template <typename... Args, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13347  struct agnostic_lua_call_wrapper<bases<Args...>, is_index, is_variable, checked, boost, clean_stack, C> {
13348  static int call(lua_State*, const bases<Args...>&) {
13349  // Uh. How did you even call this, lul
13350  return 0;
13351  }
13352  };
13353 
13354  template <typename T, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13355  struct agnostic_lua_call_wrapper<std::reference_wrapper<T>, is_index, is_variable, checked, boost, clean_stack, C> {
13356  static int call(lua_State* L, std::reference_wrapper<T> f) {
13358  }
13359  };
13360 
13361  template <typename T, typename F, bool is_index, bool is_variable, bool checked = detail::default_safe_function_calls, int boost = 0, bool clean_stack = true, typename = void>
13362  struct lua_call_wrapper : agnostic_lua_call_wrapper<F, is_index, is_variable, checked, boost, clean_stack> {};
13363 
13364  template <typename T, typename F, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack>
13365  struct lua_call_wrapper<T, F, is_index, is_variable, checked, boost, clean_stack, std::enable_if_t<std::is_member_function_pointer<F>::value>> {
13367  typedef typename wrap::object_type object_type;
13368 
13369  template <typename Fx>
13370  static int call(lua_State* L, Fx&& f, object_type& o) {
13371  typedef typename wrap::returns_list returns_list;
13372  typedef typename wrap::args_list args_list;
13373  typedef typename wrap::caller caller;
13374  return stack::call_into_lua<checked, clean_stack>(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), std::forward<Fx>(f), o);
13375  }
13376 
13377  template <typename Fx>
13378  static int call(lua_State* L, Fx&& f) {
13379  typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
13380 #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
13381  auto maybeo = stack::unqualified_check_get<Ta*>(L, 1);
13382  if (!maybeo || maybeo.value() == nullptr) {
13383  return luaL_error(L, "sol: received nil for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)");
13384  }
13385  object_type* o = static_cast<object_type*>(maybeo.value());
13386  return call(L, std::forward<Fx>(f), *o);
13387 #else
13388  object_type& o = static_cast<object_type&>(*stack::unqualified_get<non_null<Ta*>>(L, 1));
13389  return call(L, std::forward<Fx>(f), o);
13390 #endif // Safety
13391  }
13392  };
13393 
13394  template <typename T, typename F, bool is_variable, bool checked, int boost, bool clean_stack>
13395  struct lua_call_wrapper<T, F, false, is_variable, checked, boost, clean_stack, std::enable_if_t<std::is_member_object_pointer<F>::value>> {
13398  typedef typename wrap::object_type object_type;
13399 
13400  template <typename V>
13401  static int call_assign(std::true_type, lua_State* L, V&& f, object_type& o) {
13402  typedef typename wrap::args_list args_list;
13403  typedef typename wrap::caller caller;
13404  return stack::call_into_lua<checked, clean_stack>(types<void>(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, o);
13405  }
13406 
13407  template <typename V>
13408  static int call_assign(std::true_type, lua_State* L, V&& f) {
13409  typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
13410 #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
13411  auto maybeo = stack::check_get<Ta*>(L, 1);
13412  if (!maybeo || maybeo.value() == nullptr) {
13413  if (is_variable) {
13414  return luaL_error(L, "sol: received nil for 'self' argument (bad '.' access?)");
13415  }
13416  return luaL_error(L, "sol: received nil for 'self' argument (pass 'self' as first argument)");
13417  }
13418  object_type* o = static_cast<object_type*>(maybeo.value());
13419  return call_assign(std::true_type(), L, f, *o);
13420 #else
13421  object_type& o = static_cast<object_type&>(*stack::get<non_null<Ta*>>(L, 1));
13422  return call_assign(std::true_type(), L, f, o);
13423 #endif // Safety
13424  }
13425 
13426  template <typename... Args>
13427  static int call_assign(std::false_type, lua_State* L, Args&&...) {
13428  return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available");
13429  }
13430 
13431  template <typename... Args>
13432  static int call_const(std::false_type, lua_State* L, Args&&... args) {
13433  typedef typename traits_type::return_type R;
13434  return call_assign(std::is_copy_assignable<meta::unqualified_t<R>>(), L, std::forward<Args>(args)...);
13435  }
13436 
13437  template <typename... Args>
13438  static int call_const(std::true_type, lua_State* L, Args&&...) {
13439  return luaL_error(L, "sol: cannot write to a readonly (const) variable");
13440  }
13441 
13442  template <typename V>
13443  static int call(lua_State* L, V&& f) {
13444  return call_const(std::is_const<typename traits_type::return_type>(), L, std::forward<V>(f));
13445  }
13446 
13447  template <typename V>
13448  static int call(lua_State* L, V&& f, object_type& o) {
13449  return call_const(std::is_const<typename traits_type::return_type>(), L, std::forward<V>(f), o);
13450  }
13451  };
13452 
13453  template <typename T, typename F, bool is_variable, bool checked, int boost, bool clean_stack>
13454  struct lua_call_wrapper<T, F, true, is_variable, checked, boost, clean_stack, std::enable_if_t<std::is_member_object_pointer<F>::value>> {
13457  typedef typename wrap::object_type object_type;
13458 
13459  template <typename V>
13460  static int call(lua_State* L, V&& v, object_type& o) {
13461  typedef typename wrap::returns_list returns_list;
13462  typedef typename wrap::caller caller;
13463  F f(std::forward<V>(v));
13464  return stack::call_into_lua<checked, clean_stack>(returns_list(), types<>(), L, boost + (is_variable ? 3 : 2), caller(), f, o);
13465  }
13466 
13467  template <typename V>
13468  static int call(lua_State* L, V&& f) {
13469  typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
13470 #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
13471  auto maybeo = stack::check_get<Ta*>(L, 1);
13472  if (!maybeo || maybeo.value() == nullptr) {
13473  if (is_variable) {
13474  return luaL_error(L, "sol: 'self' argument is lua_nil (bad '.' access?)");
13475  }
13476  return luaL_error(L, "sol: 'self' argument is lua_nil (pass 'self' as first argument)");
13477  }
13478  object_type* o = static_cast<object_type*>(maybeo.value());
13479  return call(L, f, *o);
13480 #else
13481  object_type& o = static_cast<object_type&>(*stack::get<non_null<Ta*>>(L, 1));
13482  return call(L, f, o);
13483 #endif // Safety
13484  }
13485  };
13486 
13487  template <typename T, typename F, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13488  struct lua_call_wrapper<T, readonly_wrapper<F>, false, is_variable, checked, boost, clean_stack, C> {
13491  typedef typename wrap::object_type object_type;
13492 
13493  template <typename V>
13494  static int call(lua_State* L, V&&) {
13495  return luaL_error(L, "sol: cannot write to a sol::readonly variable");
13496  }
13497 
13498  template <typename V>
13499  static int call(lua_State* L, V&&, object_type&) {
13500  return luaL_error(L, "sol: cannot write to a sol::readonly variable");
13501  }
13502  };
13503 
13504  template <typename T, typename F, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13505  struct lua_call_wrapper<T, readonly_wrapper<F>, true, is_variable, checked, boost, clean_stack, C> : lua_call_wrapper<T, F, true, is_variable, checked, boost, clean_stack, C> {
13506  };
13507 
13508  template <typename T, typename... Args, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13509  struct lua_call_wrapper<T, constructor_list<Args...>, is_index, is_variable, checked, boost, clean_stack, C> {
13510  typedef constructor_list<Args...> F;
13511 
13512  static int call(lua_State* L, F&) {
13513  const auto& meta = usertype_traits<T>::metatable();
13514  int argcount = lua_gettop(L);
13516  argcount -= static_cast<int>(syntax);
13517 
13518  T* obj = detail::usertype_allocate<T>(L);
13519  reference userdataref(L, -1);
13520 
13521  construct_match<T, Args...>(constructor_match<T, false, clean_stack>(obj), L, argcount, boost + 1 + static_cast<int>(syntax));
13522 
13523  userdataref.push();
13525  umf();
13526 
13527  return 1;
13528  }
13529  };
13530 
13531  template <typename T, typename... Cxs, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13532  struct lua_call_wrapper<T, constructor_wrapper<Cxs...>, is_index, is_variable, checked, boost, clean_stack, C> {
13533  typedef constructor_wrapper<Cxs...> F;
13534 
13535  struct onmatch {
13536  template <typename Fx, std::size_t I, typename... R, typename... Args>
13537  int operator()(types<Fx>, index_value<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start, F& f) {
13538  const auto& meta = usertype_traits<T>::metatable();
13539  T* obj = detail::usertype_allocate<T>(L);
13540  reference userdataref(L, -1);
13541 
13542  auto& func = std::get<I>(f.functions);
13543  stack::call_into_lua<checked, clean_stack>(r, a, L, boost + start, func, detail::implicit_wrapper<T>(obj));
13544 
13545  userdataref.push();
13547  umf();
13548 
13549  return 1;
13550  }
13551  };
13552 
13553  static int call(lua_State* L, F& f) {
13555  int syntaxval = static_cast<int>(syntax);
13556  int argcount = lua_gettop(L) - syntaxval;
13557  return construct_match<T, meta::pop_front_type_t<meta::function_args_t<Cxs>>...>(onmatch(), L, argcount, 1 + syntaxval, f);
13558  }
13559  };
13560 
13561  template <typename T, typename Fx, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack>
13562  struct lua_call_wrapper<T, destructor_wrapper<Fx>, is_index, is_variable, checked, boost, clean_stack, std::enable_if_t<std::is_void<Fx>::value>> {
13564 
13565  static int call(lua_State* L, const F&) {
13566  return detail::usertype_alloc_destruct<T>(L);
13567  }
13568  };
13569 
13570  template <typename T, typename Fx, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack>
13571  struct lua_call_wrapper<T, destructor_wrapper<Fx>, is_index, is_variable, checked, boost, clean_stack, std::enable_if_t<!std::is_void<Fx>::value>> {
13573 
13574  static int call_void(std::true_type, lua_State* L, const F& f) {
13575  typedef meta::bind_traits<meta::unqualified_t<decltype(f.fx)>> bt;
13576  typedef typename bt::template arg_at<0> arg0;
13577  typedef meta::unqualified_t<arg0> O;
13578 
13579  O& obj = stack::get<O>(L);
13581  return 0;
13582  }
13583 
13584  static int call_void(std::false_type, lua_State* L, const F& f) {
13585  T& obj = stack::get<T>(L);
13587  return 0;
13588  }
13589 
13590  static int call(lua_State* L, const F& f) {
13591  return call_void(std::is_void<T>(), L, f);
13592  }
13593  };
13594 
13595  template <typename T, typename... Fs, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13596  struct lua_call_wrapper<T, overload_set<Fs...>, is_index, is_variable, checked, boost, clean_stack, C> {
13597  typedef overload_set<Fs...> F;
13598 
13599  struct on_match {
13600  template <typename Fx, std::size_t I, typename... R, typename... Args>
13601  int operator()(types<Fx>, index_value<I>, types<R...>, types<Args...>, lua_State* L, int, int, F& fx) {
13602  auto& f = std::get<I>(fx.functions);
13604  }
13605  };
13606 
13607  static int call(lua_State* L, F& fx) {
13608  return overload_match_arity<Fs...>(on_match(), L, lua_gettop(L), 1, fx);
13609  }
13610  };
13611 
13612  template <typename T, typename... Fs, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13613  struct lua_call_wrapper<T, factory_wrapper<Fs...>, is_index, is_variable, checked, boost, clean_stack, C> {
13614  typedef factory_wrapper<Fs...> F;
13615 
13616  struct on_match {
13617  template <typename Fx, std::size_t I, typename... R, typename... Args>
13618  int operator()(types<Fx>, index_value<I>, types<R...>, types<Args...>, lua_State* L, int, int, F& fx) {
13619  auto& f = std::get<I>(fx.functions);
13621  }
13622  };
13623 
13624  static int call(lua_State* L, F& fx) {
13625  return overload_match_arity<Fs...>(on_match(), L, lua_gettop(L) - boost, 1 + boost, fx);
13626  }
13627  };
13628 
13629  template <typename T, typename R, typename W, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13630  struct lua_call_wrapper<T, property_wrapper<R, W>, is_index, is_variable, checked, boost, clean_stack, C> {
13631  typedef std::conditional_t<is_index, R, W> P;
13633  typedef wrapper<U> wrap;
13636 
13637  template <typename F>
13638  static int self_call(std::true_type, lua_State* L, F&& f) {
13639  // The type being void means we don't have any arguments, so it might be a free functions?
13640  typedef typename traits_type::free_args_list args_list;
13641  typedef typename wrap::returns_list returns_list;
13642  typedef typename wrap::caller caller;
13643  return stack::call_into_lua<checked, clean_stack>(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f);
13644  }
13645 
13646  template <typename F>
13647  static int self_call(std::false_type, lua_State* L, F&& f) {
13649  typedef T Ta;
13650  typedef std::remove_pointer_t<object_type> Oa;
13651 #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
13652  auto maybeo = stack::check_get<Ta*>(L, 1);
13653  if (!maybeo || maybeo.value() == nullptr) {
13654  if (is_variable) {
13655  return luaL_error(L, "sol: 'self' argument is lua_nil (bad '.' access?)");
13656  }
13657  return luaL_error(L, "sol: 'self' argument is lua_nil (pass 'self' as first argument)");
13658  }
13659  Oa* o = static_cast<Oa*>(maybeo.value());
13660 #else
13661  Oa* o = static_cast<Oa*>(stack::get<non_null<Ta*>>(L, 1));
13662 #endif // Safety
13663  typedef typename wrap::returns_list returns_list;
13664  typedef typename wrap::caller caller;
13665  return stack::call_into_lua<checked, clean_stack>(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, detail::implicit_wrapper<Oa>(*o));
13666  }
13667 
13668  template <typename F, typename... Args>
13669  static int defer_call(std::false_type, lua_State* L, F&& f, Args&&... args) {
13670  return self_call(meta::any<std::is_void<object_type>, meta::boolean<lua_type_of<meta::unwrap_unqualified_t<object_type>>::value != type::userdata>>(), L, pick(meta::boolean<is_index>(), f), std::forward<Args>(args)...);
13671  }
13672 
13673  template <typename F, typename... Args>
13674  static int defer_call(std::true_type, lua_State* L, F&& f, Args&&... args) {
13675  auto& p = pick(meta::boolean<is_index>(), std::forward<F>(f));
13676  return lua_call_wrapper<T, meta::unqualified_t<decltype(p)>, is_index, is_variable, checked, boost, clean_stack>{}.call(L, p, std::forward<Args>(args)...);
13677  }
13678 
13679  template <typename F, typename... Args>
13680  static int call(lua_State* L, F&& f, Args&&... args) {
13681  typedef meta::any<
13682  std::is_void<U>,
13683  std::is_same<U, no_prop>,
13687  std::is_member_pointer<U>>
13688  is_specialized;
13689  return defer_call(is_specialized(), L, std::forward<F>(f), std::forward<Args>(args)...);
13690  }
13691  };
13692 
13693  template <typename T, typename V, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13694  struct lua_call_wrapper<T, protect_t<V>, is_index, is_variable, checked, boost, clean_stack, C> {
13695  typedef protect_t<V> F;
13696 
13697  template <typename... Args>
13698  static int call(lua_State* L, F& fx, Args&&... args) {
13699  return lua_call_wrapper<T, V, is_index, is_variable, true, boost, clean_stack>{}.call(L, fx.value, std::forward<Args>(args)...);
13700  }
13701  };
13702 
13703  template <typename T, typename F, typename... Filters, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13704  struct lua_call_wrapper<T, filter_wrapper<F, Filters...>, is_index, is_variable, checked, boost, clean_stack, C> {
13705  typedef filter_wrapper<F, Filters...> P;
13706 
13707  template <std::size_t... In>
13708  static int call(std::index_sequence<In...>, lua_State* L, P& fx) {
13710  (void)detail::swallow{ int(), (filter_detail::handle_filter(std::get<In>(fx.filters), L, pushed), int())... };
13711  return pushed;
13712  }
13713 
13714  static int call(lua_State* L, P& fx) {
13715  typedef typename P::indices indices;
13716  return call(indices(), L, fx);
13717  }
13718  };
13719 
13720  template <typename T, typename Sig, typename P, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
13721  struct lua_call_wrapper<T, function_arguments<Sig, P>, is_index, is_variable, checked, boost, clean_stack, C> {
13722  template <typename F>
13723  static int call(lua_State* L, F&& f) {
13724  return lua_call_wrapper<T, meta::unqualified_t<P>, is_index, is_variable, checked, boost, clean_stack>{}.call(L, std::get<0>(f.arguments));
13725  }
13726  };
13727 
13728  template <typename T, bool is_index, bool is_variable, int boost = 0, bool checked = detail::default_safe_function_calls, bool clean_stack = true, typename Fx, typename... Args>
13729  inline int call_wrapped(lua_State* L, Fx&& fx, Args&&... args) {
13730  return lua_call_wrapper<T, meta::unqualified_t<Fx>, is_index, is_variable, checked, boost, clean_stack>{}.call(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
13731  }
13732 
13733  template <typename T, bool is_index, bool is_variable, typename F, int start = 1, bool checked = detail::default_safe_function_calls, bool clean_stack = true>
13734  inline int call_user(lua_State* L) {
13735  auto& fx = stack::unqualified_get<user<F>>(L, upvalue_index(start));
13736  return call_wrapped<T, is_index, is_variable, 0, checked, clean_stack>(L, fx);
13737  }
13738 
13739  template <typename T, typename = void>
13740  struct is_var_bind : std::false_type {};
13741 
13742  template <typename T>
13743  struct is_var_bind<T, std::enable_if_t<std::is_member_object_pointer<T>::value>> : std::true_type {};
13744 
13745  template <>
13746  struct is_var_bind<no_prop> : std::true_type {};
13747 
13748  template <typename R, typename W>
13749  struct is_var_bind<property_wrapper<R, W>> : std::true_type {};
13750 
13751  template <typename T>
13752  struct is_var_bind<var_wrapper<T>> : std::true_type {};
13753 
13754  template <typename T>
13755  struct is_var_bind<readonly_wrapper<T>> : is_var_bind<meta::unqualified_t<T>> {};
13756 
13757  template <typename F, typename... Filters>
13758  struct is_var_bind<filter_wrapper<F, Filters...>> : is_var_bind<meta::unqualified_t<F>> {};
13759  } // namespace call_detail
13760 
13761  template <typename T>
13762  struct is_variable_binding : call_detail::is_var_bind<meta::unqualified_t<T>> {};
13763 
13764  template <typename T>
13765  struct is_function_binding : meta::neg<is_variable_binding<T>> {};
13766 
13767 } // namespace sol
13768 
13769 // end of sol/call.hpp
13770 
13771 namespace sol {
13772  namespace function_detail {
13773  template <typename F, F fx>
13774  inline int call_wrapper_variable(std::false_type, lua_State* L) {
13775  typedef meta::bind_traits<meta::unqualified_t<F>> traits_type;
13776  typedef typename traits_type::args_list args_list;
13778  return stack::call_into_lua(return_type(), args_list(), L, 1, fx);
13779  }
13780 
13781  template <typename R, typename V, V, typename T>
13782  inline int call_set_assignable(std::false_type, T&&, lua_State* L) {
13783  return luaL_error(L, "cannot write to this type: copy assignment/constructor not available");
13784  }
13785 
13786  template <typename R, typename V, V variable, typename T>
13787  inline int call_set_assignable(std::true_type, lua_State* L, T&& mem) {
13788  (mem.*variable) = stack::get<R>(L, 2);
13789  return 0;
13790  }
13791 
13792  template <typename R, typename V, V, typename T>
13793  inline int call_set_variable(std::false_type, lua_State* L, T&&) {
13794  return luaL_error(L, "cannot write to a const variable");
13795  }
13796 
13797  template <typename R, typename V, V variable, typename T>
13798  inline int call_set_variable(std::true_type, lua_State* L, T&& mem) {
13799  return call_set_assignable<R, V, variable>(std::is_assignable<std::add_lvalue_reference_t<R>, R>(), L, std::forward<T>(mem));
13800  }
13801 
13802  template <typename V, V variable>
13803  inline int call_wrapper_variable(std::true_type, lua_State* L) {
13804  typedef meta::bind_traits<meta::unqualified_t<V>> traits_type;
13805  typedef typename traits_type::object_type T;
13806  typedef typename traits_type::return_type R;
13807  auto& mem = stack::get<T>(L, 1);
13808  switch (lua_gettop(L)) {
13809  case 1: {
13810  decltype(auto) r = (mem.*variable);
13811  stack::push_reference(L, std::forward<decltype(r)>(r));
13812  return 1;
13813  }
13814  case 2:
13815  return call_set_variable<R, V, variable>(meta::neg<std::is_const<R>>(), L, mem);
13816  default:
13817  return luaL_error(L, "incorrect number of arguments to member variable function call");
13818  }
13819  }
13820 
13821  template <typename F, F fx>
13822  inline int call_wrapper_function(std::false_type, lua_State* L) {
13823  return call_wrapper_variable<F, fx>(std::is_member_object_pointer<F>(), L);
13824  }
13825 
13826  template <typename F, F fx>
13827  inline int call_wrapper_function(std::true_type, lua_State* L) {
13828  return call_detail::call_wrapped<void, false, false>(L, fx);
13829  }
13830 
13831  template <typename F, F fx>
13833  return call_wrapper_function<F, fx>(std::is_member_function_pointer<meta::unqualified_t<F>>(), L);
13834  }
13835 
13836  template <typename... Fxs>
13838  template <typename Fx, std::size_t I, typename R, typename... Args>
13839  int operator()(types<Fx>, index_value<I>, types<R>, types<Args...>, lua_State* L, int, int) const {
13840  typedef meta::at_in_pack_t<I, Fxs...> target;
13841  return target::call(L);
13842  }
13843  };
13844 
13845  template <typename F, F fx>
13846  inline int c_call_raw(std::true_type, lua_State* L) {
13847  return fx(L);
13848  }
13849 
13850  template <typename F, F fx>
13851  inline int c_call_raw(std::false_type, lua_State* L) {
13852 #ifdef __clang__
13853  return detail::trampoline(L, function_detail::call_wrapper_entry<F, fx>);
13854 #else
13855  return detail::typed_static_trampoline<decltype(&function_detail::call_wrapper_entry<F, fx>), (&function_detail::call_wrapper_entry<F, fx>)>(L);
13856 #endif // fuck you clang :c
13857  }
13858 
13859  } // namespace function_detail
13860 
13861  template <typename F, F fx>
13862  inline int c_call(lua_State* L) {
13863  typedef meta::unqualified_t<F> Fu;
13864  typedef std::integral_constant<bool, std::is_same<Fu, lua_CFunction>::value
13865 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
13866  || std::is_same<Fu, detail::lua_CFunction_noexcept>::value
13867 #endif
13868  > is_raw;
13869  return function_detail::c_call_raw<F, fx>(is_raw(), L);
13870  }
13871 
13872  template <typename F, F f>
13873  struct wrap {
13874  typedef F type;
13875 
13876  static int call(lua_State* L) {
13877  return c_call<type, f>(L);
13878  }
13879  };
13880 
13881  template <typename... Fxs>
13882  inline int c_call(lua_State* L) {
13883  if (sizeof...(Fxs) < 2) {
13885  }
13886  else {
13887  return call_detail::overload_match_arity<typename Fxs::type...>(function_detail::c_call_matcher<Fxs...>(), L, lua_gettop(L), 1);
13888  }
13889  }
13890 
13891 } // namespace sol
13892 
13893 // end of sol/function_types_templated.hpp
13894 
13895 // beginning of sol/function_types_stateless.hpp
13896 
13897 namespace sol {
13898 namespace function_detail {
13899  template <typename Function, bool is_yielding>
13901  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
13903 
13904  static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) {
13905  auto udata = stack::stack_detail::get_as_upvalues<function_type*>(L);
13906  function_type* fx = udata.first;
13907  return call_detail::call_wrapped<void, true, false>(L, fx);
13908  }
13909 
13910  static int call(lua_State* L) {
13911  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
13912  if (is_yielding) {
13913  return lua_yield(L, nr);
13914  }
13915  else {
13916  return nr;
13917  }
13918  }
13919 
13920  int operator()(lua_State* L) {
13921  return call(L);
13922  }
13923  };
13924 
13925  template <typename T, typename Function, bool is_yielding>
13927  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
13929 
13930  static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) {
13931  // Layout:
13932  // idx 1...n: verbatim data of member function pointer
13933  // idx n + 1: is the object's void pointer
13934  // We don't need to store the size, because the other side is templated
13935  // with the same member function pointer type
13936  auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
13937  auto objdata = stack::stack_detail::get_as_upvalues<T*>(L, memberdata.second);
13938  function_type& memfx = memberdata.first;
13939  auto& item = *objdata.first;
13940  return call_detail::call_wrapped<T, true, false, -1>(L, memfx, item);
13941  }
13942 
13943  static int call(lua_State* L) {
13944  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
13945  if (is_yielding) {
13946  return lua_yield(L, nr);
13947  }
13948  else {
13949  return nr;
13950  }
13951  }
13952 
13953  int operator()(lua_State* L) {
13954  return call(L);
13955  }
13956  };
13957 
13958  template <typename T, typename Function, bool is_yielding>
13960  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
13962 
13963  static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) {
13964  // Layout:
13965  // idx 1...n: verbatim data of member variable pointer
13966  // idx n + 1: is the object's void pointer
13967  // We don't need to store the size, because the other side is templated
13968  // with the same member function pointer type
13969  auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
13970  auto objdata = stack::stack_detail::get_as_upvalues<T*>(L, memberdata.second);
13971  auto& mem = *objdata.first;
13972  function_type& var = memberdata.first;
13973  switch (lua_gettop(L)) {
13974  case 0:
13975  return call_detail::call_wrapped<T, true, false, -1>(L, var, mem);
13976  case 1:
13977  return call_detail::call_wrapped<T, false, false, -1>(L, var, mem);
13978  default:
13979  return luaL_error(L, "sol: incorrect number of arguments to member variable function");
13980  }
13981  }
13982 
13983  static int call(lua_State* L) {
13984  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
13985  if (is_yielding) {
13986  return lua_yield(L, nr);
13987  }
13988  else {
13989  return nr;
13990  }
13991  }
13992 
13993  int operator()(lua_State* L) {
13994  return call(L);
13995  }
13996  };
13997 
13998  template <typename T, typename Function, bool is_yielding>
13999  struct upvalue_member_variable<T, readonly_wrapper<Function>, is_yielding> {
14000  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
14002 
14003  static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) {
14004  // Layout:
14005  // idx 1...n: verbatim data of member variable pointer
14006  // idx n + 1: is the object's void pointer
14007  // We don't need to store the size, because the other side is templated
14008  // with the same member function pointer type
14009  auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
14010  auto objdata = stack::stack_detail::get_as_upvalues<T*>(L, memberdata.second);
14011  auto& mem = *objdata.first;
14012  function_type& var = memberdata.first;
14013  switch (lua_gettop(L)) {
14014  case 0:
14015  return call_detail::call_wrapped<T, true, false, -1>(L, var, mem);
14016  default:
14017  return luaL_error(L, "sol: incorrect number of arguments to member variable function");
14018  }
14019  }
14020 
14021  static int call(lua_State* L) {
14022  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
14023  if (is_yielding) {
14024  return lua_yield(L, nr);
14025  }
14026  else {
14027  return nr;
14028  }
14029  }
14030 
14031  int operator()(lua_State* L) {
14032  return call(L);
14033  }
14034  };
14035 
14036  template <typename T, typename Function, bool is_yielding>
14038  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
14040 
14041  static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) {
14042  // Layout:
14043  // idx 1...n: verbatim data of member variable pointer
14044  auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
14045  function_type& memfx = memberdata.first;
14046  return call_detail::call_wrapped<T, false, false>(L, memfx);
14047  }
14048 
14049  static int call(lua_State* L) {
14050  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
14051  if (is_yielding) {
14052  return lua_yield(L, nr);
14053  }
14054  else {
14055  return nr;
14056  }
14057  }
14058 
14059  int operator()(lua_State* L) {
14060  return call(L);
14061  }
14062  };
14063 
14064  template <typename T, typename Function, bool is_yielding>
14066  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
14067 
14068  static int real_call(lua_State* L) noexcept(false) {
14069  // Layout:
14070  // idx 1...n: verbatim data of member variable pointer
14071  auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
14072  function_type& var = memberdata.first;
14073  switch (lua_gettop(L)) {
14074  case 1:
14075  return call_detail::call_wrapped<T, true, false>(L, var);
14076  case 2:
14077  return call_detail::call_wrapped<T, false, false>(L, var);
14078  default:
14079  return luaL_error(L, "sol: incorrect number of arguments to member variable function");
14080  }
14081  }
14082 
14083  static int call(lua_State* L) {
14084  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
14085  if (is_yielding) {
14086  return lua_yield(L, nr);
14087  }
14088  else {
14089  return nr;
14090  }
14091  }
14092 
14093  int operator()(lua_State* L) {
14094  return call(L);
14095  }
14096  };
14097 
14098  template <typename T, typename Function, bool is_yielding>
14099  struct upvalue_this_member_variable<T, readonly_wrapper<Function>, is_yielding> {
14100  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
14102 
14103  static int real_call(lua_State* L) noexcept(false) {
14104  // Layout:
14105  // idx 1...n: verbatim data of member variable pointer
14106  auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
14107  function_type& var = memberdata.first;
14108  switch (lua_gettop(L)) {
14109  case 1:
14110  return call_detail::call_wrapped<T, true, false>(L, var);
14111  default:
14112  return luaL_error(L, "sol: incorrect number of arguments to member variable function");
14113  }
14114  }
14115 
14116  static int call(lua_State* L) {
14117  int nr = detail::typed_static_trampoline<decltype(&real_call), (&real_call)>(L);
14118  if (is_yielding) {
14119  return lua_yield(L, nr);
14120  }
14121  else {
14122  return nr;
14123  }
14124  }
14125 
14126  int operator()(lua_State* L) {
14127  return call(L);
14128  }
14129  };
14130 }
14131 } // namespace sol::function_detail
14132 
14133 // end of sol/function_types_stateless.hpp
14134 
14135 // beginning of sol/function_types_stateful.hpp
14136 
14137 namespace sol {
14138 namespace function_detail {
14139  template <typename Func, bool is_yielding, bool no_trampoline>
14141  typedef std::decay_t<meta::unwrap_unqualified_t<Func>> function_type;
14142  function_type fx;
14143 
14144  template <typename... Args>
14145  functor_function(function_type f, Args&&... args)
14146  : fx(std::move(f), std::forward<Args>(args)...) {
14147  }
14148 
14149  int call(lua_State* L) {
14150  int nr = call_detail::call_wrapped<void, true, false>(L, fx);
14151  if (is_yielding) {
14152  return lua_yield(L, nr);
14153  }
14154  else {
14155  return nr;
14156  }
14157  }
14158 
14159  int operator()(lua_State* L) {
14160  if (!no_trampoline) {
14161  auto f = [&](lua_State*) -> int { return this->call(L); };
14162  return detail::trampoline(L, f);
14163  }
14164  else {
14165  return call(L);
14166  }
14167  }
14168  };
14169 
14170  template <typename T, typename Function, bool is_yielding>
14172  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
14175  function_type invocation;
14177 
14178  template <typename... Args>
14179  member_function(function_type f, Args&&... args)
14180  : invocation(std::move(f)), member(std::forward<Args>(args)...) {
14181  }
14182 
14183  int call(lua_State* L) {
14184  int nr = call_detail::call_wrapped<T, true, false, -1>(L, invocation, detail::unwrap(detail::deref(member)));
14185  if (is_yielding) {
14186  return lua_yield(L, nr);
14187  }
14188  else {
14189  return nr;
14190  }
14191  }
14192 
14193  int operator()(lua_State* L) {
14194  auto f = [&](lua_State*) -> int { return this->call(L); };
14195  return detail::trampoline(L, f);
14196  }
14197  };
14198 
14199  template <typename T, typename Function, bool is_yielding>
14201  typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
14204  function_type var;
14206  typedef std::add_lvalue_reference_t<meta::unwrapped_t<std::remove_reference_t<decltype(detail::deref(member))>>> M;
14207 
14208  template <typename... Args>
14209  member_variable(function_type v, Args&&... args)
14210  : var(std::move(v)), member(std::forward<Args>(args)...) {
14211  }
14212 
14213  int call(lua_State* L) {
14214  int nr;
14215  {
14216  M mem = detail::unwrap(detail::deref(member));
14217  switch (lua_gettop(L)) {
14218  case 0:
14219  nr = call_detail::call_wrapped<T, true, false, -1>(L, var, mem);
14220  break;
14221  case 1:
14222  nr = call_detail::call_wrapped<T, false, false, -1>(L, var, mem);
14223  break;
14224  default:
14225  nr = luaL_error(L, "sol: incorrect number of arguments to member variable function");
14226  break;
14227  }
14228  }
14229  if (is_yielding) {
14230  return lua_yield(L, nr);
14231  }
14232  else {
14233  return nr;
14234  }
14235  }
14236 
14237  int operator()(lua_State* L) {
14238  auto f = [&](lua_State*) -> int { return this->call(L); };
14239  return detail::trampoline(L, f);
14240  }
14241  };
14242 }
14243 } // namespace sol::function_detail
14244 
14245 // end of sol/function_types_stateful.hpp
14246 
14247 // beginning of sol/function_types_overloaded.hpp
14248 
14249 namespace sol {
14250 namespace function_detail {
14251  template <int start_skew = 0, typename... Functions>
14253  typedef std::tuple<Functions...> overload_list;
14254  typedef std::make_index_sequence<sizeof...(Functions)> indices;
14256 
14258  : overloads(std::move(set)) {
14259  }
14260 
14261  overloaded_function(Functions... fxs)
14262  : overloads(fxs...) {
14263  }
14264 
14265  template <typename Fx, std::size_t I, typename... R, typename... Args>
14266  int call(types<Fx>, index_value<I>, types<R...>, types<Args...>, lua_State* L, int, int) {
14267  auto& func = std::get<I>(overloads);
14268  return call_detail::call_wrapped<void, true, false, start_skew>(L, func);
14269  }
14270 
14271  int operator()(lua_State* L) {
14272  auto mfx = [&](auto&&... args) { return this->call(std::forward<decltype(args)>(args)...); };
14273  return call_detail::overload_match<Functions...>(mfx, L, 1 + start_skew);
14274  }
14275  };
14276 }
14277 } // namespace sol::function_detail
14278 
14279 // end of sol/function_types_overloaded.hpp
14280 
14281 // beginning of sol/resolve.hpp
14282 
14283 namespace sol {
14284 
14285 #ifndef __clang__
14286  // constexpr is fine for not-clang
14287 
14288  namespace detail {
14289  template <typename R, typename... Args, typename F, typename = std::result_of_t<meta::unqualified_t<F>(Args...)>>
14290  inline constexpr auto resolve_i(types<R(Args...)>, F &&) -> R (meta::unqualified_t<F>::*)(Args...) {
14291  using Sig = R(Args...);
14292  typedef meta::unqualified_t<F> Fu;
14293  return static_cast<Sig Fu::*>(&Fu::operator());
14294  }
14295 
14296  template <typename F, typename U = meta::unqualified_t<F>>
14297  inline constexpr auto resolve_f(std::true_type, F&& f)
14298  -> decltype(resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f))) {
14299  return resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f));
14300  }
14301 
14302  template <typename F>
14303  inline constexpr void resolve_f(std::false_type, F&&) {
14305  "Cannot use no-template-parameter call with an overloaded functor: specify the signature");
14306  }
14307 
14308  template <typename F, typename U = meta::unqualified_t<F>>
14309  inline constexpr auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature<U>(), std::forward<F>(f))) {
14310  return resolve_f(meta::has_deducible_signature<U>{}, std::forward<F>(f));
14311  }
14312 
14313  template <typename... Args, typename F, typename R = std::result_of_t<F&(Args...)>>
14314  inline constexpr auto resolve_i(types<Args...>, F&& f) -> decltype(resolve_i(types<R(Args...)>(), std::forward<F>(f))) {
14315  return resolve_i(types<R(Args...)>(), std::forward<F>(f));
14316  }
14317 
14318  template <typename Sig, typename C>
14319  inline constexpr Sig C::*resolve_v(std::false_type, Sig C::*mem_func_ptr) {
14320  return mem_func_ptr;
14321  }
14322 
14323  template <typename Sig, typename C>
14324  inline constexpr Sig C::*resolve_v(std::true_type, Sig C::*mem_variable_ptr) {
14325  return mem_variable_ptr;
14326  }
14327  } // namespace detail
14328 
14329  template <typename... Args, typename R>
14330  inline constexpr auto resolve(R fun_ptr(Args...)) -> R (*)(Args...) {
14331  return fun_ptr;
14332  }
14333 
14334  template <typename Sig>
14335  inline constexpr Sig* resolve(Sig* fun_ptr) {
14336  return fun_ptr;
14337  }
14338 
14339  template <typename... Args, typename R, typename C>
14340  inline constexpr auto resolve(R (C::*mem_ptr)(Args...)) -> R (C::*)(Args...) {
14341  return mem_ptr;
14342  }
14343 
14344  template <typename Sig, typename C>
14345  inline constexpr Sig C::*resolve(Sig C::*mem_ptr) {
14346  return detail::resolve_v(std::is_member_object_pointer<Sig C::*>(), mem_ptr);
14347  }
14348 
14349  template <typename... Sig, typename F, meta::disable<std::is_function<meta::unqualified_t<F>>> = meta::enabler>
14350  inline constexpr auto resolve(F&& f) -> decltype(detail::resolve_i(types<Sig...>(), std::forward<F>(f))) {
14351  return detail::resolve_i(types<Sig...>(), std::forward<F>(f));
14352  }
14353 #else
14354 
14355  // Clang has distinct problems with constexpr arguments,
14356  // so don't use the constexpr versions inside of clang.
14357 
14358  namespace detail {
14359  template <typename R, typename... Args, typename F, typename = std::result_of_t<meta::unqualified_t<F>(Args...)>>
14360  inline auto resolve_i(types<R(Args...)>, F &&) -> R (meta::unqualified_t<F>::*)(Args...) {
14361  using Sig = R(Args...);
14362  typedef meta::unqualified_t<F> Fu;
14363  return static_cast<Sig Fu::*>(&Fu::operator());
14364  }
14365 
14366  template <typename F, typename U = meta::unqualified_t<F>>
14367  inline auto resolve_f(std::true_type, F&& f)
14368  -> decltype(resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f))) {
14369  return resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f));
14370  }
14371 
14372  template <typename F>
14373  inline void resolve_f(std::false_type, F&&) {
14375  "Cannot use no-template-parameter call with an overloaded functor: specify the signature");
14376  }
14377 
14378  template <typename F, typename U = meta::unqualified_t<F>>
14379  inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature<U>(), std::forward<F>(f))) {
14380  return resolve_f(meta::has_deducible_signature<U>{}, std::forward<F>(f));
14381  }
14382 
14383  template <typename... Args, typename F, typename R = std::result_of_t<F&(Args...)>>
14384  inline auto resolve_i(types<Args...>, F&& f) -> decltype(resolve_i(types<R(Args...)>(), std::forward<F>(f))) {
14385  return resolve_i(types<R(Args...)>(), std::forward<F>(f));
14386  }
14387 
14388  template <typename Sig, typename C>
14389  inline Sig C::*resolve_v(std::false_type, Sig C::*mem_func_ptr) {
14390  return mem_func_ptr;
14391  }
14392 
14393  template <typename Sig, typename C>
14394  inline Sig C::*resolve_v(std::true_type, Sig C::*mem_variable_ptr) {
14395  return mem_variable_ptr;
14396  }
14397  } // namespace detail
14398 
14399  template <typename... Args, typename R>
14400  inline auto resolve(R fun_ptr(Args...)) -> R (*)(Args...) {
14401  return fun_ptr;
14402  }
14403 
14404  template <typename Sig>
14405  inline Sig* resolve(Sig* fun_ptr) {
14406  return fun_ptr;
14407  }
14408 
14409  template <typename... Args, typename R, typename C>
14410  inline auto resolve(R (C::*mem_ptr)(Args...)) -> R (C::*)(Args...) {
14411  return mem_ptr;
14412  }
14413 
14414  template <typename Sig, typename C>
14415  inline Sig C::*resolve(Sig C::*mem_ptr) {
14416  return detail::resolve_v(std::is_member_object_pointer<Sig C::*>(), mem_ptr);
14417  }
14418 
14419  template <typename... Sig, typename F>
14420  inline auto resolve(F&& f) -> decltype(detail::resolve_i(types<Sig...>(), std::forward<F>(f))) {
14421  return detail::resolve_i(types<Sig...>(), std::forward<F>(f));
14422  }
14423 
14424 #endif
14425 
14426 } // namespace sol
14427 
14428 // end of sol/resolve.hpp
14429 
14430 namespace sol {
14431  namespace function_detail {
14432  template <typename T>
14433  struct class_indicator {};
14434 
14435  struct call_indicator {};
14436  } // namespace function_detail
14437 
14438  namespace stack {
14439  template <typename... Sigs>
14440  struct pusher<function_sig<Sigs...>> {
14441  template <bool is_yielding, typename... Sig, typename Fx, typename... Args>
14442  static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) {
14443  typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
14445  set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14446  }
14447 
14448  template <bool is_yielding, typename R, typename... A, typename Fx, typename... Args>
14449  static void select_convertible(std::true_type, types<R(A...)>, lua_State* L, Fx&& fx, Args&&... args) {
14450  using fx_ptr_t = R (*)(A...);
14451  fx_ptr_t fxptr = detail::unwrap(std::forward<Fx>(fx));
14452  select_function<is_yielding>(std::true_type(), L, fxptr, std::forward<Args>(args)...);
14453  }
14454 
14455  template <bool is_yielding, typename R, typename... A, typename Fx, typename... Args>
14456  static void select_convertible(types<R(A...)> t, lua_State* L, Fx&& fx, Args&&... args) {
14457  typedef std::decay_t<meta::unwrap_unqualified_t<Fx>> raw_fx_t;
14458  typedef R (*fx_ptr_t)(A...);
14459  typedef std::is_convertible<raw_fx_t, fx_ptr_t> is_convertible;
14460  select_convertible<is_yielding>(is_convertible(), t, L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14461  }
14462 
14463  template <bool is_yielding, typename Fx, typename... Args>
14464  static void select_convertible(types<>, lua_State* L, Fx&& fx, Args&&... args) {
14466  select_convertible<is_yielding>(types<Sig>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14467  }
14468 
14469  template <bool is_yielding, typename Fx, typename T, typename... Args>
14470  static void select_reference_member_variable(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
14471  typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
14472  typedef function_detail::member_variable<meta::unwrap_unqualified_t<T>, clean_fx, is_yielding> F;
14473  set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
14474  }
14475 
14476  template <bool is_yielding, typename Fx, typename T, typename... Args>
14477  static void select_reference_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
14478  typedef std::decay_t<Fx> dFx;
14479  dFx memfxptr(std::forward<Fx>(fx));
14480  auto userptr = detail::ptr(std::forward<T>(obj), std::forward<Args>(args)...);
14482 
14483  int upvalues = 0;
14484  upvalues += stack::push(L, nullptr);
14485  upvalues += stack::stack_detail::push_as_upvalues(L, memfxptr);
14486  upvalues += stack::push(L, lightuserdata_value(static_cast<void*>(userptr)));
14487  stack::push(L, c_closure(freefunc, upvalues));
14488  }
14489 
14490  template <bool is_yielding, typename Fx, typename... Args>
14491  static void select_member_variable(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
14492  select_convertible<is_yielding>(types<Sigs...>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14493  }
14494 
14495  template <bool is_yielding, typename Fx, typename T, typename... Args, meta::disable<meta::is_specialization_of<meta::unqualified_t<T>, function_detail::class_indicator>> = meta::enabler>
14496  static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
14497  typedef meta::boolean<meta::is_specialization_of<meta::unqualified_t<T>, std::reference_wrapper>::value || std::is_pointer<T>::value> is_reference;
14498  select_reference_member_variable<is_yielding>(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
14499  }
14500 
14501  template <bool is_yielding, typename Fx, typename C>
14502  static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator<C>) {
14504 
14505  int upvalues = 0;
14506  upvalues += stack::push(L, nullptr);
14507  upvalues += stack::stack_detail::push_as_upvalues(L, fx);
14508  stack::push(L, c_closure(freefunc, upvalues));
14509  }
14510 
14511  template <bool is_yielding, typename Fx>
14512  static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) {
14513  typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
14515 
14516  int upvalues = 0;
14517  upvalues += stack::push(L, nullptr);
14518  upvalues += stack::stack_detail::push_as_upvalues(L, fx);
14519  stack::push(L, c_closure(freefunc, upvalues));
14520  }
14521 
14522  template <bool is_yielding, typename Fx, typename T, typename... Args>
14523  static void select_reference_member_function(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
14524  typedef std::decay_t<Fx> clean_fx;
14525  typedef function_detail::member_function<meta::unwrap_unqualified_t<T>, clean_fx, is_yielding> F;
14526  set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
14527  }
14528 
14529  template <bool is_yielding, typename Fx, typename T, typename... Args>
14530  static void select_reference_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
14531  typedef std::decay_t<Fx> dFx;
14532  dFx memfxptr(std::forward<Fx>(fx));
14533  auto userptr = detail::ptr(std::forward<T>(obj), std::forward<Args>(args)...);
14535 
14536  int upvalues = 0;
14537  upvalues += stack::push(L, nullptr);
14538  upvalues += stack::stack_detail::push_as_upvalues(L, memfxptr);
14539  upvalues += stack::push(L, lightuserdata_value(static_cast<void*>(userptr)));
14540  stack::push(L, c_closure(freefunc, upvalues));
14541  }
14542 
14543  template <bool is_yielding, typename Fx, typename... Args>
14544  static void select_member_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
14545  select_member_variable<is_yielding>(meta::is_member_object<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14546  }
14547 
14548  template <bool is_yielding, typename Fx, typename T, typename... Args, meta::disable<meta::is_specialization_of<meta::unqualified_t<T>, function_detail::class_indicator>> = meta::enabler>
14549  static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
14550  typedef meta::boolean<meta::is_specialization_of<meta::unqualified_t<T>, std::reference_wrapper>::value || std::is_pointer<T>::value> is_reference;
14551  select_reference_member_function<is_yielding>(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
14552  }
14553 
14554  template <bool is_yielding, typename Fx, typename C>
14555  static void select_member_function(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator<C>) {
14557 
14558  int upvalues = 0;
14559  upvalues += stack::push(L, nullptr);
14560  upvalues += stack::stack_detail::push_as_upvalues(L, fx);
14561  stack::push(L, c_closure(freefunc, upvalues));
14562  }
14563 
14564  template <bool is_yielding, typename Fx>
14565  static void select_member_function(std::true_type, lua_State* L, Fx&& fx) {
14566  typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
14568 
14569  int upvalues = 0;
14570  upvalues += stack::push(L, nullptr);
14571  upvalues += stack::stack_detail::push_as_upvalues(L, fx);
14572  stack::push(L, c_closure(freefunc, upvalues));
14573  }
14574 
14575  template <bool is_yielding, typename Fx, typename... Args>
14576  static void select_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
14577  select_member_function<is_yielding>(std::is_member_function_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14578  }
14579 
14580  template <bool is_yielding, typename Fx, typename... Args>
14581  static void select_function(std::true_type, lua_State* L, Fx&& fx, Args&&... args) {
14582  std::decay_t<Fx> target(std::forward<Fx>(fx), std::forward<Args>(args)...);
14584 
14585  int upvalues = 0;
14586  upvalues += stack::push(L, nullptr);
14587  upvalues += stack::stack_detail::push_as_upvalues(L, target);
14588  stack::push(L, c_closure(freefunc, upvalues));
14589  }
14590 
14591  template <bool is_yielding>
14592  static void select_function(std::true_type, lua_State* L, lua_CFunction f) {
14593  // TODO: support yielding
14594  stack::push(L, f);
14595  }
14596 
14597 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
14598  template <bool is_yielding>
14599  static void select_function(std::true_type, lua_State* L, detail::lua_CFunction_noexcept f) {
14600  // TODO: support yielding
14601  stack::push(L, f);
14602  }
14603 #endif // noexcept function type
14604 
14605  template <bool is_yielding, typename Fx, typename... Args, meta::disable<is_lua_reference<meta::unqualified_t<Fx>>> = meta::enabler>
14606  static void select(lua_State* L, Fx&& fx, Args&&... args) {
14607  select_function<is_yielding>(std::is_function<std::remove_pointer_t<meta::unqualified_t<Fx>>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
14608  }
14609 
14610  template <bool is_yielding, typename Fx, meta::enable<is_lua_reference<meta::unqualified_t<Fx>>> = meta::enabler>
14611  static void select(lua_State* L, Fx&& fx) {
14612  // TODO: hoist into lambda in this case??
14613  stack::push(L, std::forward<Fx>(fx));
14614  }
14615 
14616  template <bool is_yielding, typename Fx, typename... Args>
14617  static void set_fx(lua_State* L, Args&&... args) {
14618  lua_CFunction freefunc = detail::static_trampoline<function_detail::call<meta::unqualified_t<Fx>, 2, is_yielding>>;
14619 
14620  int upvalues = 0;
14621  upvalues += stack::push(L, nullptr);
14622  upvalues += stack::push<user<Fx>>(L, std::forward<Args>(args)...);
14623  stack::push(L, c_closure(freefunc, upvalues));
14624  }
14625 
14627  static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
14628  // Set will always place one thing (function) on the stack
14629  select<false>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
14630  return 1;
14631  }
14632 
14633  template <typename... Args>
14634  static int push(lua_State* L, detail::yield_tag_t, Args&&... args) {
14635  // Set will always place one thing (function) on the stack
14636  select<true>(L, std::forward<Args>(args)...);
14637  return 1;
14638  }
14639  };
14640 
14641  template <typename T>
14642  struct pusher<yielding_t<T>> {
14643  template <typename... Args>
14644  static int push(lua_State* L, const yielding_t<T>& f, Args&&... args) {
14645  pusher<function_sig<>> p{};
14646  (void)p;
14647  return p.push(L, detail::yield_tag, f.func, std::forward<Args>(args)...);
14648  }
14649 
14650  template <typename... Args>
14651  static int push(lua_State* L, yielding_t<T>&& f, Args&&... args) {
14652  pusher<function_sig<>> p{};
14653  (void)p;
14654  return p.push(L, detail::yield_tag, f.func, std::forward<Args>(args)...);
14655  }
14656  };
14657 
14658  template <typename T, typename... Args>
14659  struct pusher<function_arguments<T, Args...>> {
14660  template <std::size_t... I, typename FP>
14661  static int push_func(std::index_sequence<I...>, lua_State* L, FP&& fp) {
14662  return stack::push<T>(L, detail::forward_get<I>(fp.arguments)...);
14663  }
14664 
14665  static int push(lua_State* L, const function_arguments<T, Args...>& fp) {
14666  return push_func(std::make_index_sequence<sizeof...(Args)>(), L, fp);
14667  }
14668 
14669  static int push(lua_State* L, function_arguments<T, Args...>&& fp) {
14670  return push_func(std::make_index_sequence<sizeof...(Args)>(), L, std::move(fp));
14671  }
14672  };
14673 
14674  template <typename Signature>
14675  struct pusher<std::function<Signature>> {
14676  static int push(lua_State* L, const std::function<Signature>& fx) {
14677  return pusher<function_sig<Signature>>{}.push(L, fx);
14678  }
14679 
14680  static int push(lua_State* L, std::function<Signature>&& fx) {
14681  return pusher<function_sig<Signature>>{}.push(L, std::move(fx));
14682  }
14683  };
14684 
14685  template <typename Signature>
14686  struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
14687  template <typename F, typename... Args>
14688  static int push(lua_State* L, F&& f, Args&&... args) {
14689  pusher<function_sig<>> p{};
14690  (void)p;
14691  return p.push(L, std::forward<F>(f), std::forward<Args>(args)...);
14692  }
14693  };
14694 
14695  template <typename Signature>
14696  struct pusher<Signature, std::enable_if_t<meta::all<std::is_function<std::remove_pointer_t<Signature>>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>
14697 #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
14698  ,
14699  meta::neg<std::is_same<Signature, detail::lua_CFunction_noexcept>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<detail::lua_CFunction_noexcept>>>
14700 #endif // noexcept function types
14701  >::value>> {
14702  template <typename F>
14703  static int push(lua_State* L, F&& f) {
14704  return pusher<function_sig<>>{}.push(L, std::forward<F>(f));
14705  }
14706  };
14707 
14708  template <typename... Functions>
14709  struct pusher<overload_set<Functions...>> {
14710  static int push(lua_State* L, overload_set<Functions...>&& set) {
14711  // TODO: yielding
14712  typedef function_detail::overloaded_function<0, Functions...> F;
14713  pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(set.functions));
14714  return 1;
14715  }
14716 
14717  static int push(lua_State* L, const overload_set<Functions...>& set) {
14718  // TODO: yielding
14719  typedef function_detail::overloaded_function<0, Functions...> F;
14720  pusher<function_sig<>>{}.set_fx<false, F>(L, set.functions);
14721  return 1;
14722  }
14723  };
14724 
14725  template <typename T>
14726  struct pusher<protect_t<T>> {
14727  static int push(lua_State* L, protect_t<T>&& pw) {
14728  lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>, 2>;
14729  int upvalues = 0;
14730  upvalues += stack::push(L, nullptr);
14731  upvalues += stack::push<user<protect_t<T>>>(L, std::move(pw.value));
14732  return stack::push(L, c_closure(cf, upvalues));
14733  }
14734 
14735  static int push(lua_State* L, const protect_t<T>& pw) {
14736  lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>, 2>;
14737  int upvalues = 0;
14738  upvalues += stack::push(L, nullptr);
14739  upvalues += stack::push<user<protect_t<T>>>(L, pw.value);
14740  return stack::push(L, c_closure(cf, upvalues));
14741  }
14742  };
14743 
14744  template <typename F, typename G>
14745  struct pusher<property_wrapper<F, G>, std::enable_if_t<!std::is_void<F>::value && !std::is_void<G>::value>> {
14746  static int push(lua_State* L, property_wrapper<F, G>&& pw) {
14747  return stack::push(L, overload(std::move(pw.read), std::move(pw.write)));
14748  }
14749  static int push(lua_State* L, const property_wrapper<F, G>& pw) {
14750  return stack::push(L, overload(pw.read, pw.write));
14751  }
14752  };
14753 
14754  template <typename F>
14755  struct pusher<property_wrapper<F, void>> {
14756  static int push(lua_State* L, property_wrapper<F, void>&& pw) {
14757  return stack::push(L, std::move(pw.read));
14758  }
14759  static int push(lua_State* L, const property_wrapper<F, void>& pw) {
14760  return stack::push(L, pw.read);
14761  }
14762  };
14763 
14764  template <typename F>
14765  struct pusher<property_wrapper<void, F>> {
14766  static int push(lua_State* L, property_wrapper<void, F>&& pw) {
14767  return stack::push(L, std::move(pw.write));
14768  }
14769  static int push(lua_State* L, const property_wrapper<void, F>& pw) {
14770  return stack::push(L, pw.write);
14771  }
14772  };
14773 
14774  template <typename T>
14775  struct pusher<var_wrapper<T>> {
14776  static int push(lua_State* L, var_wrapper<T>&& vw) {
14777  return stack::push(L, std::move(vw.value));
14778  }
14779  static int push(lua_State* L, const var_wrapper<T>& vw) {
14780  return stack::push(L, vw.value);
14781  }
14782  };
14783 
14784  template <typename... Functions>
14785  struct pusher<factory_wrapper<Functions...>> {
14786  static int push(lua_State* L, const factory_wrapper<Functions...>& fw) {
14787  typedef function_detail::overloaded_function<0, Functions...> F;
14788  pusher<function_sig<>>{}.set_fx<false, F>(L, fw.functions);
14789  return 1;
14790  }
14791 
14792  static int push(lua_State* L, factory_wrapper<Functions...>&& fw) {
14793  typedef function_detail::overloaded_function<0, Functions...> F;
14794  pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(fw.functions));
14795  return 1;
14796  }
14797 
14799  typedef function_detail::overloaded_function<1, Functions...> F;
14800  pusher<function_sig<>>{}.set_fx<false, F>(L, set.functions);
14801  return 1;
14802  }
14803 
14805  typedef function_detail::overloaded_function<1, Functions...> F;
14806  pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(set.functions));
14807  return 1;
14808  }
14809  };
14810 
14811  template <>
14813  static int push(lua_State* L, no_construction) {
14814  lua_CFunction cf = &function_detail::no_construction_error;
14815  return stack::push(L, cf);
14816  }
14817 
14819  return push(L, c);
14820  }
14821  };
14822 
14823  template <typename T, typename... Lists>
14824  struct pusher<detail::tagged<T, constructor_list<Lists...>>> {
14825  static int push(lua_State* L, detail::tagged<T, constructor_list<Lists...>>) {
14826  lua_CFunction cf = call_detail::construct<T, detail::default_safe_function_calls, true, Lists...>;
14827  return stack::push(L, cf);
14828  }
14829 
14830  static int push(lua_State* L, constructor_list<Lists...>) {
14831  lua_CFunction cf = call_detail::construct<T, detail::default_safe_function_calls, true, Lists...>;
14832  return stack::push(L, cf);
14833  }
14834  };
14835 
14836  template <typename L0, typename... Lists>
14837  struct pusher<constructor_list<L0, Lists...>> {
14838  typedef constructor_list<L0, Lists...> cl_t;
14839  static int push(lua_State* L, cl_t cl) {
14840  typedef typename meta::bind_traits<L0>::return_type T;
14841  return stack::push<detail::tagged<T, cl_t>>(L, cl);
14842  }
14843  };
14844 
14845  template <typename T, typename... Fxs>
14846  struct pusher<detail::tagged<T, constructor_wrapper<Fxs...>>> {
14847  template <typename C>
14848  static int push(lua_State* L, C&& c) {
14849  lua_CFunction cf = call_detail::call_user<T, false, false, constructor_wrapper<Fxs...>, 2>;
14850  int upvalues = 0;
14851  upvalues += stack::push(L, nullptr);
14852  upvalues += stack::push<user<constructor_wrapper<Fxs...>>>(L, std::forward<C>(c));
14853  return stack::push(L, c_closure(cf, upvalues));
14854  }
14855  };
14856 
14857  template <typename F, typename... Fxs>
14858  struct pusher<constructor_wrapper<F, Fxs...>> {
14859  template <typename C>
14860  static int push(lua_State* L, C&& c) {
14861  typedef typename meta::bind_traits<F>::template arg_at<0> arg0;
14863  return stack::push<detail::tagged<T, constructor_wrapper<F, Fxs...>>>(L, std::forward<C>(c));
14864  }
14865  };
14866 
14867  template <typename T>
14868  struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
14869  static int push(lua_State* L, destructor_wrapper<void>) {
14870  lua_CFunction cf = detail::usertype_alloc_destruct<T>;
14871  return stack::push(L, cf);
14872  }
14873  };
14874 
14875  template <typename T, typename Fx>
14876  struct pusher<detail::tagged<T, destructor_wrapper<Fx>>> {
14877  static int push(lua_State* L, destructor_wrapper<Fx>&& c) {
14878  lua_CFunction cf = call_detail::call_user<T, false, false, destructor_wrapper<Fx>, 2>;
14879  int upvalues = 0;
14880  upvalues += stack::push(L, nullptr);
14881  upvalues += stack::push<user<destructor_wrapper<Fx>>>(L, std::move(c));
14882  return stack::push(L, c_closure(cf, upvalues));
14883  }
14884 
14885  static int push(lua_State* L, const destructor_wrapper<Fx>& c) {
14886  lua_CFunction cf = call_detail::call_user<T, false, false, destructor_wrapper<Fx>, 2>;
14887  int upvalues = 0;
14888  upvalues += stack::push(L, nullptr);
14889  upvalues += stack::push<user<destructor_wrapper<Fx>>>(L, c);
14890  return stack::push(L, c_closure(cf, upvalues));
14891  }
14892  };
14893 
14894  template <typename Fx>
14896  static int push(lua_State* L, destructor_wrapper<Fx>&& c) {
14897  lua_CFunction cf = call_detail::call_user<void, false, false, destructor_wrapper<Fx>, 2>;
14898  int upvalues = 0;
14899  upvalues += stack::push(L, nullptr);
14900  upvalues += stack::push<user<destructor_wrapper<Fx>>>(L, std::move(c));
14901  return stack::push(L, c_closure(cf, upvalues));
14902  }
14903 
14904  static int push(lua_State* L, const destructor_wrapper<Fx>& c) {
14905  lua_CFunction cf = call_detail::call_user<void, false, false, destructor_wrapper<Fx>, 2>;
14906  int upvalues = 0;
14907  upvalues += stack::push(L, nullptr);
14908  upvalues += stack::push<user<destructor_wrapper<Fx>>>(L, c);
14909  return stack::push(L, c_closure(cf, upvalues));
14910  }
14911  };
14912 
14913  template <typename F, typename... Filters>
14914  struct pusher<filter_wrapper<F, Filters...>> {
14915  typedef filter_wrapper<F, Filters...> P;
14916 
14917  static int push(lua_State* L, const P& p) {
14918  lua_CFunction cf = call_detail::call_user<void, false, false, P, 2>;
14919  int upvalues = 0;
14920  upvalues += stack::push(L, nullptr);
14921  upvalues += stack::push<user<P>>(L, p);
14922  return stack::push(L, c_closure(cf, upvalues));
14923  }
14924 
14925  static int push(lua_State* L, P&& p) {
14926  lua_CFunction cf = call_detail::call_user<void, false, false, P, 2>;
14927  int upvalues = 0;
14928  upvalues += stack::push(L, nullptr);
14929  upvalues += stack::push<user<P>>(L, std::move(p));
14930  return stack::push(L, c_closure(cf, upvalues));
14931  }
14932  };
14933  } // namespace stack
14934 } // namespace sol
14935 
14936 // end of sol/function_types.hpp
14937 
14938 namespace sol {
14939  template <typename base_t, bool aligned = false>
14940  class basic_function : public base_t {
14941  private:
14942  void luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount) const {
14943  lua_call(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount));
14944  }
14945 
14946  template <std::size_t... I, typename... Ret>
14947  auto invoke(types<Ret...>, std::index_sequence<I...>, std::ptrdiff_t n) const {
14948  luacall(n, lua_size<std::tuple<Ret...>>::value);
14949  return stack::pop<std::tuple<Ret...>>(lua_state());
14950  }
14951 
14952  template <std::size_t I, typename Ret>
14953  Ret invoke(types<Ret>, std::index_sequence<I>, std::ptrdiff_t n) const {
14954  luacall(n, lua_size<Ret>::value);
14955  return stack::pop<Ret>(lua_state());
14956  }
14957 
14958  template <std::size_t I>
14959  void invoke(types<void>, std::index_sequence<I>, std::ptrdiff_t n) const {
14960  luacall(n, 0);
14961  }
14962 
14963  unsafe_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n) const {
14964  int stacksize = lua_gettop(lua_state());
14965  int firstreturn = (std::max)(1, stacksize - static_cast<int>(n));
14966  luacall(n, LUA_MULTRET);
14967  int poststacksize = lua_gettop(lua_state());
14968  int returncount = poststacksize - (firstreturn - 1);
14969  return unsafe_function_result(lua_state(), firstreturn, returncount);
14970  }
14971 
14972  public:
14973  using base_t::lua_state;
14974 
14975  basic_function() = default;
14976  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_function>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
14977  basic_function(T&& r) noexcept
14978  : base_t(std::forward<T>(r)) {
14979 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
14980  if (!is_function<meta::unqualified_t<T>>::value) {
14981  auto pp = stack::push_pop(*this);
14983  stack::check<basic_function>(lua_state(), -1, handler);
14984  }
14985 #endif // Safety
14986  }
14987  basic_function(const basic_function&) = default;
14988  basic_function& operator=(const basic_function&) = default;
14989  basic_function(basic_function&&) = default;
14990  basic_function& operator=(basic_function&&) = default;
14992  : basic_function(r.lua_state(), r.stack_index()) {
14993  }
14995  : basic_function(r.lua_state(), r.stack_index()) {
14996  }
14998  : base_t(n) {
14999  }
15000  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15001  basic_function(lua_State* L, T&& r)
15002  : base_t(L, std::forward<T>(r)) {
15003 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15004  auto pp = stack::push_pop(*this);
15006  stack::check<basic_function>(lua_state(), -1, handler);
15007 #endif // Safety
15008  }
15009  basic_function(lua_State* L, int index = -1)
15010  : base_t(L, index) {
15011 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15013  stack::check<basic_function>(L, index, handler);
15014 #endif // Safety
15015  }
15016  basic_function(lua_State* L, ref_index index)
15017  : base_t(L, index) {
15018 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15019  auto pp = stack::push_pop(*this);
15021  stack::check<basic_function>(lua_state(), -1, handler);
15022 #endif // Safety
15023  }
15024 
15025  template <typename... Args>
15026  unsafe_function_result operator()(Args&&... args) const {
15027  return call<>(std::forward<Args>(args)...);
15028  }
15029 
15030  template <typename... Ret, typename... Args>
15031  decltype(auto) operator()(types<Ret...>, Args&&... args) const {
15032  return call<Ret...>(std::forward<Args>(args)...);
15033  }
15034 
15035  template <typename... Ret, typename... Args>
15036  decltype(auto) call(Args&&... args) const {
15037  if (!aligned) {
15038  base_t::push();
15039  }
15040  int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
15041  return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount);
15042  }
15043  };
15044 } // namespace sol
15045 
15046 // end of sol/unsafe_function.hpp
15047 
15048 // beginning of sol/protected_function.hpp
15049 
15050 // beginning of sol/protected_handler.hpp
15051 
15052 namespace sol {
15053  namespace detail {
15054  inline const char(&default_handler_name())[9]{
15055  static const char name[9] = "sol.\xF0\x9F\x94\xA9";
15056  return name;
15057  }
15058 
15059  template <bool b, typename target_t = reference>
15062  const target_t& target;
15064 
15065  protected_handler(std::false_type, const target_t& target)
15066  : target(target), stackindex(0) {
15067  if (b) {
15068  stackindex = lua_gettop(target.lua_state()) + 1;
15069  target.push();
15070  }
15071  }
15072 
15073  protected_handler(std::true_type, const target_t& target)
15074  : target(target), stackindex(0) {
15075  if (b) {
15076  stackindex = target.stack_index();
15077  }
15078  }
15079 
15080  protected_handler(const target_t& target)
15081  : protected_handler(is_stack(), target) {
15082  }
15083 
15084  bool valid() const noexcept {
15085  return b;
15086  }
15087 
15089  if (!is_stack::value && stackindex != 0) {
15090  lua_remove(target.lua_state(), stackindex);
15091  }
15092  }
15093  };
15094 
15095  template <typename base_t, typename T>
15097  return p;
15098  }
15099 
15100  template <typename Reference, bool is_main_ref = false>
15101  static Reference get_default_handler(lua_State* L) {
15102  if (is_stack_based<Reference>::value || L == nullptr)
15103  return Reference(L, lua_nil);
15104  L = is_main_ref ? main_thread(L, L) : L;
15105  lua_getglobal(L, default_handler_name());
15106  auto pp = stack::pop_n(L, 1);
15107  return Reference(L, -1);
15108  }
15109 
15110  template <typename T>
15111  static void set_default_handler(lua_State* L, const T& ref) {
15112  if (L == nullptr) {
15113  return;
15114  }
15115  if (!ref.valid()) {
15116  lua_pushnil(L);
15117  lua_setglobal(L, default_handler_name());
15118  }
15119  else {
15120  ref.push(L);
15121  lua_setglobal(L, default_handler_name());
15122  }
15123  }
15124  } // namespace detail
15125 } // namespace sol
15126 
15127 // end of sol/protected_handler.hpp
15128 
15129 namespace sol {
15130  template <typename base_t, bool aligned = false, typename handler_t = reference>
15131  class basic_protected_function : public base_t {
15132  public:
15134 
15135  static handler_t get_default_handler(lua_State* L) {
15136  return detail::get_default_handler<handler_t, is_main_threaded<base_t>::value>(L);
15137  }
15138 
15139  template <typename T>
15140  static void set_default_handler(const T& ref) {
15141  detail::set_default_handler(ref.lua_state(), ref);
15142  }
15143 
15144  private:
15145  template <bool b>
15146  call_status luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, detail::protected_handler<b, handler_t>& h) const {
15147  return static_cast<call_status>(lua_pcall(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stackindex));
15148  }
15149 
15150  template <std::size_t... I, bool b, typename... Ret>
15151  auto invoke(types<Ret...>, std::index_sequence<I...>, std::ptrdiff_t n, detail::protected_handler<b, handler_t>& h) const {
15152  luacall(n, sizeof...(Ret), h);
15153  return stack::pop<std::tuple<Ret...>>(lua_state());
15154  }
15155 
15156  template <std::size_t I, bool b, typename Ret>
15157  Ret invoke(types<Ret>, std::index_sequence<I>, std::ptrdiff_t n, detail::protected_handler<b, handler_t>& h) const {
15158  luacall(n, 1, h);
15159  return stack::pop<Ret>(lua_state());
15160  }
15161 
15162  template <std::size_t I, bool b>
15163  void invoke(types<void>, std::index_sequence<I>, std::ptrdiff_t n, detail::protected_handler<b, handler_t>& h) const {
15164  luacall(n, 0, h);
15165  }
15166 
15167  template <bool b>
15168  protected_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n, detail::protected_handler<b, handler_t>& h) const {
15169  int stacksize = lua_gettop(lua_state());
15170  int poststacksize = stacksize;
15171  int firstreturn = 1;
15172  int returncount = 0;
15174 #if !defined(SOL_NO_EXCEPTIONS) || !SOL_NO_EXCEPTIONS
15175  auto onexcept = [&](optional<const std::exception&> maybe_ex, const char* error) {
15176  h.stackindex = 0;
15177  if (b) {
15178  h.target.push();
15179  detail::call_exception_handler(lua_state(), maybe_ex, error);
15180  lua_call(lua_state(), 1, 1);
15181  }
15182  else {
15183  detail::call_exception_handler(lua_state(), maybe_ex, error);
15184  }
15185  };
15186  (void)onexcept;
15187 #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !SOL_NO_EXCEPTIONS_SAFE_PROPAGATION) || (defined(SOL_LUAJIT) && SOL_LUAJIT)
15188  try {
15189 #endif // Safe Exception Propagation
15190 #endif // No Exceptions
15191  firstreturn = (std::max)(1, static_cast<int>(stacksize - n - static_cast<int>(h.valid())));
15192  code = luacall(n, LUA_MULTRET, h);
15193  poststacksize = lua_gettop(lua_state()) - static_cast<int>(h.valid());
15194  returncount = poststacksize - (firstreturn - 1);
15195 #ifndef SOL_NO_EXCEPTIONS
15196 #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !SOL_NO_EXCEPTIONS_SAFE_PROPAGATION) || (defined(SOL_LUAJIT) && SOL_LUAJIT)
15197  }
15198  // Handle C++ errors thrown from C++ functions bound inside of lua
15199  catch (const char* error) {
15200  onexcept(optional<const std::exception&>(nullopt), error);
15201  firstreturn = lua_gettop(lua_state());
15202  return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
15203  }
15204  catch (const std::string& error) {
15205  onexcept(optional<const std::exception&>(nullopt), error.c_str());
15206  firstreturn = lua_gettop(lua_state());
15207  return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
15208  }
15209  catch (const std::exception& error) {
15210  onexcept(optional<const std::exception&>(error), error.what());
15211  firstreturn = lua_gettop(lua_state());
15212  return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
15213  }
15214 #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !SOL_NO_EXCEPTIONS_SAFE_PROPAGATION)
15215  // LuaJIT cannot have the catchall when the safe propagation is on
15216  // but LuaJIT will swallow all C++ errors
15217  // if we don't at least catch std::exception ones
15218  catch (...) {
15219  onexcept(optional<const std::exception&>(nullopt), "caught (...) unknown error during protected_function call");
15220  firstreturn = lua_gettop(lua_state());
15221  return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
15222  }
15223 #endif // LuaJIT
15224 #else
15225  // do not handle exceptions: they can be propogated into C++ and keep all type information / rich information
15226 #endif // Safe Exception Propagation
15227 #endif // Exceptions vs. No Exceptions
15228  return protected_function_result(lua_state(), firstreturn, returncount, returncount, code);
15229  }
15230 
15231  public:
15232  using base_t::lua_state;
15233 
15234  handler_t error_handler;
15235 
15236  basic_protected_function() = default;
15237  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_protected_function>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15239  : base_t(std::forward<T>(r)), error_handler(get_default_handler(r.lua_state())) {
15240 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15241  if (!is_function<meta::unqualified_t<T>>::value) {
15242  auto pp = stack::push_pop(*this);
15244  stack::check<basic_protected_function>(lua_state(), -1, handler);
15245  }
15246 #endif // Safety
15247  }
15249  basic_protected_function& operator=(const basic_protected_function&) = default;
15251  basic_protected_function& operator=(basic_protected_function&&) = default;
15253  : basic_protected_function(b, get_default_handler(b.lua_state())) {
15254  }
15256  : basic_protected_function(std::move(b), get_default_handler(b.lua_state())) {
15257  }
15259  : base_t(b), error_handler(std::move(eh)) {
15260  }
15262  : base_t(std::move(b)), error_handler(std::move(eh)) {
15263  }
15265  : basic_protected_function(r.lua_state(), r.stack_index(), get_default_handler(r.lua_state())) {
15266  }
15268  : basic_protected_function(r.lua_state(), r.stack_index(), get_default_handler(r.lua_state())) {
15269  }
15271  : basic_protected_function(r.lua_state(), r.stack_index(), std::move(eh)) {
15272  }
15274  : basic_protected_function(r.lua_state(), r.stack_index(), std::move(eh)) {
15275  }
15276 
15277  template <typename Super>
15279  : basic_protected_function(p, get_default_handler(p.lua_state())) {
15280  }
15281  template <typename Super>
15283  : basic_protected_function(std::move(p), get_default_handler(p.lua_state())) {
15284  }
15285  template <typename Proxy, typename Handler, meta::enable<std::is_base_of<proxy_base_tag, meta::unqualified_t<Proxy>>, meta::neg<is_lua_index<meta::unqualified_t<Handler>>>> = meta::enabler>
15286  basic_protected_function(Proxy&& p, Handler&& eh)
15287  : basic_protected_function(detail::force_cast<base_t>(p), std::forward<Handler>(eh)) {
15288  }
15289 
15290  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15291  basic_protected_function(lua_State* L, T&& r)
15292  : basic_protected_function(L, std::forward<T>(r), get_default_handler(L)) {
15293  }
15294  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15295  basic_protected_function(lua_State* L, T&& r, handler_t eh)
15296  : base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
15297 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15298  auto pp = stack::push_pop(*this);
15300  stack::check<basic_protected_function>(lua_state(), -1, handler);
15301 #endif // Safety
15302  }
15303 
15305  : base_t(n), error_handler(n) {
15306  }
15307 
15308  basic_protected_function(lua_State* L, int index = -1)
15310  }
15311  basic_protected_function(lua_State* L, int index, handler_t eh)
15312  : base_t(L, index), error_handler(std::move(eh)) {
15313 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15315  stack::check<basic_protected_function>(L, index, handler);
15316 #endif // Safety
15317  }
15320  }
15321  basic_protected_function(lua_State* L, absolute_index index, handler_t eh)
15322  : base_t(L, index), error_handler(std::move(eh)) {
15323 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15325  stack::check<basic_protected_function>(L, index, handler);
15326 #endif // Safety
15327  }
15330  }
15331  basic_protected_function(lua_State* L, raw_index index, handler_t eh)
15332  : base_t(L, index), error_handler(std::move(eh)) {
15333 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15335  stack::check<basic_protected_function>(L, index, handler);
15336 #endif // Safety
15337  }
15340  }
15341  basic_protected_function(lua_State* L, ref_index index, handler_t eh)
15342  : base_t(L, index), error_handler(std::move(eh)) {
15343 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15344  auto pp = stack::push_pop(*this);
15346  stack::check<basic_protected_function>(lua_state(), -1, handler);
15347 #endif // Safety
15348  }
15349 
15350  template <typename... Args>
15351  protected_function_result operator()(Args&&... args) const {
15352  return call<>(std::forward<Args>(args)...);
15353  }
15354 
15355  template <typename... Ret, typename... Args>
15356  decltype(auto) operator()(types<Ret...>, Args&&... args) const {
15357  return call<Ret...>(std::forward<Args>(args)...);
15358  }
15359 
15360  template <typename... Ret, typename... Args>
15361  decltype(auto) call(Args&&... args) const {
15362  if (!aligned) {
15363  // we do not expect the function to already be on the stack: push it
15364  if (error_handler.valid()) {
15366  base_t::push();
15367  int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
15368  return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
15369  }
15370  else {
15372  base_t::push();
15373  int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
15374  return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
15375  }
15376  }
15377  else {
15378  // the function is already on the stack at the right location
15379  if (error_handler.valid()) {
15380  // the handler will be pushed onto the stack manually,
15381  // since it's not already on the stack this means we need to push our own
15382  // function on the stack too and swap things to be in-place
15383  if (!is_stack_handler::value) {
15384  // so, we need to remove the function at the top and then dump the handler out ourselves
15385  base_t::push();
15386  }
15388  if (!is_stack_handler::value) {
15389  lua_replace(lua_state(), -3);
15390  h.stackindex = lua_absindex(lua_state(), -2);
15391  }
15392  int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
15393  return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
15394  }
15395  else {
15397  int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
15398  return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
15399  }
15400  }
15401  }
15402  };
15403 } // namespace sol
15404 
15405 // end of sol/protected_function.hpp
15406 
15407 namespace sol {
15408  template <typename... Ret, typename... Args>
15409  inline decltype(auto) stack_proxy::call(Args&&... args) {
15410  stack_function sf(this->lua_state(), this->stack_index());
15411  return sf.template call<Ret...>(std::forward<Args>(args)...);
15412  }
15413 
15415  : L(o.lua_state()), index(o.stack_index()), returncount(o.return_count()), popcount(o.return_count()), err(o.status()) {
15416  // Must be manual, otherwise destructor will screw us
15417  // return count being 0 is enough to keep things clean
15418  // but we will be thorough
15419  o.abandon();
15420  }
15421 
15423  L = o.lua_state();
15424  index = o.stack_index();
15425  returncount = o.return_count();
15426  popcount = o.return_count();
15427  err = o.status();
15428  // Must be manual, otherwise destructor will screw us
15429  // return count being 0 is enough to keep things clean
15430  // but we will be thorough
15431  o.abandon();
15432  return *this;
15433  }
15434 
15436  : L(o.lua_state()), index(o.stack_index()), returncount(o.return_count()) {
15437  // Must be manual, otherwise destructor will screw us
15438  // return count being 0 is enough to keep things clean
15439  // but we will be thorough
15440  o.abandon();
15441  }
15443  L = o.lua_state();
15444  index = o.stack_index();
15445  returncount = o.return_count();
15446  // Must be manual, otherwise destructor will screw us
15447  // return count being 0 is enough to keep things clean
15448  // but we will be thorough
15449  o.abandon();
15450  return *this;
15451  }
15452 
15453  namespace stack {
15454  template <typename Signature>
15455  struct getter<std::function<Signature>> {
15457  typedef typename fx_t::args_list args_lists;
15459 
15460  template <typename... Args, typename... Ret>
15461  static std::function<Signature> get_std_func(types<Ret...>, types<Args...>, lua_State* L, int index) {
15462  unsafe_function f(L, index);
15463  auto fx = [ f = std::move(f) ](Args && ... args) -> meta::return_type_t<Ret...> {
15464  return f.call<Ret...>(std::forward<Args>(args)...);
15465  };
15466  return std::move(fx);
15467  }
15468 
15469  template <typename... FxArgs>
15470  static std::function<Signature> get_std_func(types<void>, types<FxArgs...>, lua_State* L, int index) {
15471  unsafe_function f(L, index);
15472  auto fx = [f = std::move(f)](FxArgs&&... args) -> void {
15473  f(std::forward<FxArgs>(args)...);
15474  };
15475  return std::move(fx);
15476  }
15477 
15478  template <typename... FxArgs>
15479  static std::function<Signature> get_std_func(types<>, types<FxArgs...> t, lua_State* L, int index) {
15480  return get_std_func(types<void>(), t, L, index);
15481  }
15482 
15483  static std::function<Signature> get(lua_State* L, int index, record& tracking) {
15484  tracking.last = 1;
15485  tracking.used += 1;
15486  type t = type_of(L, index);
15487  if (t == type::none || t == type::lua_nil) {
15488  return nullptr;
15489  }
15490  return get_std_func(return_types(), args_lists(), L, index);
15491  }
15492  };
15493  } // namespace stack
15494 
15495 } // namespace sol
15496 
15497 // end of sol/function.hpp
15498 
15499 namespace sol {
15500  template <typename Table, typename Key>
15501  struct proxy : public proxy_base<proxy<Table, Key>> {
15502  private:
15503  typedef meta::condition<meta::is_specialization_of<Key, std::tuple>, Key, std::tuple<meta::condition<std::is_array<meta::unqualified_t<Key>>, Key&, meta::unqualified_t<Key>>>> key_type;
15504 
15505  template <typename T, std::size_t... I>
15506  decltype(auto) tuple_get(std::index_sequence<I...>) const {
15507  return tbl.template traverse_get<T>(std::get<I>(key)...);
15508  }
15509 
15510  template <std::size_t... I, typename T>
15511  void tuple_set(std::index_sequence<I...>, T&& value) {
15512  tbl.traverse_set(std::get<I>(key)..., std::forward<T>(value));
15513  }
15514 
15515  auto setup_table(std::true_type) {
15516  auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(lua_state(), key, tbl.stack_index());
15517  lua_pop(lua_state(), p.levels);
15518  return p;
15519  }
15520 
15521  bool is_valid(std::false_type) {
15522  auto pp = stack::push_pop(tbl);
15523  auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(lua_state(), key, lua_gettop(lua_state()));
15524  lua_pop(lua_state(), p.levels);
15525  return p;
15526  }
15527 
15528  public:
15529  Table tbl;
15530  key_type key;
15531 
15532  template <typename T>
15533  proxy(Table table, T&& k)
15534  : tbl(table), key(std::forward<T>(k)) {
15535  }
15536 
15537  template <typename T>
15538  proxy& set(T&& item) {
15539  tuple_set(std::make_index_sequence<std::tuple_size<meta::unqualified_t<key_type>>::value>(), std::forward<T>(item));
15540  return *this;
15541  }
15542 
15543  template <typename... Args>
15544  proxy& set_function(Args&&... args) {
15545  tbl.set_function(key, std::forward<Args>(args)...);
15546  return *this;
15547  }
15548 
15549  template <typename U, meta::enable<meta::neg<is_lua_reference_or_proxy<meta::unwrap_unqualified_t<U>>>, meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
15550  proxy& operator=(U&& other) {
15551  return set_function(std::forward<U>(other));
15552  }
15553 
15554  template <typename U, meta::disable<meta::neg<is_lua_reference_or_proxy<meta::unwrap_unqualified_t<U>>>, meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
15555  proxy& operator=(U&& other) {
15556  return set(std::forward<U>(other));
15557  }
15558 
15559  template <typename T>
15560  proxy& operator=(std::initializer_list<T> other) {
15561  return set(std::move(other));
15562  }
15563 
15564  template <typename T>
15565  decltype(auto) get() const {
15566  return tuple_get<T>(std::make_index_sequence<std::tuple_size<meta::unqualified_t<key_type>>::value>());
15567  }
15568 
15569  template <typename T>
15570  decltype(auto) get_or(T&& otherwise) const {
15571  typedef decltype(get<T>()) U;
15572  optional<U> option = get<optional<U>>();
15573  if (option) {
15574  return static_cast<U>(option.value());
15575  }
15576  return static_cast<U>(std::forward<T>(otherwise));
15577  }
15578 
15579  template <typename T, typename D>
15580  decltype(auto) get_or(D&& otherwise) const {
15581  optional<T> option = get<optional<T>>();
15582  if (option) {
15583  return static_cast<T>(option.value());
15584  }
15585  return static_cast<T>(std::forward<D>(otherwise));
15586  }
15587 
15588  template <typename T>
15589  decltype(auto) get_or_create() {
15590  return get_or_create<T>(new_table());
15591  }
15592 
15593  template <typename T, typename Otherwise>
15594  decltype(auto) get_or_create(Otherwise&& other) {
15595  if (!this->valid()) {
15596  this->set(std::forward<Otherwise>(other));
15597  }
15598  return get<T>();
15599  }
15600 
15601  template <typename K>
15602  decltype(auto) operator[](K&& k) const {
15603  auto keys = meta::tuplefy(key, std::forward<K>(k));
15604  return proxy<Table, decltype(keys)>(tbl, std::move(keys));
15605  }
15606 
15607  template <typename... Ret, typename... Args>
15608  decltype(auto) call(Args&&... args) {
15609 #if !defined(__clang__) && defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 191200000
15610  // MSVC is ass sometimes
15611  return get<function>().call<Ret...>(std::forward<Args>(args)...);
15612 #else
15613  return get<function>().template call<Ret...>(std::forward<Args>(args)...);
15614 #endif
15615  }
15616 
15617  template <typename... Args>
15618  decltype(auto) operator()(Args&&... args) {
15619  return call<>(std::forward<Args>(args)...);
15620  }
15621 
15622  bool valid() const {
15623  auto pp = stack::push_pop(tbl);
15624  auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(lua_state(), key, lua_gettop(lua_state()));
15625  lua_pop(lua_state(), p.levels);
15626  return p;
15627  }
15628 
15629  int push() const noexcept {
15630  return push(this->lua_state());
15631  }
15632 
15633  int push(lua_State* L) const noexcept {
15634  return get<reference>().push(L);
15635  }
15636 
15637  type get_type() const {
15638  type t = type::none;
15639  auto pp = stack::push_pop(tbl);
15640  auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(lua_state(), key, lua_gettop(lua_state()));
15641  if (p) {
15642  t = type_of(lua_state(), -1);
15643  }
15644  lua_pop(lua_state(), p.levels);
15645  return t;
15646  }
15647 
15648  lua_State* lua_state() const {
15649  return tbl.lua_state();
15650  }
15651 
15653  if (this->valid()) {
15654  this->set(new_table());
15655  }
15656  return *this;
15657  }
15658  };
15659 
15660  template <typename Table, typename Key, typename T>
15661  inline bool operator==(T&& left, const proxy<Table, Key>& right) {
15662  typedef decltype(stack::get<T>(nullptr, 0)) U;
15663  return right.template get<optional<U>>() == left;
15664  }
15665 
15666  template <typename Table, typename Key, typename T>
15667  inline bool operator==(const proxy<Table, Key>& right, T&& left) {
15668  typedef decltype(stack::get<T>(nullptr, 0)) U;
15669  return right.template get<optional<U>>() == left;
15670  }
15671 
15672  template <typename Table, typename Key, typename T>
15673  inline bool operator!=(T&& left, const proxy<Table, Key>& right) {
15674  typedef decltype(stack::get<T>(nullptr, 0)) U;
15675  return right.template get<optional<U>>() != left;
15676  }
15677 
15678  template <typename Table, typename Key, typename T>
15679  inline bool operator!=(const proxy<Table, Key>& right, T&& left) {
15680  typedef decltype(stack::get<T>(nullptr, 0)) U;
15681  return right.template get<optional<U>>() != left;
15682  }
15683 
15684  template <typename Table, typename Key>
15685  inline bool operator==(lua_nil_t, const proxy<Table, Key>& right) {
15686  return !right.valid();
15687  }
15688 
15689  template <typename Table, typename Key>
15690  inline bool operator==(const proxy<Table, Key>& right, lua_nil_t) {
15691  return !right.valid();
15692  }
15693 
15694  template <typename Table, typename Key>
15695  inline bool operator!=(lua_nil_t, const proxy<Table, Key>& right) {
15696  return right.valid();
15697  }
15698 
15699  template <typename Table, typename Key>
15700  inline bool operator!=(const proxy<Table, Key>& right, lua_nil_t) {
15701  return right.valid();
15702  }
15703 
15704  template <bool b>
15705  template <typename Super>
15707  basic_reference<b> v = r;
15708  this->operator=(std::move(v));
15709  return *this;
15710  }
15711 
15712  template <bool b>
15713  template <typename Super>
15715  basic_reference<b> v = r;
15716  this->operator=(std::move(v));
15717  return *this;
15718  }
15719 
15720  namespace stack {
15721  template <typename Table, typename Key>
15722  struct pusher<proxy<Table, Key>> {
15723  static int push(lua_State* L, const proxy<Table, Key>& p) {
15724  reference r = p;
15725  return r.push(L);
15726  }
15727  };
15728  } // namespace stack
15729 } // namespace sol
15730 
15731 // end of sol/proxy.hpp
15732 
15733 // beginning of sol/usertype.hpp
15734 
15735 // beginning of sol/usertype_metatable.hpp
15736 
15737 // beginning of sol/deprecate.hpp
15738 
15739 #ifndef SOL_DEPRECATED
15740 #ifdef _MSC_VER
15741 #define SOL_DEPRECATED __declspec(deprecated)
15742 #elif __GNUC__
15743 #define SOL_DEPRECATED __attribute__((deprecated))
15744 #else
15745 #define SOL_DEPRECATED [[deprecated]]
15746 #endif // compilers
15747 #endif // SOL_DEPRECATED
15748 
15749 namespace sol {
15750 namespace detail {
15751  template <typename T>
15753  using type = T;
15754  };
15755 }
15756 } // namespace sol::detail
15757 
15758 // end of sol/deprecate.hpp
15759 
15760 // beginning of sol/object.hpp
15761 
15762 // beginning of sol/object_base.hpp
15763 
15764 namespace sol {
15765 
15766  template <typename base_t>
15767  class basic_object_base : public base_t {
15768  private:
15769  template <typename T>
15770  decltype(auto) as_stack(std::true_type) const {
15771  return stack::get<T>(base_t::lua_state(), base_t::stack_index());
15772  }
15773 
15774  template <typename T>
15775  decltype(auto) as_stack(std::false_type) const {
15776  base_t::push();
15777  return stack::pop<T>(base_t::lua_state());
15778  }
15779 
15780  template <typename T>
15781  bool is_stack(std::true_type) const {
15782  return stack::check<T>(base_t::lua_state(), base_t::stack_index(), no_panic);
15783  }
15784 
15785  template <typename T>
15786  bool is_stack(std::false_type) const {
15787  int r = base_t::registry_index();
15788  if (r == LUA_REFNIL)
15789  return meta::any_same<meta::unqualified_t<T>, lua_nil_t, nullopt_t, std::nullptr_t>::value ? true : false;
15790  if (r == LUA_NOREF)
15791  return false;
15792  auto pp = stack::push_pop(*this);
15793  return stack::check<T>(base_t::lua_state(), -1, no_panic);
15794  }
15795 
15796  public:
15797  basic_object_base() noexcept = default;
15798  basic_object_base(const basic_object_base&) = default;
15799  basic_object_base(basic_object_base&&) = default;
15800  basic_object_base& operator=(const basic_object_base&) = default;
15801  basic_object_base& operator=(basic_object_base&&) = default;
15803  basic_object_base(T&& arg, Args&&... args)
15804  : base_t(std::forward<T>(arg), std::forward<Args>(args)...) {
15805  }
15806 
15807  template <typename T>
15808  decltype(auto) as() const {
15809  return as_stack<T>(is_stack_based<base_t>());
15810  }
15811 
15812  template <typename T>
15813  bool is() const {
15814  return is_stack<T>(is_stack_based<base_t>());
15815  }
15816  };
15817 } // namespace sol
15818 
15819 // end of sol/object_base.hpp
15820 
15821 // beginning of sol/userdata.hpp
15822 
15823 namespace sol {
15824  template <typename base_type>
15825  class basic_userdata : public basic_table<base_type> {
15827 
15828  public:
15829  using base_t::lua_state;
15830 
15831  basic_userdata() noexcept = default;
15832  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_userdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15833  basic_userdata(T&& r) noexcept
15834  : base_t(std::forward<T>(r)) {
15835 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15836  if (!is_userdata<meta::unqualified_t<T>>::value) {
15837  auto pp = stack::push_pop(*this);
15838  type_assert(lua_state(), -1, type::userdata);
15839  }
15840 #endif // Safety
15841  }
15842  basic_userdata(const basic_userdata&) = default;
15843  basic_userdata(basic_userdata&&) = default;
15844  basic_userdata& operator=(const basic_userdata&) = default;
15845  basic_userdata& operator=(basic_userdata&&) = default;
15847  : basic_userdata(r.lua_state(), r.stack_index()) {
15848  }
15850  : basic_userdata(r.lua_state(), r.stack_index()) {
15851  }
15852  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15853  basic_userdata(lua_State* L, T&& r)
15854  : base_t(L, std::forward<T>(r)) {
15855 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15856  auto pp = stack::push_pop(*this);
15858  stack::check<basic_userdata>(L, -1, handler);
15859 #endif // Safety
15860  }
15861  basic_userdata(lua_State* L, int index = -1)
15862  : base_t(detail::no_safety, L, index) {
15863 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15865  stack::check<basic_userdata>(L, index, handler);
15866 #endif // Safety
15867  }
15868  basic_userdata(lua_State* L, ref_index index)
15869  : base_t(detail::no_safety, L, index) {
15870 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15871  auto pp = stack::push_pop(*this);
15873  stack::check<basic_userdata>(L, -1, handler);
15874 #endif // Safety
15875  }
15876  };
15877 
15878  template <typename base_type>
15879  class basic_lightuserdata : public basic_object_base<base_type> {
15881 
15882  public:
15883  using base_t::lua_state;
15884 
15885  basic_lightuserdata() noexcept = default;
15886  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_lightuserdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15887  basic_lightuserdata(T&& r) noexcept
15888  : base_t(std::forward<T>(r)) {
15889 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15891  auto pp = stack::push_pop(*this);
15892  type_assert(lua_state(), -1, type::lightuserdata);
15893  }
15894 #endif // Safety
15895  }
15896  basic_lightuserdata(const basic_lightuserdata&) = default;
15898  basic_lightuserdata& operator=(const basic_lightuserdata&) = default;
15899  basic_lightuserdata& operator=(basic_lightuserdata&&) = default;
15901  : basic_lightuserdata(r.lua_state(), r.stack_index()) {
15902  }
15904  : basic_lightuserdata(r.lua_state(), r.stack_index()) {
15905  }
15906  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
15907  basic_lightuserdata(lua_State* L, T&& r)
15908  : basic_lightuserdata(L, std::forward<T>(r)) {
15909 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15910  auto pp = stack::push_pop(*this);
15912  stack::check<basic_lightuserdata>(lua_state(), -1, handler);
15913 #endif // Safety
15914  }
15915  basic_lightuserdata(lua_State* L, int index = -1)
15916  : base_t(L, index) {
15917 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15919  stack::check<basic_lightuserdata>(L, index, handler);
15920 #endif // Safety
15921  }
15922  basic_lightuserdata(lua_State* L, ref_index index)
15923  : base_t(L, index) {
15924 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
15925  auto pp = stack::push_pop(*this);
15927  stack::check<basic_lightuserdata>(lua_state(), index, handler);
15928 #endif // Safety
15929  }
15930  };
15931 
15932 } // namespace sol
15933 
15934 // end of sol/userdata.hpp
15935 
15936 // beginning of sol/as_args.hpp
15937 
15938 namespace sol {
15939  template <typename T>
15940  struct as_args_t {
15941  T src;
15942  };
15943 
15944  template <typename Source>
15945  auto as_args(Source&& source) {
15946  return as_args_t<Source>{ std::forward<Source>(source) };
15947  }
15948 
15949  namespace stack {
15950  template <typename T>
15951  struct pusher<as_args_t<T>> {
15952  int push(lua_State* L, const as_args_t<T>& e) {
15953  int p = 0;
15954  for (const auto& i : e.src) {
15955  p += stack::push(L, i);
15956  }
15957  return p;
15958  }
15959  };
15960  } // namespace stack
15961 } // namespace sol
15962 
15963 // end of sol/as_args.hpp
15964 
15965 // beginning of sol/variadic_args.hpp
15966 
15967 namespace sol {
15968  struct variadic_args {
15969  private:
15970  lua_State* L;
15971  int index;
15973 
15974  public:
15978  typedef std::ptrdiff_t difference_type;
15979  typedef std::size_t size_type;
15982  typedef std::reverse_iterator<iterator> reverse_iterator;
15983  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
15984 
15985  variadic_args() = default;
15986  variadic_args(lua_State* luastate, int stackindex = -1)
15987  : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lua_gettop(luastate)) {
15988  }
15989  variadic_args(lua_State* luastate, int stackindex, int lastindex)
15990  : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lastindex) {
15991  }
15992  variadic_args(const variadic_args&) = default;
15993  variadic_args& operator=(const variadic_args&) = default;
15995  : L(o.L), index(o.index), stacktop(o.stacktop) {
15996  // Must be manual, otherwise destructor will screw us
15997  // return count being 0 is enough to keep things clean
15998  // but will be thorough
15999  o.L = nullptr;
16000  o.index = 0;
16001  o.stacktop = 0;
16002  }
16004  L = o.L;
16005  index = o.index;
16006  stacktop = o.stacktop;
16007  // Must be manual, otherwise destructor will screw us
16008  // return count being 0 is enough to keep things clean
16009  // but will be thorough
16010  o.L = nullptr;
16011  o.index = 0;
16012  o.stacktop = 0;
16013  return *this;
16014  }
16015 
16016  iterator begin() {
16017  return iterator(L, index, stacktop + 1);
16018  }
16019  iterator end() {
16020  return iterator(L, stacktop + 1, stacktop + 1);
16021  }
16022  const_iterator begin() const {
16023  return const_iterator(L, index, stacktop + 1);
16024  }
16025  const_iterator end() const {
16026  return const_iterator(L, stacktop + 1, stacktop + 1);
16027  }
16028  const_iterator cbegin() const {
16029  return begin();
16030  }
16031  const_iterator cend() const {
16032  return end();
16033  }
16034 
16035  reverse_iterator rbegin() {
16036  return std::reverse_iterator<iterator>(begin());
16037  }
16038  reverse_iterator rend() {
16039  return std::reverse_iterator<iterator>(end());
16040  }
16041  const_reverse_iterator rbegin() const {
16042  return std::reverse_iterator<const_iterator>(begin());
16043  }
16044  const_reverse_iterator rend() const {
16045  return std::reverse_iterator<const_iterator>(end());
16046  }
16047  const_reverse_iterator crbegin() const {
16048  return std::reverse_iterator<const_iterator>(cbegin());
16049  }
16050  const_reverse_iterator crend() const {
16051  return std::reverse_iterator<const_iterator>(cend());
16052  }
16053 
16054  int push() const {
16055  return push(L);
16056  }
16057 
16058  int push(lua_State* target) const {
16059  int pushcount = 0;
16060  for (int i = index; i <= stacktop; ++i) {
16061  lua_pushvalue(L, i);
16062  pushcount += 1;
16063  }
16064  if (target != L) {
16065  lua_xmove(L, target, pushcount);
16066  }
16067  return pushcount;
16068  }
16069 
16070  template <typename T>
16071  decltype(auto) get(difference_type index_offset = 0) const {
16072  return stack::get<T>(L, index + static_cast<int>(index_offset));
16073  }
16074 
16075  type get_type(difference_type index_offset = 0) const noexcept {
16076  return type_of(L, index + static_cast<int>(index_offset));
16077  }
16078 
16079  stack_proxy operator[](difference_type index_offset) const {
16080  return stack_proxy(L, index + static_cast<int>(index_offset));
16081  }
16082 
16083  lua_State* lua_state() const {
16084  return L;
16085  };
16086  int stack_index() const {
16087  return index;
16088  };
16089  int leftover_count() const {
16090  return stacktop - (index - 1);
16091  }
16092  std::size_t size() const {
16093  return static_cast<std::size_t>(leftover_count());
16094  }
16095  int top() const {
16096  return stacktop;
16097  }
16098  };
16099 
16100  namespace stack {
16101  template <>
16103  static variadic_args get(lua_State* L, int index, record& tracking) {
16104  tracking.last = 0;
16105  return variadic_args(L, index);
16106  }
16107  };
16108 
16109  template <>
16111  static int push(lua_State* L, const variadic_args& ref) {
16112  return ref.push(L);
16113  }
16114  };
16115  } // namespace stack
16116 } // namespace sol
16117 
16118 // end of sol/variadic_args.hpp
16119 
16120 namespace sol {
16121 
16122  template <typename R = reference, bool should_pop = !is_stack_based<R>::value, typename T>
16123  R make_reference(lua_State* L, T&& value) {
16124  int backpedal = stack::push(L, std::forward<T>(value));
16125  R r = stack::get<R>(L, -backpedal);
16126  if (should_pop) {
16127  lua_pop(L, backpedal);
16128  }
16129  return r;
16130  }
16131 
16132  template <typename T, typename R = reference, bool should_pop = !is_stack_based<R>::value, typename... Args>
16133  R make_reference(lua_State* L, Args&&... args) {
16134  int backpedal = stack::push<T>(L, std::forward<Args>(args)...);
16135  R r = stack::get<R>(L, -backpedal);
16136  if (should_pop) {
16137  lua_pop(L, backpedal);
16138  }
16139  return r;
16140  }
16141 
16142  template <typename base_type>
16143  class basic_object : public basic_object_base<base_type> {
16144  private:
16146 
16147  template <bool invert_and_pop = false>
16148  basic_object(std::integral_constant<bool, invert_and_pop>, lua_State* L, int index = -1) noexcept
16149  : base_t(L, index) {
16150  if (invert_and_pop) {
16151  lua_pop(L, -index);
16152  }
16153  }
16154 
16155  public:
16156  basic_object() noexcept = default;
16157  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_object>>, meta::neg<std::is_same<base_type, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
16159  : base_t(std::forward<T>(r)) {
16160  }
16161  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
16162  basic_object(lua_State* L, T&& r)
16163  : base_t(L, std::forward<T>(r)) {
16164  }
16166  : base_t(r) {
16167  }
16168  basic_object(const basic_object&) = default;
16169  basic_object(basic_object&&) = default;
16170  basic_object(const stack_reference& r) noexcept
16171  : basic_object(r.lua_state(), r.stack_index()) {
16172  }
16174  : basic_object(r.lua_state(), r.stack_index()) {
16175  }
16176  template <typename Super>
16177  basic_object(const proxy_base<Super>& r) noexcept
16178  : basic_object(r.operator basic_object()) {
16179  }
16180  template <typename Super>
16182  : basic_object(r.operator basic_object()) {
16183  }
16184  basic_object(lua_State* L, lua_nil_t r) noexcept
16185  : base_t(L, r) {
16186  }
16187  basic_object(lua_State* L, int index = -1) noexcept
16188  : base_t(L, index) {
16189  }
16190  basic_object(lua_State* L, absolute_index index) noexcept
16191  : base_t(L, index) {
16192  }
16193  basic_object(lua_State* L, raw_index index) noexcept
16194  : base_t(L, index) {
16195  }
16196  basic_object(lua_State* L, ref_index index) noexcept
16197  : base_t(L, index) {
16198  }
16199  template <typename T, typename... Args>
16200  basic_object(lua_State* L, in_place_type_t<T>, Args&&... args) noexcept
16201  : basic_object(std::integral_constant<bool, !is_stack_based<base_t>::value>(), L, -stack::push<T>(L, std::forward<Args>(args)...)) {
16202  }
16203  template <typename T, typename... Args>
16204  basic_object(lua_State* L, in_place_t, T&& arg, Args&&... args) noexcept
16205  : basic_object(L, in_place_type<T>, std::forward<T>(arg), std::forward<Args>(args)...) {
16206  }
16207  basic_object& operator=(const basic_object&) = default;
16208  basic_object& operator=(basic_object&&) = default;
16209  basic_object& operator=(const base_type& b) {
16210  base_t::operator=(b);
16211  return *this;
16212  }
16213  basic_object& operator=(base_type&& b) {
16214  base_t::operator=(std::move(b));
16215  return *this;
16216  }
16217  template <typename Super>
16219  this->operator=(r.operator basic_object());
16220  return *this;
16221  }
16222  template <typename Super>
16224  this->operator=(r.operator basic_object());
16225  return *this;
16226  }
16227  };
16228 
16229  template <typename T>
16230  object make_object(lua_State* L, T&& value) {
16231  return make_reference<object, true>(L, std::forward<T>(value));
16232  }
16233 
16234  template <typename T, typename... Args>
16235  object make_object(lua_State* L, Args&&... args) {
16236  return make_reference<T, object, true>(L, std::forward<Args>(args)...);
16237  }
16238 } // namespace sol
16239 
16240 // end of sol/object.hpp
16241 
16242 // beginning of sol/container_usertype_metatable.hpp
16243 
16244 // beginning of sol/container_traits.hpp
16245 
16246 namespace sol {
16247 
16248  template <typename T>
16250 
16251  template <typename T>
16252  struct as_container_t {
16254 
16256  : source(std::move(value)) {
16257  }
16258 
16259  operator std::add_rvalue_reference_t<T>() {
16260  return std::move(source);
16261  }
16262 
16263  operator std::add_lvalue_reference_t<std::add_const_t<T>>() const {
16264  return source;
16265  }
16266  };
16267 
16268  template <typename T>
16269  struct as_container_t<T&> {
16270  std::reference_wrapper<T> source;
16271 
16272  as_container_t(T& value)
16273  : source(value) {
16274  }
16275 
16276  operator T&() {
16277  return source;
16278  }
16279  };
16280 
16281  template <typename T>
16282  auto as_container(T&& value) {
16283  return as_container_t<T>(std::forward<T>(value));
16284  }
16285 
16286  namespace container_detail {
16287 
16288  template <typename T>
16290  private:
16291  typedef std::array<char, 1> one;
16292  typedef std::array<char, 2> two;
16293 
16294  template <typename C>
16295  static one test(decltype(&C::clear));
16296  template <typename C>
16297  static two test(...);
16298 
16299  public:
16300  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16301  };
16302 
16303  template <typename T>
16305  private:
16306  typedef std::array<char, 1> one;
16307  typedef std::array<char, 2> two;
16308 
16309  template <typename C>
16310  static one test(decltype(&C::empty));
16311  template <typename C>
16312  static two test(...);
16313 
16314  public:
16315  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16316  };
16317 
16318  template <typename T>
16320  private:
16321  typedef std::array<char, 1> one;
16322  typedef std::array<char, 2> two;
16323 
16324  template <typename C>
16325  static one test(decltype(std::declval<C>().erase_after(std::declval<std::add_rvalue_reference_t<typename C::const_iterator>>()))*);
16326  template <typename C>
16327  static two test(...);
16328 
16329  public:
16330  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16331  };
16332 
16333  template <typename T, typename = void>
16334  struct has_find_test {
16335  private:
16336  typedef std::array<char, 1> one;
16337  typedef std::array<char, 2> two;
16338 
16339  template <typename C>
16340  static one test(decltype(std::declval<C>().find(std::declval<std::add_rvalue_reference_t<typename C::value_type>>()))*);
16341  template <typename C>
16342  static two test(...);
16343 
16344  public:
16345  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16346  };
16347 
16348  template <typename T>
16349  struct has_find_test<T, std::enable_if_t<meta::is_lookup<T>::value>> {
16350  private:
16351  typedef std::array<char, 1> one;
16352  typedef std::array<char, 2> two;
16353 
16354  template <typename C>
16355  static one test(decltype(std::declval<C>().find(std::declval<std::add_rvalue_reference_t<typename C::key_type>>()))*);
16356  template <typename C>
16357  static two test(...);
16358 
16359  public:
16360  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16361  };
16362 
16363  template <typename T>
16365  private:
16366  typedef std::array<char, 1> one;
16367  typedef std::array<char, 2> two;
16368 
16369  template <typename C>
16370  static one test(decltype(std::declval<C>().erase(std::declval<typename C::iterator>()))*);
16371  template <typename C>
16372  static two test(...);
16373 
16374  public:
16375  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16376  };
16377 
16378  template <typename T>
16380  private:
16381  typedef std::array<char, 1> one;
16382  typedef std::array<char, 2> two;
16383 
16384  template <typename C>
16385  static one test(decltype(&C::find));
16386  template <typename C>
16387  static two test(...);
16388 
16389  public:
16390  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16391  };
16392 
16393  template <typename T>
16395  private:
16396  typedef std::array<char, 1> one;
16397  typedef std::array<char, 2> two;
16398 
16399  template <typename C>
16400  static one test(decltype(&C::insert));
16401  template <typename C>
16402  static two test(...);
16403 
16404  public:
16405  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16406  };
16407 
16408  template <typename T>
16410  private:
16411  typedef std::array<char, 1> one;
16412  typedef std::array<char, 2> two;
16413 
16414  template <typename C>
16415  static one test(decltype(&C::erase));
16416  template <typename C>
16417  static two test(...);
16418 
16419  public:
16420  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16421  };
16422 
16423  template <typename T>
16425  private:
16426  typedef std::array<char, 1> one;
16427  typedef std::array<char, 2> two;
16428 
16429  template <typename C>
16430  static one test(decltype(&C::index_set));
16431  template <typename C>
16432  static two test(...);
16433 
16434  public:
16435  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16436  };
16437 
16438  template <typename T>
16440  private:
16441  typedef std::array<char, 1> one;
16442  typedef std::array<char, 2> two;
16443 
16444  template <typename C>
16445  static one test(decltype(&C::index_get));
16446  template <typename C>
16447  static two test(...);
16448 
16449  public:
16450  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16451  };
16452 
16453  template <typename T>
16455  private:
16456  typedef std::array<char, 1> one;
16457  typedef std::array<char, 2> two;
16458 
16459  template <typename C>
16460  static one test(decltype(&C::set));
16461  template <typename C>
16462  static two test(...);
16463 
16464  public:
16465  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16466  };
16467 
16468  template <typename T>
16470  private:
16471  typedef std::array<char, 1> one;
16472  typedef std::array<char, 2> two;
16473 
16474  template <typename C>
16475  static one test(decltype(&C::get));
16476  template <typename C>
16477  static two test(...);
16478 
16479  public:
16480  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16481  };
16482 
16483  template <typename T>
16485  private:
16486  typedef std::array<char, 1> one;
16487  typedef std::array<char, 2> two;
16488 
16489  template <typename C>
16490  static one test(decltype(&C::at));
16491  template <typename C>
16492  static two test(...);
16493 
16494  public:
16495  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16496  };
16497 
16498  template <typename T>
16500  private:
16501  typedef std::array<char, 1> one;
16502  typedef std::array<char, 2> two;
16503 
16504  template <typename C>
16505  static one test(decltype(&C::pairs));
16506  template <typename C>
16507  static two test(...);
16508 
16509  public:
16510  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16511  };
16512 
16513  template <typename T>
16515  private:
16516  typedef std::array<char, 1> one;
16517  typedef std::array<char, 2> two;
16518 
16519  template <typename C>
16520  static one test(decltype(&C::ipairs));
16521  template <typename C>
16522  static two test(...);
16523 
16524  public:
16525  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16526  };
16527 
16528  template <typename T>
16530  private:
16531  typedef std::array<char, 1> one;
16532  typedef std::array<char, 2> two;
16533 
16534  template <typename C>
16535  static one test(decltype(&C::next));
16536  template <typename C>
16537  static two test(...);
16538 
16539  public:
16540  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16541  };
16542 
16543  template <typename T>
16545  private:
16546  typedef std::array<char, 1> one;
16547  typedef std::array<char, 2> two;
16548 
16549  template <typename C>
16550  static one test(decltype(&C::add));
16551  template <typename C>
16552  static two test(...);
16553 
16554  public:
16555  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16556  };
16557 
16558  template <typename T>
16560  private:
16561  typedef std::array<char, 1> one;
16562  typedef std::array<char, 2> two;
16563 
16564  template <typename C>
16565  static one test(decltype(&C::size));
16566  template <typename C>
16567  static two test(...);
16568 
16569  public:
16570  static const bool value = sizeof(test<T>(0)) == sizeof(char);
16571  };
16572 
16573  template <typename T>
16575 
16576  template <typename T>
16578 
16579  template <typename T>
16581 
16582  template <typename T>
16584 
16585  template <typename T>
16587 
16588  template <typename T>
16590 
16591  template <typename T>
16593 
16594  template <typename T>
16596 
16597  template <typename T>
16599 
16600  template <typename T>
16602 
16603  template <typename T>
16605 
16606  template <typename T>
16608 
16609  template <typename T>
16611 
16612  template <typename T>
16614 
16615  template <typename T>
16617 
16618  template <typename T>
16620 
16621  template <typename T>
16623 
16624  template <typename T>
16626 
16627  template <typename T>
16629 
16630  template <typename T>
16632 
16633  template <typename T>
16635 
16636  template <typename T>
16637  struct is_forced_container<as_container_t<T>> : std::true_type {};
16638 
16639  template <typename T>
16641  typedef T type;
16642  };
16643 
16644  template <typename T>
16646  typedef T type;
16647  };
16648 
16649  template <typename T>
16651 
16652  template <typename T>
16653  decltype(auto) get_key(std::false_type, T&& t) {
16654  return std::forward<T>(t);
16655  }
16656 
16657  template <typename T>
16658  decltype(auto) get_key(std::true_type, T&& t) {
16659  return t.first;
16660  }
16661 
16662  template <typename T>
16663  decltype(auto) get_value(std::false_type, T&& t) {
16664  return std::forward<T>(t);
16665  }
16666 
16667  template <typename T>
16668  decltype(auto) get_value(std::true_type, T&& t) {
16669  return t.second;
16670  }
16671 
16672  struct error_result {
16673  int results;
16674  const char* fmt_;
16675  std::array<const char*, 4> args;
16676 
16677  error_result() : results(0), fmt_(nullptr) {
16678  }
16679 
16680  error_result(int results) : results(results), fmt_(nullptr) {
16681  }
16682 
16683  error_result(const char* fmt_, const char* msg) : results(0), fmt_(fmt_) {
16684  args[0] = msg;
16685  }
16686  };
16687 
16688  inline int handle_errors(lua_State* L, const error_result& er) {
16689  if (er.fmt_ == nullptr) {
16690  return er.results;
16691  }
16692  return luaL_error(L, er.fmt_, er.args[0], er.args[1], er.args[2], er.args[3]);
16693  }
16694 
16695  template <typename X, typename = void>
16697  private:
16698  typedef std::remove_pointer_t<meta::unwrap_unqualified_t<X>> T;
16699 
16700  public:
16703 
16704  static int at(lua_State* L) {
16705  return luaL_error(L, "sol: cannot call 'at(index)' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16706  }
16707 
16708  static int get(lua_State* L) {
16709  return luaL_error(L, "sol: cannot call 'get(key)' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16710  }
16711 
16712  static int index_get(lua_State* L) {
16713  return luaL_error(L, "sol: cannot call 'container[key]' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16714  }
16715 
16716  static int set(lua_State* L) {
16717  return luaL_error(L, "sol: cannot call 'set(key, value)' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16718  }
16719 
16720  static int index_set(lua_State* L) {
16721  return luaL_error(L, "sol: cannot call 'container[key] = value' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16722  }
16723 
16724  static int add(lua_State* L) {
16725  return luaL_error(L, "sol: cannot call 'add' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16726  }
16727 
16728  static int insert(lua_State* L) {
16729  return luaL_error(L, "sol: cannot call 'insert' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16730  }
16731 
16732  static int find(lua_State* L) {
16733  return luaL_error(L, "sol: cannot call 'find' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16734  }
16735 
16736  static int size(lua_State* L) {
16737  return luaL_error(L, "sol: cannot call 'end' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16738  }
16739 
16740  static int clear(lua_State* L) {
16741  return luaL_error(L, "sol: cannot call 'clear' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16742  }
16743 
16744  static int empty(lua_State* L) {
16745  return luaL_error(L, "sol: cannot call 'empty' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16746  }
16747 
16748  static int erase(lua_State* L) {
16749  return luaL_error(L, "sol: cannot call 'erase' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16750  }
16751 
16752  static int next(lua_State* L) {
16753  return luaL_error(L, "sol: cannot call 'next' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16754  }
16755 
16756  static int pairs(lua_State* L) {
16757  return luaL_error(L, "sol: cannot call '__pairs/pairs' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16758  }
16759 
16760  static int ipairs(lua_State* L) {
16761  return luaL_error(L, "sol: cannot call '__ipairs' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16762  }
16763 
16764  static iterator begin(lua_State* L, T&) {
16765  luaL_error(L, "sol: cannot call 'being' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16766  return lua_nil;
16767  }
16768 
16769  static iterator end(lua_State* L, T&) {
16770  luaL_error(L, "sol: cannot call 'end' on type '%s': it is not recognized as a container", detail::demangle<T>().c_str());
16771  return lua_nil;
16772  }
16773  };
16774 
16775  template <typename X>
16776  struct container_traits_default<X, std::enable_if_t<meta::all<is_forced_container<meta::unqualified_t<X>>, meta::has_value_type<meta::unqualified_t<container_decay_t<X>>>, meta::has_iterator<meta::unqualified_t<container_decay_t<X>>>>::value>> {
16777  private:
16778  typedef std::remove_pointer_t<meta::unwrap_unqualified_t<container_decay_t<X>>> T;
16779 
16780  private:
16785  typedef typename T::iterator iterator;
16786  typedef typename T::value_type value_type;
16787  typedef std::conditional_t<is_matched_lookup::value,
16788  std::pair<value_type, value_type>,
16789  std::conditional_t<is_associative::value || is_lookup::value,
16790  value_type,
16791  std::pair<std::ptrdiff_t, value_type>
16792  >
16793  > KV;
16794  typedef typename KV::first_type K;
16795  typedef typename KV::second_type V;
16796  typedef std::conditional_t<is_matched_lookup::value, std::ptrdiff_t, K> next_K;
16797  typedef decltype(*std::declval<iterator&>()) iterator_return;
16798  typedef std::conditional_t<is_associative::value || is_matched_lookup::value,
16799  std::add_lvalue_reference_t<V>,
16800  std::conditional_t<is_lookup::value,
16801  V,
16802  iterator_return
16803  >
16805  typedef typename meta::iterator_tag<iterator>::type iterator_category;
16806  typedef std::is_same<iterator_category, std::input_iterator_tag> is_input_iterator;
16807  typedef std::conditional_t<is_input_iterator::value,
16808  V,
16809  decltype(detail::deref_non_pointer(std::declval<captured_type>()))
16811  typedef std::is_copy_assignable<V> is_copyable;
16812  typedef meta::neg<meta::any<
16813  std::is_const<V>, std::is_const<std::remove_reference_t<iterator_return>>, meta::neg<is_copyable>
16815  typedef meta::unqualified_t<decltype(get_key(is_associative(), std::declval<std::add_lvalue_reference_t<value_type>>()))> key_type;
16816  typedef meta::all<std::is_integral<K>, meta::neg<meta::any<is_associative, is_lookup>>> is_linear_integral;
16817 
16818  struct iter {
16820  iterator it;
16821  std::size_t i;
16822 
16823  iter(T& source, iterator it)
16824  : source(source), it(std::move(it)), i(0) {
16825  }
16826  };
16827 
16828  static auto& get_src(lua_State* L) {
16829 #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
16830  auto p = stack::unqualified_check_get<T*>(L, 1);
16831  if (!p) {
16832  luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle<T>().c_str());
16833  }
16834  if (p.value() == nullptr) {
16835  luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument with ':' or call on a '%s' type)", detail::demangle<T>().c_str());
16836  }
16837  return *p.value();
16838 #else
16839  return stack::unqualified_get<T>(L, 1);
16840 #endif // Safe getting with error
16841  }
16842 
16843  static error_result at_category(std::input_iterator_tag, lua_State* L, T& self, std::ptrdiff_t pos) {
16844  pos += deferred_traits::index_adjustment(L, self);
16845  if (pos < 0) {
16846  return stack::push(L, lua_nil);
16847  }
16848  auto it = deferred_traits::begin(L, self);
16849  auto e = deferred_traits::end(L, self);
16850  if (it == e) {
16851  return stack::push(L, lua_nil);
16852  }
16853  while (pos > 0) {
16854  --pos;
16855  ++it;
16856  if (it == e) {
16857  return stack::push(L, lua_nil);
16858  }
16859  }
16860  return get_associative(is_associative(), L, it);
16861  }
16862 
16863  static error_result at_category(std::random_access_iterator_tag, lua_State* L, T& self, std::ptrdiff_t pos) {
16864  std::ptrdiff_t len = static_cast<std::ptrdiff_t>(size_start(L, self));
16865  pos += deferred_traits::index_adjustment(L, self);
16866  if (pos < 0 || pos >= len) {
16867  return stack::push(L, lua_nil);
16868  }
16869  auto it = std::next(deferred_traits::begin(L, self), pos);
16870  return get_associative(is_associative(), L, it);
16871  }
16872 
16873  static error_result at_start(lua_State* L, T& self, std::ptrdiff_t pos) {
16874  return at_category(iterator_category(), L, self, pos);
16875  }
16876 
16877  static error_result get_associative(std::true_type, lua_State* L, iterator& it) {
16878  auto& v = *it;
16879  return stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(v.second));
16880  }
16881 
16882  static error_result get_associative(std::false_type, lua_State* L, iterator& it) {
16883  return stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(*it));
16884  }
16885 
16886  static error_result get_category(std::input_iterator_tag, lua_State* L, T& self, K& key) {
16887  key += deferred_traits::index_adjustment(L, self);
16888  if (key < 0) {
16889  return stack::push(L, lua_nil);
16890  }
16891  auto it = deferred_traits::begin(L, self);
16892  auto e = deferred_traits::end(L, self);
16893  if (it == e) {
16894  return stack::push(L, lua_nil);
16895  }
16896  while (key > 0) {
16897  --key;
16898  ++it;
16899  if (it == e) {
16900  return stack::push(L, lua_nil);
16901  }
16902  }
16903  return get_associative(is_associative(), L, it);
16904  }
16905 
16906  static error_result get_category(std::random_access_iterator_tag, lua_State* L, T& self, K& key) {
16907  std::ptrdiff_t len = static_cast<std::ptrdiff_t>(size_start(L, self));
16908  key += deferred_traits::index_adjustment(L, self);
16909  if (key < 0 || key >= len) {
16910  return stack::push(L, lua_nil);
16911  }
16912  auto it = std::next(deferred_traits::begin(L, self), key);
16913  return get_associative(is_associative(), L, it);
16914  }
16915 
16916  static error_result get_it(std::true_type, lua_State* L, T& self, K& key) {
16917  return get_category(iterator_category(), L, self, key);
16918  }
16919 
16920  static error_result get_comparative(std::true_type, lua_State* L, T& self, K& key) {
16921  auto fx = [&](const value_type& r) -> bool {
16922  return key == get_key(is_associative(), r);
16923  };
16924  auto e = deferred_traits::end(L, self);
16925  auto it = std::find_if(deferred_traits::begin(L, self), e, std::ref(fx));
16926  if (it == e) {
16927  return stack::push(L, lua_nil);
16928  }
16929  return get_associative(is_associative(), L, it);
16930  }
16931 
16932  static error_result get_comparative(std::false_type, lua_State*, T&, K&) {
16933  return error_result("cannot get this key on '%s': no suitable way to increment iterator and compare to key value '%s'", detail::demangle<T>().data(), detail::demangle<K>().data());
16934  }
16935 
16936  static error_result get_it(std::false_type, lua_State* L, T& self, K& key) {
16937  return get_comparative(meta::supports_op_equal<K, key_type>(), L, self, key);
16938  }
16939 
16940  static error_result set_associative(std::true_type, iterator& it, stack_object value) {
16941  auto& v = *it;
16942  v.second = value.as<V>();
16943  return {};
16944  }
16945 
16946  static error_result set_associative(std::false_type, iterator& it, stack_object value) {
16947  auto& v = *it;
16948  v = value.as<V>();
16949  return {};
16950  }
16951 
16952  static error_result set_writable(std::true_type, lua_State*, T&, iterator& it, stack_object value) {
16953  return set_associative(is_associative(), it, std::move(value));
16954  }
16955 
16956  static error_result set_writable(std::false_type, lua_State*, T&, iterator&, stack_object) {
16957  return error_result("cannot perform a 'set': '%s's iterator reference is not writable (non-copy-assignable or const)", detail::demangle<T>().data());
16958  }
16959 
16960  static error_result set_category(std::input_iterator_tag, lua_State* L, T& self, stack_object okey, stack_object value) {
16961  decltype(auto) key = okey.as<K>();
16962  key += deferred_traits::index_adjustment(L, self);
16963  auto e = deferred_traits::end(L, self);
16964  auto it = deferred_traits::begin(L, self);
16965  auto backit = it;
16966  for (; key > 0 && it != e; --key, ++it) {
16967  backit = it;
16968  }
16969  if (it == e) {
16970  if (key == 0) {
16971  return add_copyable(is_copyable(), L, self, std::move(value), meta::has_insert_after<T>::value ? backit : it);
16972  }
16973  return error_result("out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
16974  }
16975  return set_writable(is_writable(), L, self, it, std::move(value));
16976  }
16977 
16978  static error_result set_category(std::random_access_iterator_tag, lua_State* L, T& self, stack_object okey, stack_object value) {
16979  decltype(auto) key = okey.as<K>();
16980  if (key <= 0) {
16981  return error_result("sol: out of bounds (too small) for set on '%s'", detail::demangle<T>().c_str());
16982  }
16983  key += deferred_traits::index_adjustment(L, self);
16984  std::ptrdiff_t len = static_cast<std::ptrdiff_t>(size_start(L, self));
16985  if (key == len) {
16986  return add_copyable(is_copyable(), L, self, std::move(value));
16987  }
16988  else if (key > len) {
16989  return error_result("sol: out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
16990  }
16991  auto it = std::next(deferred_traits::begin(L, self), key);
16992  return set_writable(is_writable(), L, self, it, std::move(value));
16993  }
16994 
16995  static error_result set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) {
16996  decltype(auto) key = okey.as<K>();
16997  if (!is_writable::value) {
16998  return error_result("cannot perform a 'set': '%s's iterator reference is not writable (non-copy-assignable or const)", detail::demangle<T>().data());
16999  }
17000  auto fx = [&](const value_type& r) -> bool {
17001  return key == get_key(is_associative(), r);
17002  };
17003  auto e = deferred_traits::end(L, self);
17004  auto it = std::find_if(deferred_traits::begin(L, self), e, std::ref(fx));
17005  if (it == e) {
17006  return {};
17007  }
17008  return set_writable(is_writable(), L, self, it, std::move(value));
17009  }
17010 
17011  static error_result set_comparative(std::false_type, lua_State*, T&, stack_object, stack_object) {
17012  return error_result("cannot set this value on '%s': no suitable way to increment iterator or compare to '%s' key", detail::demangle<T>().data(), detail::demangle<K>().data());
17013  }
17014 
17015  static error_result set_associative_insert(std::true_type, lua_State*, T& self, iterator& it, K& key, stack_object value) {
17016  self.insert(it, value_type(key, value.as<V>()));
17017  return {};
17018  }
17019 
17020  static error_result set_associative_insert(std::false_type, lua_State*, T& self, iterator& it, K& key, stack_object) {
17021  self.insert(it, key);
17022  return {};
17023  }
17024 
17025  static error_result set_associative_find(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) {
17026  decltype(auto) key = okey.as<K>();
17027  auto it = self.find(key);
17028  if (it == deferred_traits::end(L, self)) {
17029  return set_associative_insert(is_associative(), L, self, it, key, std::move(value));
17030  }
17031  return set_writable(is_writable(), L, self, it, std::move(value));
17032  }
17033 
17034  static error_result set_associative_find(std::false_type, lua_State* L, T& self, stack_object key, stack_object value) {
17035  return set_comparative(meta::supports_op_equal<K, key_type>(), L, self, std::move(key), std::move(value));
17036  }
17037 
17038  static error_result set_it(std::true_type, lua_State* L, T& self, stack_object key, stack_object value) {
17039  return set_category(iterator_category(), L, self, std::move(key), std::move(value));
17040  }
17041 
17042  static error_result set_it(std::false_type, lua_State* L, T& self, stack_object key, stack_object value) {
17043  return set_associative_find(meta::all<has_find<T>, meta::any<is_associative, is_lookup>>(), L, self, std::move(key), std::move(value));
17044  }
17045 
17046  static error_result find_has_associative_lookup(std::true_type, lua_State* L, T& self) {
17047  decltype(auto) key = stack::unqualified_get<K>(L, 2);
17048  auto it = self.find(key);
17049  if (it == deferred_traits::end(L, self)) {
17050  return stack::push(L, lua_nil);
17051  }
17052  return get_associative(is_associative(), L, it);
17053  }
17054 
17055  static error_result find_has_associative_lookup(std::false_type, lua_State* L, T& self) {
17056  decltype(auto) value = stack::unqualified_get<V>(L, 2);
17057  auto it = self.find(value);
17058  if (it == deferred_traits::end(L, self)) {
17059  return stack::push(L, lua_nil);
17060  }
17061  return get_associative(is_associative(), L, it);
17062  }
17063 
17064  static error_result find_has(std::true_type, lua_State* L, T& self) {
17065  return find_has_associative_lookup(meta::any<is_lookup, is_associative>(), L, self);
17066  }
17067 
17068  static error_result find_associative_lookup(std::true_type, lua_State* L, iterator& it, std::size_t) {
17069  return get_associative(is_associative(), L, it);
17070  }
17071 
17072  static error_result find_associative_lookup(std::false_type, lua_State* L, iterator&, std::size_t index) {
17073  return stack::push(L, index);
17074  }
17075 
17076  static error_result find_comparative(std::false_type, lua_State*, T&) {
17077  return error_result("cannot call 'find' on '%s': there is no 'find' function and the value_type is not equality comparable", detail::demangle<T>().c_str());
17078  }
17079 
17080  static error_result find_comparative(std::true_type, lua_State* L, T& self) {
17081  decltype(auto) value = stack::unqualified_get<V>(L, 2);
17082  auto it = deferred_traits::begin(L, self);
17083  auto e = deferred_traits::end(L, self);
17084  std::size_t index = 1;
17085  for (;; ++it, ++index) {
17086  if (it == e) {
17087  return stack::push(L, lua_nil);
17088  }
17089  if (value == get_value(is_associative(), *it)) {
17090  break;
17091  }
17092  }
17093  return find_associative_lookup(meta::any<is_lookup, is_associative>(), L, it, index);
17094  }
17095 
17096  static error_result find_has(std::false_type, lua_State* L, T& self) {
17097  return find_comparative(meta::supports_op_equal<V>(), L, self);
17098  }
17099 
17100  static error_result add_insert_after(std::false_type, lua_State* L, T& self, stack_object value, iterator&) {
17101  return add_insert_after(std::false_type(), L, self, value);
17102  }
17103 
17104  static error_result add_insert_after(std::false_type, lua_State*, T&, stack_object) {
17105  return error_result("cannot call 'add' on type '%s': no suitable insert/push_back C++ functions", detail::demangle<T>().data());
17106  }
17107 
17108  static error_result add_insert_after(std::true_type, lua_State*, T& self, stack_object value, iterator& pos) {
17109  self.insert_after(pos, value.as<V>());
17110  return {};
17111  }
17112 
17113  static error_result add_insert_after(std::true_type, lua_State* L, T& self, stack_object value) {
17114  auto backit = self.before_begin();
17115  {
17116  auto e = deferred_traits::end(L, self);
17117  for (auto it = deferred_traits::begin(L, self); it != e; ++backit, ++it) {
17118  }
17119  }
17120  return add_insert_after(std::true_type(), L, self, value, backit);
17121  }
17122 
17123  static error_result add_insert(std::true_type, lua_State*, T& self, stack_object value, iterator& pos) {
17124  self.insert(pos, value.as<V>());
17125  return {};
17126  }
17127 
17128  static error_result add_insert(std::true_type, lua_State* L, T& self, stack_object value) {
17129  auto pos = deferred_traits::end(L, self);
17130  return add_insert(std::true_type(), L, self, value, pos);
17131  }
17132 
17133  static error_result add_insert(std::false_type, lua_State* L, T& self, stack_object value, iterator& pos) {
17134  return add_insert_after(meta::has_insert_after<T>(), L, self, std::move(value), pos);
17135  }
17136 
17137  static error_result add_insert(std::false_type, lua_State* L, T& self, stack_object value) {
17138  return add_insert_after(meta::has_insert_after<T>(), L, self, std::move(value));
17139  }
17140 
17141  static error_result add_push_back(std::true_type, lua_State*, T& self, stack_object value, iterator&) {
17142  self.push_back(value.as<V>());
17143  return {};
17144  }
17145 
17146  static error_result add_push_back(std::true_type, lua_State*, T& self, stack_object value) {
17147  self.push_back(value.as<V>());
17148  return {};
17149  }
17150 
17151  static error_result add_push_back(std::false_type, lua_State* L, T& self, stack_object value, iterator& pos) {
17152  return add_insert(meta::has_insert<T>(), L, self, value, pos);
17153  }
17154 
17155  static error_result add_push_back(std::false_type, lua_State* L, T& self, stack_object value) {
17156  return add_insert(meta::has_insert<T>(), L, self, value);
17157  }
17158 
17159  static error_result add_associative(std::true_type, lua_State* L, T& self, stack_object key, iterator& pos) {
17160  self.insert(pos, value_type(key.as<K>(), stack::unqualified_get<V>(L, 3)));
17161  return {};
17162  }
17163 
17164  static error_result add_associative(std::true_type, lua_State* L, T& self, stack_object key) {
17165  auto pos = deferred_traits::end(L, self);
17166  return add_associative(std::true_type(), L, self, std::move(key), pos);
17167  }
17168 
17169  static error_result add_associative(std::false_type, lua_State* L, T& self, stack_object value, iterator& pos) {
17170  return add_push_back(meta::has_push_back<T>(), L, self, value, pos);
17171  }
17172 
17173  static error_result add_associative(std::false_type, lua_State* L, T& self, stack_object value) {
17174  return add_push_back(meta::has_push_back<T>(), L, self, value);
17175  }
17176 
17177  static error_result add_copyable(std::true_type, lua_State* L, T& self, stack_object value, iterator& pos) {
17178  return add_associative(is_associative(), L, self, std::move(value), pos);
17179  }
17180 
17181  static error_result add_copyable(std::true_type, lua_State* L, T& self, stack_object value) {
17182  return add_associative(is_associative(), L, self, value);
17183  }
17184 
17185  static error_result add_copyable(std::false_type, lua_State* L, T& self, stack_object value, iterator&) {
17186  return add_copyable(std::false_type(), L, self, std::move(value));
17187  }
17188 
17189  static error_result add_copyable(std::false_type, lua_State*, T&, stack_object) {
17190  return error_result("cannot call 'add' on '%s': value_type is non-copyable", detail::demangle<T>().data());
17191  }
17192 
17193  static error_result insert_lookup(std::true_type, lua_State* L, T& self, stack_object, stack_object value) {
17194  // TODO: should we warn or error about someone calling insert on an ordered / lookup container with no associativity?
17195  return add_copyable(std::true_type(), L, self, std::move(value));
17196  }
17197 
17198  static error_result insert_lookup(std::false_type, lua_State* L, T& self, stack_object where, stack_object value) {
17199  auto it = deferred_traits::begin(L, self);
17200  auto key = where.as<K>();
17201  key += deferred_traits::index_adjustment(L, self);
17202  std::advance(it, key);
17203  self.insert(it, value.as<V>());
17204  return {};
17205  }
17206 
17207  static error_result insert_after_has(std::true_type, lua_State* L, T& self, stack_object where, stack_object value) {
17208  auto key = where.as<K>();
17209  auto backit = self.before_begin();
17210  {
17211  key += deferred_traits::index_adjustment(L, self);
17212  auto e = deferred_traits::end(L, self);
17213  for (auto it = deferred_traits::begin(L, self); key > 0; ++backit, ++it, --key) {
17214  if (backit == e) {
17215  return error_result("sol: out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
17216  }
17217  }
17218  }
17219  self.insert_after(backit, value.as<V>());
17220  return {};
17221  }
17222 
17223  static error_result insert_after_has(std::false_type, lua_State*, T&, stack_object, stack_object) {
17224  return error_result("cannot call 'insert' on '%s': no suitable or similar functionality detected on this container", detail::demangle<T>().data());
17225  }
17226 
17227  static error_result insert_has(std::true_type, lua_State* L, T& self, stack_object key, stack_object value) {
17228  return insert_lookup(meta::any<is_associative, is_lookup>(), L, self, std::move(key), std::move(value));
17229  }
17230 
17231  static error_result insert_has(std::false_type, lua_State* L, T& self, stack_object where, stack_object value) {
17232  return insert_after_has(meta::has_insert_after<T>(), L, self, where, value);
17233  }
17234 
17235  static error_result insert_copyable(std::true_type, lua_State* L, T& self, stack_object key, stack_object value) {
17236  return insert_has(meta::has_insert<T>(), L, self, std::move(key), std::move(value));
17237  }
17238 
17239  static error_result insert_copyable(std::false_type, lua_State*, T&, stack_object, stack_object) {
17240  return error_result("cannot call 'insert' on '%s': value_type is non-copyable", detail::demangle<T>().data());
17241  }
17242 
17243  static error_result erase_integral(std::true_type, lua_State* L, T& self, K& key) {
17244  auto it = deferred_traits::begin(L, self);
17245  key += deferred_traits::index_adjustment(L, self);
17246  std::advance(it, key);
17247  self.erase(it);
17248 
17249  return {};
17250  }
17251 
17252  static error_result erase_integral(std::false_type, lua_State* L, T& self, const K& key) {
17253  auto fx = [&](const value_type& r) -> bool {
17254  return key == r;
17255  };
17256  auto e = deferred_traits::end(L, self);
17257  auto it = std::find_if(deferred_traits::begin(L, self), e, std::ref(fx));
17258  if (it == e) {
17259  return {};
17260  }
17261  self.erase(it);
17262 
17263  return {};
17264  }
17265 
17266  static error_result erase_associative_lookup(std::true_type, lua_State*, T& self, const K& key) {
17267  self.erase(key);
17268  return {};
17269  }
17270 
17271  static error_result erase_associative_lookup(std::false_type, lua_State* L, T& self, K& key) {
17272  return erase_integral(std::is_integral<K>(), L, self, key);
17273  }
17274 
17275  static error_result erase_after_has(std::true_type, lua_State* L, T& self, K& key) {
17276  auto backit = self.before_begin();
17277  {
17278  key += deferred_traits::index_adjustment(L, self);
17279  auto e = deferred_traits::end(L, self);
17280  for (auto it = deferred_traits::begin(L, self); key > 0; ++backit, ++it, --key) {
17281  if (backit == e) {
17282  return error_result("sol: out of bounds for erase on '%s'", detail::demangle<T>().c_str());
17283  }
17284  }
17285  }
17286  self.erase_after(backit);
17287  return {};
17288  }
17289 
17290  static error_result erase_after_has(std::false_type, lua_State*, T&, const K&) {
17291  return error_result("sol: cannot call erase on '%s'", detail::demangle<T>().c_str());
17292  }
17293 
17294  static error_result erase_has(std::true_type, lua_State* L, T& self, K& key) {
17295  return erase_associative_lookup(meta::any<is_associative, is_lookup>(), L, self, key);
17296  }
17297 
17298  static error_result erase_has(std::false_type, lua_State* L, T& self, K& key) {
17299  return erase_after_has(has_erase_after<T>(), L, self, key);
17300  }
17301 
17302  static auto size_has(std::false_type, lua_State* L, T& self) {
17303  return std::distance(deferred_traits::begin(L, self), deferred_traits::end(L, self));
17304  }
17305 
17306  static auto size_has(std::true_type, lua_State*, T& self) {
17307  return self.size();
17308  }
17309 
17310  static void clear_has(std::true_type, lua_State*, T& self) {
17311  self.clear();
17312  }
17313 
17314  static void clear_has(std::false_type, lua_State* L, T&) {
17315  luaL_error(L, "sol: cannot call clear on '%s'", detail::demangle<T>().c_str());
17316  }
17317 
17318  static bool empty_has(std::true_type, lua_State*, T& self) {
17319  return self.empty();
17320  }
17321 
17322  static bool empty_has(std::false_type, lua_State* L, T& self) {
17323  return deferred_traits::begin(L, self) == deferred_traits::end(L, self);
17324  }
17325 
17326  static error_result get_start(lua_State* L, T& self, K& key) {
17327  return get_it(is_linear_integral(), L, self, key);
17328  }
17329 
17330  static error_result set_start(lua_State* L, T& self, stack_object key, stack_object value) {
17331  return set_it(is_linear_integral(), L, self, std::move(key), std::move(value));
17332  }
17333 
17334  static std::size_t size_start(lua_State* L, T& self) {
17335  return size_has(meta::has_size<T>(), L, self);
17336  }
17337 
17338  static void clear_start(lua_State* L, T& self) {
17339  clear_has(has_clear<T>(), L, self);
17340  }
17341 
17342  static bool empty_start(lua_State* L, T& self) {
17343  return empty_has(has_empty<T>(), L, self);
17344  }
17345 
17346  static error_result erase_start(lua_State* L, T& self, K& key) {
17347  return erase_has(has_erase<T>(), L, self, key);
17348  }
17349 
17350  template <bool ip>
17351  static int next_associative(std::true_type, lua_State* L) {
17352  iter& i = stack::unqualified_get<user<iter>>(L, 1);
17353  auto& source = i.source;
17354  auto& it = i.it;
17355  if (it == deferred_traits::end(L, source)) {
17356  return 0;
17357  }
17358  int p;
17359  if (ip) {
17360  ++i.i;
17361  p = stack::push_reference(L, i.i);
17362  }
17363  else {
17364  p = stack::push_reference(L, it->first);
17365  }
17366  p += stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(it->second));
17367  std::advance(it, 1);
17368  return p;
17369  }
17370 
17371  template <bool>
17372  static int next_associative(std::false_type, lua_State* L) {
17373  iter& i = stack::unqualified_get<user<iter>>(L, 1);
17374  auto& source = i.source;
17375  auto& it = i.it;
17376  next_K k = stack::unqualified_get<next_K>(L, 2);
17377  if (it == deferred_traits::end(L, source)) {
17378  return 0;
17379  }
17380  int p;
17381  p = stack::push_reference(L, k + 1);
17382  p += stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(*it));
17383  std::advance(it, 1);
17384  return p;
17385  }
17386 
17387  template <bool ip>
17388  static int next_iter(lua_State* L) {
17390  return next_associative<ip>(is_assoc(), L);
17391  }
17392 
17393  template <bool ip>
17394  static int pairs_associative(std::true_type, lua_State* L) {
17395  auto& src = get_src(L);
17396  stack::push(L, next_iter<ip>);
17397  stack::push<user<iter>>(L, src, deferred_traits::begin(L, src));
17398  stack::push(L, lua_nil);
17399  return 3;
17400  }
17401 
17402  template <bool ip>
17403  static int pairs_associative(std::false_type, lua_State* L) {
17404  auto& src = get_src(L);
17405  stack::push(L, next_iter<ip>);
17406  stack::push<user<iter>>(L, src, deferred_traits::begin(L, src));
17407  stack::push(L, 0);
17408  return 3;
17409  }
17410 
17411  public:
17412  static int at(lua_State* L) {
17413  auto& self = get_src(L);
17414  error_result er;
17415  {
17416  std::ptrdiff_t pos = stack::unqualified_get<std::ptrdiff_t>(L);
17417  er = at_start(L, self, pos);
17418  }
17419  return handle_errors(L, er);
17420  }
17421 
17422  static int get(lua_State* L) {
17423  auto& self = get_src(L);
17424  error_result er;
17425  {
17426  decltype(auto) key = stack::unqualified_get<K>(L);
17427  er = get_start(L, self, key);
17428  }
17429  return handle_errors(L, er);
17430  }
17431 
17432  static int index_get(lua_State* L) {
17433  return get(L);
17434  }
17435 
17436  static int set(lua_State* L) {
17437  stack_object value = stack_object(L, raw_index(3));
17438  if (type_of(L, 3) == type::lua_nil) {
17439  return erase(L);
17440  }
17441  auto& self = get_src(L);
17442  error_result er = set_start(L, self, stack_object(L, raw_index(2)), std::move(value));
17443  return handle_errors(L, er);
17444  }
17445 
17446  static int index_set(lua_State* L) {
17447  return set(L);
17448  }
17449 
17450  static int add(lua_State* L) {
17451  auto& self = get_src(L);
17452  error_result er = add_copyable(is_copyable(), L, self, stack_object(L, raw_index(2)));
17453  return handle_errors(L, er);
17454  }
17455 
17456  static int insert(lua_State* L) {
17457  auto& self = get_src(L);
17458  error_result er = insert_copyable(is_copyable(), L, self, stack_object(L, raw_index(2)), stack_object(L, raw_index(3)));
17459  return handle_errors(L, er);
17460  }
17461 
17462  static int find(lua_State* L) {
17463  auto& self = get_src(L);
17464  error_result er = find_has(has_find<T>(), L, self);
17465  return handle_errors(L, er);
17466  }
17467 
17468  static iterator begin(lua_State*, T& self) {
17469  using std::begin;
17470  return begin(self);
17471  }
17472 
17473  static iterator end(lua_State*, T& self) {
17474  using std::end;
17475  return end(self);
17476  }
17477 
17478  static int size(lua_State* L) {
17479  auto& self = get_src(L);
17480  std::size_t r = size_start(L, self);
17481  return stack::push(L, r);
17482  }
17483 
17484  static int clear(lua_State* L) {
17485  auto& self = get_src(L);
17486  clear_start(L, self);
17487  return 0;
17488  }
17489 
17490  static int erase(lua_State* L) {
17491  auto& self = get_src(L);
17492  error_result er;
17493  {
17494  decltype(auto) key = stack::unqualified_get<K>(L, 2);
17495  er = erase_start(L, self, key);
17496  }
17497  return handle_errors(L, er);
17498  }
17499 
17500  static int empty(lua_State* L) {
17501  auto& self = get_src(L);
17502  return stack::push(L, empty_start(L, self));
17503  }
17504 
17505  static std::ptrdiff_t index_adjustment(lua_State*, T&) {
17506 #if defined(SOL_CONTAINERS_START_INDEX)
17507  return static_cast<std::ptrdiff_t>((SOL_CONTAINERS_START) == 0 ? 0 : -(SOL_CONTAINERS_START));
17508 #else
17509  return static_cast<std::ptrdiff_t>(-1);
17510 #endif
17511  }
17512 
17513  static int pairs(lua_State* L) {
17515  return pairs_associative<false>(is_assoc(), L);
17516  }
17517 
17518  static int ipairs(lua_State* L) {
17520  return pairs_associative<true>(is_assoc(), L);
17521  }
17522 
17523  static int next(lua_State* L) {
17524  return stack::push(L, next_iter<false>);
17525  }
17526  };
17527 
17528  template <typename X>
17529  struct container_traits_default<X, std::enable_if_t<std::is_array<std::remove_pointer_t<meta::unwrap_unqualified_t<X>>>::value>> {
17530  private:
17531  typedef std::remove_pointer_t<meta::unwrap_unqualified_t<X>> T;
17533 
17534  public:
17535  typedef std::remove_extent_t<T> value_type;
17536  typedef value_type* iterator;
17537 
17538  private:
17539  struct iter {
17541  iterator it;
17542 
17543  iter(T& source, iterator it)
17544  : source(source), it(std::move(it)) {
17545  }
17546  };
17547 
17548  static auto& get_src(lua_State* L) {
17549  auto p = stack::unqualified_check_get<T*>(L, 1);
17550 #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
17551  if (!p) {
17552  luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle<T>().c_str());
17553  }
17554  if (p.value() == nullptr) {
17555  luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument with ':' or call on a '%s' type)", detail::demangle<T>().c_str());
17556  }
17557 #endif // Safe getting with error
17558  return *p.value();
17559  }
17560 
17561  static int find(std::true_type, lua_State* L) {
17562  T& self = get_src(L);
17563  decltype(auto) value = stack::unqualified_get<value_type>(L, 2);
17564  std::size_t N = std::extent<T>::value;
17565  for (std::size_t idx = 0; idx < N; ++idx) {
17566  const auto& v = self[idx];
17567  if (v == value) {
17568  return stack::push(L, idx + 1);
17569  }
17570  }
17571  return stack::push(L, lua_nil);
17572  }
17573 
17574  static int find(std::false_type, lua_State* L) {
17575  return luaL_error(L, "sol: cannot call 'find' on '%s': no supported comparison operator for the value type", detail::demangle<T>().c_str());
17576  }
17577 
17578  static int next_iter(lua_State* L) {
17579  iter& i = stack::unqualified_get<user<iter>>(L, 1);
17580  auto& source = i.source;
17581  auto& it = i.it;
17582  std::size_t k = stack::unqualified_get<std::size_t>(L, 2);
17583  if (it == deferred_traits::end(L, source)) {
17584  return 0;
17585  }
17586  int p;
17587  p = stack::push_reference(L, k + 1);
17589  std::advance(it, 1);
17590  return p;
17591  }
17592 
17593  public:
17594  static int clear(lua_State* L) {
17595  return luaL_error(L, "sol: cannot call 'clear' on type '%s': cannot remove all items from a fixed array", detail::demangle<T>().c_str());
17596  }
17597 
17598  static int erase(lua_State* L) {
17599  return luaL_error(L, "sol: cannot call 'erase' on type '%s': cannot remove an item from fixed arrays", detail::demangle<T>().c_str());
17600  }
17601 
17602  static int add(lua_State* L) {
17603  return luaL_error(L, "sol: cannot call 'add' on type '%s': cannot add to fixed arrays", detail::demangle<T>().c_str());
17604  }
17605 
17606  static int insert(lua_State* L) {
17607  return luaL_error(L, "sol: cannot call 'insert' on type '%s': cannot insert new entries into fixed arrays", detail::demangle<T>().c_str());
17608  }
17609 
17610  static int at(lua_State* L) {
17611  return get(L);
17612  }
17613 
17614  static int get(lua_State* L) {
17615  T& self = get_src(L);
17616  std::ptrdiff_t idx = stack::unqualified_get<std::ptrdiff_t>(L, 2);
17617  idx += deferred_traits::index_adjustment(L, self);
17618  if (idx >= static_cast<std::ptrdiff_t>(std::extent<T>::value) || idx < 0) {
17619  return stack::push(L, lua_nil);
17620  }
17621  return stack::push_reference(L, detail::deref_non_pointer(self[idx]));
17622  }
17623 
17624  static int index_get(lua_State* L) {
17625  return get(L);
17626  }
17627 
17628  static int set(lua_State* L) {
17629  T& self = get_src(L);
17630  std::ptrdiff_t idx = stack::unqualified_get<std::ptrdiff_t>(L, 2);
17631  idx += deferred_traits::index_adjustment(L, self);
17632  if (idx >= static_cast<std::ptrdiff_t>(std::extent<T>::value)) {
17633  return luaL_error(L, "sol: index out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
17634  }
17635  if (idx < 0) {
17636  return luaL_error(L, "sol: index out of bounds (too small) for set on '%s'", detail::demangle<T>().c_str());
17637  }
17638  self[idx] = stack::unqualified_get<value_type>(L, 3);
17639  return 0;
17640  }
17641 
17642  static int index_set(lua_State* L) {
17643  return set(L);
17644  }
17645 
17646  static int find(lua_State* L) {
17648  }
17649 
17650  static int size(lua_State* L) {
17651  return stack::push(L, std::extent<T>::value);
17652  }
17653 
17654  static int empty(lua_State* L) {
17655  return stack::push(L, std::extent<T>::value > 0);
17656  }
17657 
17658  static int pairs(lua_State* L) {
17659  auto& src = get_src(L);
17660  stack::push(L, next_iter);
17661  stack::push<user<iter>>(L, src, deferred_traits::begin(L, src));
17662  stack::push(L, 0);
17663  return 3;
17664  }
17665 
17666  static int ipairs(lua_State* L) {
17667  return pairs(L);
17668  }
17669 
17670  static int next(lua_State* L) {
17671  return stack::push(L, next_iter);
17672  }
17673 
17674  static std::ptrdiff_t index_adjustment(lua_State*, T&) {
17675 #if defined(SOL_CONTAINERS_START_INDEX)
17676  return (SOL_CONTAINERS_START) == 0 ? 0 : -(SOL_CONTAINERS_START);
17677 #else
17678  return -1;
17679 #endif
17680  }
17681 
17682  static iterator begin(lua_State*, T& self) {
17683  return std::addressof(self[0]);
17684  }
17685 
17686  static iterator end(lua_State*, T& self) {
17687  return std::addressof(self[0]) + std::extent<T>::value;
17688  }
17689  };
17690 
17691  template <typename X>
17693  } // namespace container_detail
17694 
17695  template <typename T>
17697 
17698 } // namespace sol
17699 
17700 // end of sol/container_traits.hpp
17701 
17702 namespace sol {
17703 
17704  template <typename X>
17706  typedef std::remove_pointer_t<meta::unqualified_t<X>> T;
17709 
17710  static int real_index_get_traits(std::true_type, lua_State* L) {
17711  return traits::index_get(L);
17712  }
17713 
17714  static int real_index_get_traits(std::false_type, lua_State* L) {
17715  return default_traits::index_get(L);
17716  }
17717 
17718  static int real_index_call(lua_State* L) {
17720  static const call_map calls{
17721  { "at", &at_call },
17722  { "get", &real_get_call },
17723  { "set", &real_set_call },
17724  { "size", &real_length_call },
17725  { "add", &real_add_call },
17726  { "empty", &real_empty_call },
17727  { "insert", &real_insert_call },
17728  { "clear", &real_clear_call },
17729  { "find", &real_find_call },
17730  { "erase", &real_erase_call },
17731  { "pairs", &pairs_call },
17732  { "next", &next_call },
17733  };
17734  auto maybenameview = stack::unqualified_check_get<string_view>(L, 2);
17735  if (maybenameview) {
17736  const string_view& nameview = *maybenameview;
17737 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
17738  auto it = calls.find(nameview, string_view_hash(), std::equal_to<string_view>());
17739 #else
17740  std::string name(nameview.data(), nameview.size());
17741  auto it = calls.find(name);
17742 #endif
17743  if (it != calls.cend()) {
17744  return stack::push(L, it->second);
17745  }
17746  }
17747  return real_index_get_traits(container_detail::has_traits_index_get<traits>(), L);
17748  }
17749 
17750  static int real_at_traits(std::true_type, lua_State* L) {
17751  return traits::at(L);
17752  }
17753 
17754  static int real_at_traits(std::false_type, lua_State* L) {
17755  return default_traits::at(L);
17756  }
17757 
17758  static int real_at_call(lua_State* L) {
17759  return real_at_traits(container_detail::has_traits_at<traits>(), L);
17760  }
17761 
17762  static int real_get_traits(std::true_type, lua_State* L) {
17763  return traits::get(L);
17764  }
17765 
17766  static int real_get_traits(std::false_type, lua_State* L) {
17767  return default_traits::get(L);
17768  }
17769 
17770  static int real_get_call(lua_State* L) {
17771  return real_get_traits(container_detail::has_traits_get<traits>(), L);
17772  }
17773 
17774  static int real_set_traits(std::true_type, lua_State* L) {
17775  return traits::set(L);
17776  }
17777 
17778  static int real_set_traits(std::false_type, lua_State* L) {
17779  return default_traits::set(L);
17780  }
17781 
17782  static int real_set_call(lua_State* L) {
17783  return real_set_traits(container_detail::has_traits_set<traits>(), L);
17784  }
17785 
17786  static int real_index_set_traits(std::true_type, lua_State* L) {
17787  return traits::index_set(L);
17788  }
17789 
17790  static int real_index_set_traits(std::false_type, lua_State* L) {
17791  return default_traits::index_set(L);
17792  }
17793 
17794  static int real_new_index_call(lua_State* L) {
17795  return real_index_set_traits(container_detail::has_traits_index_set<traits>(), L);
17796  }
17797 
17798  static int real_pairs_traits(std::true_type, lua_State* L) {
17799  return traits::pairs(L);
17800  }
17801 
17802  static int real_pairs_traits(std::false_type, lua_State* L) {
17803  return default_traits::pairs(L);
17804  }
17805 
17806  static int real_pairs_call(lua_State* L) {
17807  return real_pairs_traits(container_detail::has_traits_pairs<traits>(), L);
17808  }
17809 
17810  static int real_ipairs_traits(std::true_type, lua_State* L) {
17811  return traits::ipairs(L);
17812  }
17813 
17814  static int real_ipairs_traits(std::false_type, lua_State* L) {
17815  return default_traits::ipairs(L);
17816  }
17817 
17818  static int real_ipairs_call(lua_State* L) {
17819  return real_ipairs_traits(container_detail::has_traits_ipairs<traits>(), L);
17820  }
17821 
17822  static int real_next_traits(std::true_type, lua_State* L) {
17823  return traits::next(L);
17824  }
17825 
17826  static int real_next_traits(std::false_type, lua_State* L) {
17827  return default_traits::next(L);
17828  }
17829 
17830  static int real_next_call(lua_State* L) {
17831  return real_next_traits(container_detail::has_traits_next<traits>(), L);
17832  }
17833 
17834  static int real_size_traits(std::true_type, lua_State* L) {
17835  return traits::size(L);
17836  }
17837 
17838  static int real_size_traits(std::false_type, lua_State* L) {
17839  return default_traits::size(L);
17840  }
17841 
17842  static int real_length_call(lua_State* L) {
17843  return real_size_traits(container_detail::has_traits_size<traits>(), L);
17844  }
17845 
17846  static int real_add_traits(std::true_type, lua_State* L) {
17847  return traits::add(L);
17848  }
17849 
17850  static int real_add_traits(std::false_type, lua_State* L) {
17851  return default_traits::add(L);
17852  }
17853 
17854  static int real_add_call(lua_State* L) {
17855  return real_add_traits(container_detail::has_traits_add<traits>(), L);
17856  }
17857 
17858  static int real_insert_traits(std::true_type, lua_State* L) {
17859  return traits::insert(L);
17860  }
17861 
17862  static int real_insert_traits(std::false_type, lua_State* L) {
17863  return default_traits::insert(L);
17864  }
17865 
17866  static int real_insert_call(lua_State* L) {
17867  return real_insert_traits(container_detail::has_traits_insert<traits>(), L);
17868  }
17869 
17870  static int real_clear_traits(std::true_type, lua_State* L) {
17871  return traits::clear(L);
17872  }
17873 
17874  static int real_clear_traits(std::false_type, lua_State* L) {
17875  return default_traits::clear(L);
17876  }
17877 
17878  static int real_clear_call(lua_State* L) {
17879  return real_clear_traits(container_detail::has_traits_clear<traits>(), L);
17880  }
17881 
17882  static int real_empty_traits(std::true_type, lua_State* L) {
17883  return traits::empty(L);
17884  }
17885 
17886  static int real_empty_traits(std::false_type, lua_State* L) {
17887  return default_traits::empty(L);
17888  }
17889 
17890  static int real_empty_call(lua_State* L) {
17891  return real_empty_traits(container_detail::has_traits_empty<traits>(), L);
17892  }
17893 
17894  static int real_erase_traits(std::true_type, lua_State* L) {
17895  return traits::erase(L);
17896  }
17897 
17898  static int real_erase_traits(std::false_type, lua_State* L) {
17899  return default_traits::erase(L);
17900  }
17901 
17902  static int real_erase_call(lua_State* L) {
17903  return real_erase_traits(container_detail::has_traits_erase<traits>(), L);
17904  }
17905 
17906  static int real_find_traits(std::true_type, lua_State* L) {
17907  return traits::find(L);
17908  }
17909 
17910  static int real_find_traits(std::false_type, lua_State* L) {
17911  return default_traits::find(L);
17912  }
17913 
17914  static int real_find_call(lua_State* L) {
17915  return real_find_traits(container_detail::has_traits_find<traits>(), L);
17916  }
17917 
17918  static int add_call(lua_State* L) {
17919  return detail::typed_static_trampoline<decltype(&real_add_call), (&real_add_call)>(L);
17920  }
17921 
17922  static int erase_call(lua_State* L) {
17923  return detail::typed_static_trampoline<decltype(&real_erase_call), (&real_erase_call)>(L);
17924  }
17925 
17926  static int insert_call(lua_State* L) {
17927  return detail::typed_static_trampoline<decltype(&real_insert_call), (&real_insert_call)>(L);
17928  }
17929 
17930  static int clear_call(lua_State* L) {
17931  return detail::typed_static_trampoline<decltype(&real_clear_call), (&real_clear_call)>(L);
17932  }
17933 
17934  static int empty_call(lua_State* L) {
17935  return detail::typed_static_trampoline<decltype(&real_empty_call), (&real_empty_call)>(L);
17936  }
17937 
17938  static int find_call(lua_State* L) {
17939  return detail::typed_static_trampoline<decltype(&real_find_call), (&real_find_call)>(L);
17940  }
17941 
17942  static int length_call(lua_State* L) {
17943  return detail::typed_static_trampoline<decltype(&real_length_call), (&real_length_call)>(L);
17944  }
17945 
17946  static int pairs_call(lua_State* L) {
17947  return detail::typed_static_trampoline<decltype(&real_pairs_call), (&real_pairs_call)>(L);
17948  }
17949 
17950  static int ipairs_call(lua_State* L) {
17951  return detail::typed_static_trampoline<decltype(&real_ipairs_call), (&real_ipairs_call)>(L);
17952  }
17953 
17954  static int next_call(lua_State* L) {
17955  return detail::typed_static_trampoline<decltype(&real_next_call), (&real_next_call)>(L);
17956  }
17957 
17958  static int at_call(lua_State* L) {
17959  return detail::typed_static_trampoline<decltype(&real_at_call), (&real_at_call)>(L);
17960  }
17961 
17962  static int get_call(lua_State* L) {
17963  return detail::typed_static_trampoline<decltype(&real_get_call), (&real_get_call)>(L);
17964  }
17965 
17966  static int set_call(lua_State* L) {
17967  return detail::typed_static_trampoline<decltype(&real_set_call), (&real_set_call)>(L);
17968  }
17969 
17970  static int index_call(lua_State* L) {
17971  return detail::typed_static_trampoline<decltype(&real_index_call), (&real_index_call)>(L);
17972  }
17973 
17974  static int new_index_call(lua_State* L) {
17975  return detail::typed_static_trampoline<decltype(&real_new_index_call), (&real_new_index_call)>(L);
17976  }
17977  };
17978 
17979  namespace stack {
17980  namespace stack_detail {
17981  template <typename T, bool is_shim = false>
17983  lua_State* L;
17984 
17985  metatable_setup(lua_State* L)
17986  : L(L) {
17987  }
17988 
17989  void operator()() {
17990  typedef container_usertype_metatable<std::conditional_t<is_shim,
17992  std::remove_pointer_t<T>>>
17993  meta_cumt;
17994  static const char* metakey = is_shim ? &usertype_traits<as_container_t<std::remove_pointer_t<T>>>::metatable()[0] : &usertype_traits<T>::metatable()[0];
17995  static const std::array<luaL_Reg, 19> reg = { {
17996  { "__pairs", &meta_cumt::pairs_call },
17997  { "__ipairs", &meta_cumt::ipairs_call },
17998  { "__len", &meta_cumt::length_call },
17999  { "__index", &meta_cumt::index_call },
18000  { "__newindex", &meta_cumt::new_index_call },
18001  { "pairs", &meta_cumt::pairs_call },
18002  { "next", &meta_cumt::next_call },
18003  { "at", &meta_cumt::at_call },
18004  { "get", &meta_cumt::get_call },
18005  { "set", &meta_cumt::set_call },
18006  { "size", &meta_cumt::length_call },
18007  { "empty", &meta_cumt::empty_call },
18008  { "clear", &meta_cumt::clear_call },
18009  { "insert", &meta_cumt::insert_call },
18010  { "add", &meta_cumt::add_call },
18011  { "find", &meta_cumt::find_call },
18012  { "erase", &meta_cumt::erase_call },
18013  std::is_pointer<T>::value ? luaL_Reg{ nullptr, nullptr } : luaL_Reg{ "__gc", &detail::usertype_alloc_destruct<T> },
18014  { nullptr, nullptr }
18015  } };
18016 
18017  if (luaL_newmetatable(L, metakey) == 1) {
18018  luaL_setfuncs(L, reg.data(), 0);
18019  }
18020  lua_setmetatable(L, -2);
18021  }
18022  };
18023  } // namespace stack_detail
18024 
18025  template <typename T>
18026  struct pusher<as_container_t<T>> {
18028 
18029  static int push_lvalue(std::true_type, lua_State* L, const C& cont) {
18031  return pusher<detail::as_pointer_tag<const C>>{}.push_fx(L, fx, detail::ptr(cont));
18032  }
18033 
18034  static int push_lvalue(std::false_type, lua_State* L, const C& cont) {
18036  return pusher<detail::as_value_tag<C>>{}.push_fx(L, fx, cont);
18037  }
18038 
18039  static int push_rvalue(std::true_type, lua_State* L, C&& cont) {
18041  return pusher<detail::as_value_tag<C>>{}.push_fx(L, fx, std::move(cont));
18042  }
18043 
18044  static int push_rvalue(std::false_type, lua_State* L, const C& cont) {
18045  return push_lvalue(std::is_lvalue_reference<T>(), L, cont);
18046  }
18047 
18048  static int push(lua_State* L, const as_container_t<T>& as_cont) {
18049  return push_lvalue(std::is_lvalue_reference<T>(), L, as_cont.source);
18050  }
18051 
18052  static int push(lua_State* L, as_container_t<T>&& as_cont) {
18053  return push_rvalue(meta::all<std::is_rvalue_reference<T>, meta::neg<std::is_lvalue_reference<T>>>(), L, std::forward<T>(as_cont.source));
18054  }
18055  };
18056 
18057  template <typename T>
18058  struct pusher<as_container_t<T*>> {
18059  typedef std::add_pointer_t<meta::unqualified_t<std::remove_pointer_t<T>>> C;
18060 
18061  static int push(lua_State* L, T* cont) {
18063  return pusher<detail::as_pointer_tag<T>>{}.push_fx(L, fx, cont);
18064  }
18065  };
18066 
18067  template <typename T>
18068  struct pusher<T, std::enable_if_t<meta::all<is_container<meta::unqualified_t<T>>, meta::neg<is_lua_reference<meta::unqualified_t<T>>>>::value>> {
18070 
18071  static int push(lua_State* L, const T& cont) {
18073  return pusher<detail::as_value_tag<T>>{}.push_fx(L, fx, cont);
18074  }
18075 
18076  static int push(lua_State* L, T&& cont) {
18078  return pusher<detail::as_value_tag<T>>{}.push_fx(L, fx, std::move(cont));
18079  }
18080  };
18081 
18082  template <typename T>
18083  struct pusher<T*, std::enable_if_t<meta::all<is_container<meta::unqualified_t<T>>, meta::neg<is_lua_reference<meta::unqualified_t<T>>>>::value>> {
18084  typedef std::add_pointer_t<meta::unqualified_t<std::remove_pointer_t<T>>> C;
18085 
18086  static int push(lua_State* L, T* cont) {
18088  return pusher<detail::as_pointer_tag<T>>{}.push_fx(L, fx, cont);
18089  }
18090  };
18091 
18092  template <typename T, typename C>
18094  template <typename Handler>
18095  static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
18096  return stack::check<T>(L, index, std::forward<Handler>(handler), tracking);
18097  }
18098  };
18099 
18100  template <typename T>
18101  struct getter<as_container_t<T>> {
18102  static decltype(auto) get(lua_State* L, int index, record& tracking) {
18103  return stack::unqualified_get<T>(L, index, tracking);
18104  }
18105  };
18106 
18107  template <typename T>
18108  struct getter<as_container_t<T>*> {
18109  static decltype(auto) get(lua_State* L, int index, record& tracking) {
18110  return stack::unqualified_get<T*>(L, index, tracking);
18111  }
18112  };
18113  } // namespace stack
18114 
18115 } // namespace sol
18116 
18117 // end of sol/container_usertype_metatable.hpp
18118 
18119 // beginning of sol/usertype_core.hpp
18120 
18121 #include <sstream>
18122 
18123 namespace sol {
18124  namespace usertype_detail {
18125  struct no_comp {
18126  template <typename A, typename B>
18127  bool operator()(A&&, B&&) const {
18128  return false;
18129  }
18130  };
18131 
18132  template <typename T>
18133  int is_check(lua_State* L) {
18134  return stack::push(L, stack::check<T>(L, 1, &no_panic));
18135  }
18136 
18137  template <typename T>
18138  inline int member_default_to_string(std::true_type, lua_State* L) {
18139  decltype(auto) ts = stack::get<T>(L, 1).to_string();
18140  return stack::push(L, std::forward<decltype(ts)>(ts));
18141  }
18142 
18143  template <typename T>
18144  inline int member_default_to_string(std::false_type, lua_State* L) {
18145  return luaL_error(L, "cannot perform to_string on '%s': no 'to_string' overload in namespace, 'to_string' member function, or operator<<(ostream&, ...) present", detail::demangle<T>().data());
18146  }
18147 
18148  template <typename T>
18149  inline int adl_default_to_string(std::true_type, lua_State* L) {
18150  using namespace std;
18151  decltype(auto) ts = to_string(stack::get<T>(L, 1));
18152  return stack::push(L, std::forward<decltype(ts)>(ts));
18153  }
18154 
18155  template <typename T>
18156  inline int adl_default_to_string(std::false_type, lua_State* L) {
18157  return member_default_to_string<T>(meta::supports_to_string_member<T>(), L);
18158  }
18159 
18160  template <typename T>
18161  inline int oss_default_to_string(std::true_type, lua_State* L) {
18162  std::ostringstream oss;
18163  oss << stack::unqualified_get<T>(L, 1);
18164  return stack::push(L, oss.str());
18165  }
18166 
18167  template <typename T>
18168  inline int oss_default_to_string(std::false_type, lua_State* L) {
18169  return adl_default_to_string<T>(meta::supports_adl_to_string<T>(), L);
18170  }
18171 
18172  template <typename T>
18173  inline int default_to_string(lua_State* L) {
18174  return oss_default_to_string<T>(meta::supports_ostream_op<T>(), L);
18175  }
18176 
18177  template <typename T, typename Op>
18178  int comparsion_operator_wrap(lua_State* L) {
18179  auto maybel = stack::unqualified_check_get<T&>(L, 1);
18180  if (maybel) {
18181  auto mayber = stack::unqualified_check_get<T&>(L, 2);
18182  if (mayber) {
18183  auto& l = *maybel;
18184  auto& r = *mayber;
18185  if (std::is_same<no_comp, Op>::value) {
18186  return stack::push(L, detail::ptr(l) == detail::ptr(r));
18187  }
18188  else {
18189  Op op;
18190  return stack::push(L, (detail::ptr(l) == detail::ptr(r)) || op(detail::deref(l), detail::deref(r)));
18191  }
18192  }
18193  }
18194  return stack::push(L, false);
18195  }
18196 
18197  template <typename T, typename Op, typename Supports, typename Regs, meta::enable<Supports> = meta::enabler>
18198  inline void make_reg_op(Regs& l, int& index, const char* name) {
18199  lua_CFunction f = &comparsion_operator_wrap<T, Op>;
18200  l[index] = luaL_Reg{ name, f };
18201  ++index;
18202  }
18203 
18204  template <typename T, typename Op, typename Supports, typename Regs, meta::disable<Supports> = meta::enabler>
18205  inline void make_reg_op(Regs&, int&, const char*) {
18206  // Do nothing if there's no support
18207  }
18208 
18209  template <typename T, typename Supports, typename Regs, meta::enable<Supports> = meta::enabler>
18210  inline void make_to_string_op(Regs& l, int& index) {
18211  const char* name = to_string(meta_function::to_string).c_str();
18212  lua_CFunction f = &detail::static_trampoline<&default_to_string<T>>;
18213  l[index] = luaL_Reg{ name, f };
18214  ++index;
18215  }
18216 
18217  template <typename T, typename Supports, typename Regs, meta::disable<Supports> = meta::enabler>
18218  inline void make_to_string_op(Regs&, int&) {
18219  // Do nothing if there's no support
18220  }
18221 
18222  template <typename T, typename Regs, meta::enable<meta::has_deducible_signature<T>> = meta::enabler>
18223  inline void make_call_op(Regs& l, int& index) {
18224  const char* name = to_string(meta_function::call).c_str();
18225  lua_CFunction f = &c_call<decltype(&T::operator()), &T::operator()>;
18226  l[index] = luaL_Reg{ name, f };
18227  ++index;
18228  }
18229 
18230  template <typename T, typename Regs, meta::disable<meta::has_deducible_signature<T>> = meta::enabler>
18231  inline void make_call_op(Regs&, int&) {
18232  // Do nothing if there's no support
18233  }
18234 
18235  template <typename T, typename Regs>
18236  inline void make_length_op_const(std::true_type, Regs& l, int& index) {
18237  const char* name = to_string(meta_function::length).c_str();
18238 #if defined(__clang__)
18239  l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> };
18240 #else
18241  typedef decltype(std::declval<T>().size()) R;
18242  using sz_func = R(T::*)()const;
18243  l[index] = luaL_Reg{ name, &c_call<decltype(static_cast<sz_func>(&T::size)), static_cast<sz_func>(&T::size)> };
18244 #endif
18245  ++index;
18246  }
18247 
18248  template <typename T, typename Regs>
18249  inline void make_length_op_const(std::false_type, Regs& l, int& index) {
18250  const char* name = to_string(meta_function::length).c_str();
18251 #if defined(__clang__)
18252  l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> };
18253 #else
18254  typedef decltype(std::declval<T>().size()) R;
18255  using sz_func = R(T::*)();
18256  l[index] = luaL_Reg{ name, &c_call<decltype(static_cast<sz_func>(&T::size)), static_cast<sz_func>(&T::size)> };
18257 #endif
18258  ++index;
18259  }
18260 
18261  template <typename T, typename Regs, meta::enable<meta::has_size<T>, meta::has_size<const T>> = meta::enabler>
18262  inline void make_length_op(Regs& l, int& index) {
18263  make_length_op_const<T>(meta::has_size<const T>(), l, index);
18264  }
18265 
18266  template <typename T, typename Regs, meta::disable<meta::has_size<T>, meta::has_size<const T>> = meta::enabler>
18267  inline void make_length_op(Regs&, int&) {
18268  // Do nothing if there's no support
18269  }
18270 
18271  template <typename T, typename Regs, meta::enable<meta::neg<std::is_pointer<T>>, std::is_destructible<T>>>
18272  void make_destructor(Regs& l, int& index) {
18273  const char* name = to_string(meta_function::garbage_collect).c_str();
18274  l[index] = luaL_Reg{ name, is_unique_usertype<T>::value ? &detail::unique_destruct<T> : &detail::usertype_alloc_destruct<T> };
18275  ++index;
18276  }
18277 
18278  template <typename T, typename Regs, meta::disable<meta::neg<std::is_pointer<T>>, std::is_destructible<T>>>
18279  void make_destructor(Regs& l, int& index) {
18280  if (!std::is_destructible<T>::value) {
18281  // if the value is not destructible, plant an erroring __gc method
18282  // to warn the user of a problem when it comes around
18283  // this won't trigger if the user performs `new_usertype` / `new_simple_usertype` and
18284  // rigs the class up properly
18285  const char* name = to_string(meta_function::garbage_collect).c_str();
18286  l[index] = luaL_Reg{ name, &detail::cannot_destruct<T> };
18287  ++index;
18288  }
18289  }
18290 
18291  template <typename T, typename Regs, typename Fx>
18292  void insert_default_registrations(std::false_type, Regs&, int&, Fx&&) {
18293  // no-op
18294  }
18295 
18296  template <typename T, typename Regs, typename Fx>
18297  void insert_default_registrations(std::true_type, Regs& l, int& index, Fx&& fx) {
18298  if (fx(meta_function::less_than)) {
18299  const char* name = to_string(meta_function::less_than).c_str();
18300  usertype_detail::make_reg_op<T, std::less<>, meta::supports_op_less<T>>(l, index, name);
18301  }
18303  const char* name = to_string(meta_function::less_than_or_equal_to).c_str();
18304  usertype_detail::make_reg_op<T, std::less_equal<>, meta::supports_op_less_equal<T>>(l, index, name);
18305  }
18306  if (fx(meta_function::equal_to)) {
18307  const char* name = to_string(meta_function::equal_to).c_str();
18308  usertype_detail::make_reg_op<T, std::conditional_t<meta::supports_op_equal<T>::value, std::equal_to<>, usertype_detail::no_comp>, std::true_type>(l, index, name);
18309  }
18310  if (fx(meta_function::pairs)) {
18311  const char* name = to_string(meta_function::pairs).c_str();
18312  l[index] = luaL_Reg{ name, container_usertype_metatable<as_container_t<T>>::pairs_call };
18313  ++index;
18314  }
18315  if (fx(meta_function::length)) {
18316  usertype_detail::make_length_op<T>(l, index);
18317  }
18318  if (fx(meta_function::to_string)) {
18319  usertype_detail::make_to_string_op<T, is_to_stringable<T>>(l, index);
18320  }
18321  if (fx(meta_function::call_function)) {
18322  usertype_detail::make_call_op<T>(l, index);
18323  }
18324  }
18325 
18326  template <typename T, typename Regs, typename Fx>
18327  void insert_default_registrations(Regs& l, int& index, Fx&& fx) {
18328  insert_default_registrations<T>(is_automagical<T>(), l, index, std::forward<Fx>(fx));
18329  }
18330  } // namespace usertype_detail
18331 
18332  namespace stack { namespace stack_detail {
18333  template <typename T>
18334  struct undefined_metatable {
18335  typedef meta::all<meta::neg<std::is_pointer<T>>, std::is_destructible<T>> is_destructible;
18336  typedef std::remove_pointer_t<T> P;
18337  lua_State* L;
18338  const char* key;
18339 
18340  undefined_metatable(lua_State* l, const char* k)
18341  : L(l), key(k) {
18342  }
18343 
18344  void operator()() const {
18345  if (luaL_newmetatable(L, key) == 1) {
18346  luaL_Reg l[32]{};
18347  int index = 0;
18348  auto fx = [](meta_function) { return true; };
18349  usertype_detail::insert_default_registrations<P>(l, index, fx);
18350  usertype_detail::make_destructor<T>(l, index);
18351  luaL_setfuncs(L, l, 0);
18352 
18353  // __type table
18354  lua_createtable(L, 0, 2);
18355  const std::string& name = detail::demangle<T>();
18356  lua_pushlstring(L, name.c_str(), name.size());
18357  lua_setfield(L, -2, "name");
18358  lua_CFunction is_func = &usertype_detail::is_check<T>;
18359  lua_pushcclosure(L, is_func, 0);
18360  lua_setfield(L, -2, "is");
18361  lua_setfield(L, -2, to_string(meta_function::type).c_str());
18362  }
18363  lua_setmetatable(L, -2);
18364  }
18365  };
18366  }
18367  } // namespace stack::stack_detail
18368 } // namespace sol
18369 
18370 // end of sol/usertype_core.hpp
18371 
18372 #include <cstdio>
18373 #include <bitset>
18374 
18375 namespace sol {
18376 
18377  struct usertype_metatable_core;
18378 
18379  namespace usertype_detail {
18380  const int metatable_index = 2;
18381  const int metatable_core_index = 3;
18382  const int filler_index = 4;
18383  const int magic_index = 5;
18384 
18385  const int simple_metatable_index = 2;
18386  const int index_function_index = 3;
18388 
18389  typedef void (*base_walk)(lua_State*, bool&, int&, string_view&);
18390  typedef int (*member_search)(lua_State*, void*, usertype_metatable_core&, int);
18391 
18396 
18398  : call_information(index, newindex, -1) {
18399  }
18400  call_information(member_search index, member_search newindex, int runtimetarget)
18401  : index(index), new_index(newindex), runtime_target(runtimetarget) {
18402  }
18403  };
18404 
18406 
18408  virtual int index(lua_State* L) = 0;
18409  virtual int new_index(lua_State* L) = 0;
18410  virtual ~variable_wrapper(){};
18411  };
18412 
18413  template <typename T, typename F>
18415  F fx;
18416 
18417  template <typename Arg>
18418  callable_binding(Arg&& arg)
18419  : fx(std::forward<Arg>(arg)) {
18420  }
18421 
18422  virtual int index(lua_State* L) override {
18423  return call_detail::call_wrapped<T, true, true>(L, fx);
18424  }
18425 
18426  virtual int new_index(lua_State* L) override {
18427  return call_detail::call_wrapped<T, false, true>(L, fx);
18428  }
18429  };
18430 
18433 
18434  struct simple_map {
18435  const char* metakey;
18436  variable_map variables;
18437  function_map functions;
18438  object index;
18439  object newindex;
18442 
18443  simple_map(const char* mkey, base_walk index, base_walk newindex, object i, object ni, variable_map&& vars, function_map&& funcs)
18444  : metakey(mkey), variables(std::move(vars)), functions(std::move(funcs)), index(std::move(i)), newindex(std::move(ni)), indexbaseclasspropogation(index), newindexbaseclasspropogation(newindex) {
18445  }
18446  };
18447  } // namespace usertype_detail
18448 
18451  lua_CFunction indexfunc;
18452  lua_CFunction newindexfunc;
18453  std::vector<object> runtime;
18455 
18456  usertype_metatable_core(lua_CFunction ifx, lua_CFunction nifx)
18457  : mapping(), indexfunc(ifx), newindexfunc(nifx), runtime(), mustindex(false) {
18458  }
18459 
18462  usertype_metatable_core& operator=(const usertype_metatable_core&) = default;
18463  usertype_metatable_core& operator=(usertype_metatable_core&&) = default;
18464  };
18465 
18466  namespace usertype_detail {
18467  const lua_Integer toplevel_magic = static_cast<lua_Integer>(0xCCC2CCC1);
18468 
18469  inline int is_indexer(string_view s) {
18470  if (s == to_string(meta_function::index)) {
18471  return 1;
18472  }
18473  else if (s == to_string(meta_function::new_index)) {
18474  return 2;
18475  }
18476  return 0;
18477  }
18478 
18479  inline int is_indexer(meta_function mf) {
18480  if (mf == meta_function::index) {
18481  return 1;
18482  }
18483  else if (mf == meta_function::new_index) {
18484  return 2;
18485  }
18486  return 0;
18487  }
18488 
18490  return 0;
18491  }
18492 
18494  return 0;
18495  }
18496 
18498  return s;
18499  }
18500 
18503  }
18504 
18506  return string_view(to_string(mf));
18507  }
18508 
18511  }
18512 
18513  template <typename Arg>
18514  inline std::string make_string(Arg&& arg) {
18515  string_view s = make_string_view(arg);
18516  return std::string(s.data(), s.size());
18517  }
18518 
18519  template <typename N>
18520  inline luaL_Reg make_reg(N&& n, lua_CFunction f) {
18521  luaL_Reg l{make_string_view(std::forward<N>(n)).data(), f};
18522  return l;
18523  }
18524 
18525  struct registrar {
18526  registrar() = default;
18527  registrar(const registrar&) = default;
18528  registrar(registrar&&) = default;
18529  registrar& operator=(const registrar&) = default;
18530  registrar& operator=(registrar&&) = default;
18531  virtual int push_um(lua_State* L) = 0;
18532  virtual ~registrar() {
18533  }
18534  };
18535 
18536  inline bool is_toplevel(lua_State* L, int index = magic_index) {
18537  int isnum = 0;
18538  lua_Integer magic = lua_tointegerx(L, upvalue_index(index), &isnum);
18539  return isnum != 0 && magic == toplevel_magic;
18540  }
18541 
18542  inline int runtime_object_call(lua_State* L, void*, usertype_metatable_core& umc, int runtimetarget) {
18543  std::vector<object>& runtime = umc.runtime;
18544  object& runtimeobj = runtime[runtimetarget];
18545  return stack::push(L, runtimeobj);
18546  }
18547 
18548  template <typename T, bool is_index>
18549  inline int indexing_fail(lua_State* L) {
18550  if (is_index) {
18551 #if 0 //defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
18552  auto maybeaccessor = stack::get<optional<string_view>>(L, is_index ? -1 : -2);
18553  string_view accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)"));
18554  return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data());
18555 #else
18556  if (is_toplevel(L)) {
18557  if (lua_getmetatable(L, 1) == 1) {
18558  int metatarget = lua_gettop(L);
18559  stack::get_field(L, stack_reference(L, raw_index(2)), metatarget);
18560  return 1;
18561  }
18562  }
18563  // With runtime extensibility, we can't hard-error things. They have to return nil, like regular table types, unfortunately...
18564  return stack::push(L, lua_nil);
18565 #endif
18566  }
18567  else {
18568  auto maybeaccessor = stack::get<optional<string_view>>(L, is_index ? -1 : -2);
18569  string_view accessor = maybeaccessor.value_or(string_view("(unknown)"));
18570  return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data());
18571  }
18572  }
18573 
18574  int runtime_new_index(lua_State* L, void*, usertype_metatable_core&, int runtimetarget);
18575 
18576  template <typename T, bool is_simple>
18577  inline int metatable_new_index(lua_State* L) {
18578  if (is_toplevel(L)) {
18579  auto non_indexable = [&L]() {
18580  if (is_simple) {
18581  simple_map& sm = stack::get<user<simple_map>>(L, upvalue_index(simple_metatable_index));
18582  function_map& functions = sm.functions;
18583  optional<string_view> maybeaccessor = stack::get<optional<string_view>>(L, 2);
18584  if (!maybeaccessor) {
18585  return;
18586  }
18587  string_view& accessor_view = maybeaccessor.value();
18588 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18589  auto preexistingit = functions.find(accessor_view, string_view_hash(), std::equal_to<string_view>());
18590 #else
18591  std::string accessor(accessor_view.data(), accessor_view.size());
18592  auto preexistingit = functions.find(accessor);
18593 #endif
18594  if (preexistingit == functions.cend()) {
18595 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18596  std::string accessor(accessor_view.data(), accessor_view.size());
18597 #endif
18598  functions.emplace_hint(preexistingit, std::move(accessor), object(L, 3));
18599  }
18600  else {
18601  preexistingit->second = object(L, 3);
18602  }
18603  return;
18604  }
18605  usertype_metatable_core& umc = stack::get<light<usertype_metatable_core>>(L, upvalue_index(metatable_core_index));
18606  bool mustindex = umc.mustindex;
18607  if (!mustindex)
18608  return;
18609  optional<string_view> maybeaccessor = stack::get<optional<string_view>>(L, 2);
18610  if (!maybeaccessor) {
18611  return;
18612  }
18613  string_view& accessor_view = maybeaccessor.value();
18614  mapping_t& mapping = umc.mapping;
18615  std::vector<object>& runtime = umc.runtime;
18616  int target = static_cast<int>(runtime.size());
18617 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18618  auto preexistingit = mapping.find(accessor_view, string_view_hash(), std::equal_to<string_view>());
18619 #else
18620  std::string accessor(accessor_view.data(), accessor_view.size());
18621  auto preexistingit = mapping.find(accessor);
18622 #endif
18623  if (preexistingit == mapping.cend()) {
18624 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18625  std::string accessor(accessor_view.data(), accessor_view.size());
18626 #endif
18627  runtime.emplace_back(L, 3);
18628  mapping.emplace_hint(mapping.cend(), std::move(accessor), call_information(&runtime_object_call, &runtime_new_index, target));
18629  }
18630  else {
18631  target = preexistingit->second.runtime_target;
18632  runtime[target] = object(L, 3);
18633  preexistingit->second = call_information(&runtime_object_call, &runtime_new_index, target);
18634  }
18635  };
18636  non_indexable();
18637  for (std::size_t i = 0; i < 4; lua_settop(L, 3), ++i) {
18638  const char* metakey = nullptr;
18639  switch (i) {
18640  case 0:
18641  metakey = &usertype_traits<T*>::metatable()[0];
18642  luaL_getmetatable(L, metakey);
18643  break;
18644  case 1:
18645  metakey = &usertype_traits<detail::unique_usertype<T>>::metatable()[0];
18646  luaL_getmetatable(L, metakey);
18647  break;
18648  case 2:
18649  metakey = &usertype_traits<T>::metatable()[0];
18650  luaL_getmetatable(L, metakey);
18651  break;
18652  case 3:
18653  default:
18654  metakey = &usertype_traits<T>::user_metatable()[0];
18655  {
18656  luaL_getmetatable(L, metakey);
18657  lua_getmetatable(L, -1);
18658  }
18659  break;
18660  }
18661  int tableindex = lua_gettop(L);
18662  if (type_of(L, tableindex) == type::lua_nil) {
18663  continue;
18664  }
18665  stack::set_field<false, true>(L, stack_reference(L, raw_index(2)), stack_reference(L, raw_index(3)), tableindex);
18666  }
18667  lua_settop(L, 0);
18668  return 0;
18669  }
18670  return indexing_fail<T, false>(L);
18671  }
18672 
18673  inline int runtime_new_index(lua_State* L, void*, usertype_metatable_core& umc, int runtimetarget) {
18674  std::vector<object>& runtime = umc.runtime;
18675  object& runtimeobj = runtime[runtimetarget];
18676  runtimeobj = object(L, 3);
18677  return 0;
18678  }
18679 
18680  template <bool is_index, typename Base>
18681  static void walk_single_base(lua_State* L, bool& found, int& ret, string_view&) {
18682  if (found)
18683  return;
18684  const char* metakey = &usertype_traits<Base>::metatable()[0];
18685  const char* gcmetakey = &usertype_traits<Base>::gc_table()[0];
18687 
18688  luaL_getmetatable(L, metakey);
18689  if (type_of(L, -1) == type::lua_nil) {
18690  lua_pop(L, 1);
18691  return;
18692  }
18693 
18694  stack::get_field(L, basewalkkey);
18695  if (type_of(L, -1) == type::lua_nil) {
18696  lua_pop(L, 2);
18697  return;
18698  }
18699  lua_CFunction basewalkfunc = stack::pop<lua_CFunction>(L);
18700  lua_pop(L, 1);
18701 
18702  stack::get_field<true>(L, gcmetakey);
18703  int value = basewalkfunc(L);
18704  if (value > -1) {
18705  found = true;
18706  ret = value;
18707  }
18708  }
18709 
18710  template <bool is_index, typename... Bases>
18711  static void walk_all_bases(lua_State* L, bool& found, int& ret, string_view& accessor) {
18712  (void)L;
18713  (void)found;
18714  (void)ret;
18715  (void)accessor;
18716  (void)detail::swallow{0, (walk_single_base<is_index, Bases>(L, found, ret, accessor), 0)...};
18717  }
18718  } // namespace usertype_detail
18719 
18720  template <typename T>
18721  struct clean_type {
18722  typedef std::conditional_t<std::is_array<meta::unqualified_t<T>>::value, T&, std::decay_t<T>> type;
18723  };
18724 
18725  template <typename T>
18727 
18728  template <typename T, typename IndexSequence, typename... Tn>
18730 
18731  template <typename T, std::size_t... I, typename... Tn>
18732  struct usertype_metatable<T, std::index_sequence<I...>, Tn...> : usertype_metatable_core, usertype_detail::registrar {
18733  typedef std::make_index_sequence<sizeof...(I) * 2> indices;
18734  typedef std::index_sequence<I...> half_indices;
18735  typedef std::array<luaL_Reg, sizeof...(Tn) / 2 + 1 + 31> regs_t;
18736  typedef std::tuple<Tn...> RawTuple;
18737  typedef std::tuple<clean_type_t<Tn>...> Tuple;
18738  template <std::size_t Idx>
18739  struct check_binding : is_variable_binding<meta::unqualified_tuple_element_t<Idx, Tuple>> {};
18741  lua_CFunction destructfunc;
18742  lua_CFunction callconstructfunc;
18743  lua_CFunction indexbase;
18744  lua_CFunction newindexbase;
18750  std::bitset<32> properties;
18751 
18752  template <std::size_t Idx, meta::enable<std::is_same<lua_CFunction, meta::unqualified_tuple_element<Idx + 1, RawTuple>>> = meta::enabler>
18753  lua_CFunction make_func() const {
18754  return std::get<Idx + 1>(functions);
18755  }
18756 
18757  template <std::size_t Idx, meta::disable<std::is_same<lua_CFunction, meta::unqualified_tuple_element<Idx + 1, RawTuple>>> = meta::enabler>
18758  lua_CFunction make_func() const {
18759  const auto& name = std::get<Idx>(functions);
18760  return (usertype_detail::make_string_view(name) == "__newindex") ? &call<Idx + 1, false> : &call<Idx + 1, true>;
18761  }
18762 
18763  static bool contains_variable() {
18764  typedef meta::any<check_binding<(I * 2 + 1)>...> has_variables;
18765  return has_variables::value;
18766  }
18767 
18768  bool contains_index() const {
18769  bool idx = false;
18770  (void)detail::swallow{0, ((idx |= (usertype_detail::is_indexer(std::get<I * 2>(functions)) != 0)), 0)...};
18771  return idx;
18772  }
18773 
18774  int finish_regs(regs_t& l, int& index) {
18775  auto prop_fx = [&](meta_function mf) { return !properties[static_cast<int>(mf)]; };
18776  usertype_detail::insert_default_registrations<T>(l, index, prop_fx);
18777  if (destructfunc != nullptr) {
18778  l[index] = luaL_Reg{to_string(meta_function::garbage_collect).c_str(), destructfunc};
18779  ++index;
18780  }
18781  return index;
18782  }
18783 
18784  template <std::size_t Idx, typename F>
18785  void make_regs(regs_t&, int&, call_construction, F&&) {
18786  callconstructfunc = call<Idx + 1>;
18787  secondarymeta = true;
18788  }
18789 
18790  template <std::size_t, typename... Bases>
18792  static_assert(!meta::any_same<T, Bases...>::value, "base classes cannot list the original class as part of the bases");
18793  if (sizeof...(Bases) < 1) {
18794  return;
18795  }
18796  mustindex = true;
18797  (void)detail::swallow{0, ((detail::has_derived<Bases>::value = true), 0)...};
18798 
18799  static_assert(sizeof(void*) <= sizeof(detail::inheritance_check_function), "The size of this data pointer is too small to fit the inheritance checking function: file a bug report.");
18800  static_assert(sizeof(void*) <= sizeof(detail::inheritance_cast_function), "The size of this data pointer is too small to fit the inheritance checking function: file a bug report.");
18801  baseclasscheck = (void*)&detail::inheritance<T, Bases...>::type_check;
18802  baseclasscast = (void*)&detail::inheritance<T, Bases...>::type_cast;
18803  indexbaseclasspropogation = usertype_detail::walk_all_bases<true, Bases...>;
18804  newindexbaseclasspropogation = usertype_detail::walk_all_bases<false, Bases...>;
18805  }
18806 
18807  template <std::size_t Idx, typename N, typename F, typename = std::enable_if_t<!meta::any_same<meta::unqualified_t<N>, base_classes_tag, call_construction>::value>>
18808  void make_regs(regs_t& l, int& index, N&& n, F&&) {
18810  return;
18811  }
18812  luaL_Reg reg = usertype_detail::make_reg(std::forward<N>(n), make_func<Idx>());
18813  for (std::size_t i = 0; i < properties.size(); ++i) {
18814  meta_function mf = static_cast<meta_function>(i);
18815  const std::string& mfname = to_string(mf);
18816  if (mfname == reg.name) {
18817  switch (mf) {
18819  if (properties[i]) {
18820 #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
18821  throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
18822 #else
18823  assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
18824 #endif
18825  }
18826  break;
18828  if (destructfunc != nullptr) {
18829 #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
18830  throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
18831 #else
18832  assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
18833 #endif
18834  }
18835  destructfunc = reg.func;
18836  return;
18837  case meta_function::index:
18838  indexfunc = reg.func;
18839  mustindex = true;
18840  properties.set(i);
18841  return;
18843  newindexfunc = reg.func;
18844  mustindex = true;
18845  properties.set(i);
18846  return;
18847  default:
18848  break;
18849  }
18850  properties.set(i);
18851  break;
18852  }
18853  }
18854  l[index] = reg;
18855  ++index;
18856  }
18857 
18858  template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == sizeof...(Tn)>>
18859  usertype_metatable(Args&&... args)
18860  : usertype_metatable_core(&usertype_detail::indexing_fail<T, true>, &usertype_detail::metatable_new_index<T, false>), usertype_detail::registrar(), functions(std::forward<Args>(args)...), destructfunc(nullptr), callconstructfunc(nullptr), indexbase(&core_indexing_call<true>), newindexbase(&core_indexing_call<false>), indexbaseclasspropogation(usertype_detail::walk_all_bases<true>), newindexbaseclasspropogation(usertype_detail::walk_all_bases<false>), baseclasscheck(nullptr), baseclasscast(nullptr), secondarymeta(contains_variable()), properties() {
18861  properties.reset();
18862  std::initializer_list<typename usertype_detail::mapping_t::value_type> ilist{{std::pair<std::string, usertype_detail::call_information>(usertype_detail::make_string(std::get<I * 2>(functions)),
18863  usertype_detail::call_information(&usertype_metatable::real_find_call<I * 2, I * 2 + 1, true>,
18864  &usertype_metatable::real_find_call<I * 2, I * 2 + 1, false>))}...};
18865  this->mapping.insert(ilist);
18866  for (const auto& n : meta_function_names()) {
18867  this->mapping.erase(n);
18868  }
18869  this->mustindex = contains_variable() || contains_index();
18870  }
18871 
18872  usertype_metatable(const usertype_metatable&) = default;
18874  usertype_metatable& operator=(const usertype_metatable&) = default;
18875  usertype_metatable& operator=(usertype_metatable&&) = default;
18876 
18877  template <std::size_t I0, std::size_t I1, bool is_index>
18878  static int real_find_call(lua_State* L, void* um, usertype_metatable_core&, int) {
18879  auto& f = *static_cast<usertype_metatable*>(um);
18880  if (is_variable_binding<decltype(std::get<I1>(f.functions))>::value) {
18881  return real_call_with<I1, is_index, true>(L, f);
18882  }
18883  // set up upvalues
18884  // for a chained call
18885  int upvalues = 0;
18886  upvalues += stack::push(L, nullptr);
18887  upvalues += stack::push(L, light<usertype_metatable>(f));
18888  auto cfunc = &call<I1, is_index>;
18889  return stack::push(L, c_closure(cfunc, upvalues));
18890  }
18891 
18892  template <bool is_index>
18893  static int real_meta_call(lua_State* L, void* um, int) {
18894  auto& f = *static_cast<usertype_metatable*>(um);
18895  return is_index ? f.indexfunc(L) : f.newindexfunc(L);
18896  }
18897 
18898  template <bool is_index, bool toplevel = false, bool is_meta_bound = false>
18899  static int core_indexing_call(lua_State* L) {
18900  usertype_metatable& f = toplevel
18901  ? static_cast<usertype_metatable&>(stack::get<light<usertype_metatable>>(L, upvalue_index(usertype_detail::metatable_index)))
18902  : static_cast<usertype_metatable&>(stack::pop<user<usertype_metatable>>(L));
18903  static const int keyidx = -2 + static_cast<int>(is_index);
18904  if (toplevel && stack::get<type>(L, keyidx) != type::string) {
18905  return is_index ? f.indexfunc(L) : f.newindexfunc(L);
18906  }
18907  int runtime_target = 0;
18908  usertype_detail::member_search member = nullptr;
18909  {
18910 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18911  string_view name = stack::get<string_view>(L, keyidx);
18912  auto memberit = f.mapping.find(name, string_view_hash(), std::equal_to<string_view>());
18913 #else
18914  std::string name = stack::get<std::string>(L, keyidx);
18915  auto memberit = f.mapping.find(name);
18916 #endif
18917  if (memberit != f.mapping.cend()) {
18918  const usertype_detail::call_information& ci = memberit->second;
18919  member = is_index ? ci.index : ci.new_index;
18920  runtime_target = ci.runtime_target;
18921  }
18922  }
18923  if (member != nullptr) {
18924  return (member)(L, static_cast<void*>(&f), static_cast<usertype_metatable_core&>(f), runtime_target);
18925  }
18926  if (is_meta_bound && toplevel && !is_index) {
18927  return usertype_detail::metatable_new_index<T, false>(L);
18928  }
18929  string_view accessor = stack::get<string_view>(L, keyidx);
18930  int ret = 0;
18931  bool found = false;
18932  // Otherwise, we need to do propagating calls through the bases
18933  if (is_index)
18934  f.indexbaseclasspropogation(L, found, ret, accessor);
18935  else
18936  f.newindexbaseclasspropogation(L, found, ret, accessor);
18937  if (found) {
18938  return ret;
18939  }
18940  if (is_meta_bound) {
18941  return is_index ? usertype_detail::indexing_fail<T, is_index>(L) : usertype_detail::metatable_new_index<T, false>(L);
18942  }
18943  return toplevel ? (is_index ? f.indexfunc(L) : f.newindexfunc(L)) : -1;
18944  }
18945 
18946  static int real_index_call(lua_State* L) {
18947  return core_indexing_call<true, true>(L);
18948  }
18949 
18950  static int real_new_index_call(lua_State* L) {
18951  return core_indexing_call<false, true>(L);
18952  }
18953 
18954  static int real_meta_index_call(lua_State* L) {
18955  return core_indexing_call<true, true, true>(L);
18956  }
18957 
18958  static int real_meta_new_index_call(lua_State* L) {
18959  return core_indexing_call<false, true, true>(L);
18960  }
18961 
18962  template <std::size_t Idx, bool is_index = true, bool is_variable = false>
18963  static int real_call(lua_State* L) {
18964  usertype_metatable& f = stack::get<light<usertype_metatable>>(L, upvalue_index(usertype_detail::metatable_index));
18965  return real_call_with<Idx, is_index, is_variable>(L, f);
18966  }
18967 
18968  template <std::size_t Idx, bool is_index = true, bool is_variable = false>
18969  static int real_call_with(lua_State* L, usertype_metatable& um) {
18970  typedef meta::unqualified_tuple_element_t<Idx - 1, Tuple> K;
18972  static const int boost = !detail::is_non_factory_constructor<F>::value
18973  && std::is_same<K, call_construction>::value
18974  ? 1
18975  : 0;
18976  auto& f = std::get<Idx>(um.functions);
18977  return call_detail::call_wrapped<T, is_index, is_variable, boost>(L, f);
18978  }
18979 
18980  template <std::size_t Idx, bool is_index = true, bool is_variable = false>
18981  static int call(lua_State* L) {
18982  return detail::typed_static_trampoline<decltype(&real_call<Idx, is_index, is_variable>), (&real_call<Idx, is_index, is_variable>)>(L);
18983  }
18984 
18985  template <std::size_t Idx, bool is_index = true, bool is_variable = false>
18986  static int call_with(lua_State* L) {
18987  return detail::typed_static_trampoline<decltype(&real_call_with<Idx, is_index, is_variable>), (&real_call_with<Idx, is_index, is_variable>)>(L);
18988  }
18989 
18990  static int index_call(lua_State* L) {
18991  return detail::typed_static_trampoline<decltype(&real_index_call), (&real_index_call)>(L);
18992  }
18993 
18994  static int new_index_call(lua_State* L) {
18995  return detail::typed_static_trampoline<decltype(&real_new_index_call), (&real_new_index_call)>(L);
18996  }
18997 
18998  static int meta_index_call(lua_State* L) {
18999  return detail::typed_static_trampoline<decltype(&real_meta_index_call), (&real_meta_index_call)>(L);
19000  }
19001 
19002  static int meta_new_index_call(lua_State* L) {
19003  return detail::typed_static_trampoline<decltype(&real_meta_new_index_call), (&real_meta_new_index_call)>(L);
19004  }
19005 
19006  virtual int push_um(lua_State* L) override {
19007  return stack::push(L, std::move(*this));
19008  }
19009 
19010  ~usertype_metatable() override {
19011  }
19012  };
19013 
19014  namespace stack {
19015 
19016  template <typename T, std::size_t... I, typename... Args>
19017  struct pusher<usertype_metatable<T, std::index_sequence<I...>, Args...>> {
19018  typedef usertype_metatable<T, std::index_sequence<I...>, Args...> umt_t;
19019  typedef typename umt_t::regs_t regs_t;
19020 
19021  static umt_t& make_cleanup(lua_State* L, umt_t&& umx) {
19022  // ensure some sort of uniqueness
19023  static int uniqueness = 0;
19025  // std::to_string doesn't exist in android still, with NDK, so this bullshit
19026  // is necessary
19027  // thanks, Android :v
19028  int appended = snprintf(nullptr, 0, "%d", uniqueness);
19029  std::size_t insertionpoint = uniquegcmetakey.length() - 1;
19030  uniquegcmetakey.append(appended, '\0');
19031  char* uniquetarget = &uniquegcmetakey[insertionpoint];
19032  snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness);
19033  ++uniqueness;
19034 
19035  const char* gcmetakey = &usertype_traits<T>::gc_table()[0];
19036  // Make sure userdata's memory is properly in lua first,
19037  // otherwise all the light userdata we make later will become invalid
19038  stack::push<user<umt_t>>(L, metatable_key, uniquegcmetakey, std::move(umx));
19039  // Create the top level thing that will act as our deleter later on
19040  stack_reference umt(L, -1);
19041  stack::set_field<true>(L, gcmetakey, umt);
19042  umt.pop();
19043 
19044  stack::get_field<true>(L, gcmetakey);
19045  umt_t& target_umt = stack::pop<user<umt_t>>(L);
19046  return target_umt;
19047  }
19048 
19049  static int push(lua_State* L, umt_t&& umx) {
19050 
19051  umt_t& um = make_cleanup(L, std::move(umx));
19052  usertype_metatable_core& umc = um;
19053  regs_t value_table{{}};
19054  int lastreg = 0;
19055  (void)detail::swallow{0, (um.template make_regs<(I * 2)>(value_table, lastreg, std::get<(I * 2)>(um.functions), std::get<(I * 2 + 1)>(um.functions)), 0)...};
19056  um.finish_regs(value_table, lastreg);
19057  value_table[lastreg] = {nullptr, nullptr};
19058  regs_t ref_table = value_table;
19059  regs_t unique_table = value_table;
19060  bool hasdestructor = !value_table.empty() && to_string(meta_function::garbage_collect) == value_table[lastreg - 1].name;
19061  if (hasdestructor) {
19062  ref_table[lastreg - 1] = {nullptr, nullptr};
19063  }
19064  unique_table[lastreg - 1] = {value_table[lastreg - 1].name, detail::unique_destruct<T>};
19065 
19066  lua_createtable(L, 0, 2);
19067  stack_reference type_table(L, -1);
19068 
19069  stack::set_field(L, "name", detail::demangle<T>(), type_table.stack_index());
19070  stack::set_field(L, "is", &usertype_detail::is_check<T>, type_table.stack_index());
19071 
19072  // Now use um
19073  const bool& mustindex = umc.mustindex;
19074  for (std::size_t i = 0; i < 3; ++i) {
19075  // Pointer types, AKA "references" from C++
19076  const char* metakey = nullptr;
19077  luaL_Reg* metaregs = nullptr;
19078  switch (i) {
19079  case 0:
19080  metakey = &usertype_traits<T*>::metatable()[0];
19081  metaregs = ref_table.data();
19082  break;
19083  case 1:
19084  metakey = &usertype_traits<detail::unique_usertype<T>>::metatable()[0];
19085  metaregs = unique_table.data();
19086  break;
19087  case 2:
19088  default:
19089  metakey = &usertype_traits<T>::metatable()[0];
19090  metaregs = value_table.data();
19091  break;
19092  }
19093  luaL_newmetatable(L, metakey);
19094  stack_reference t(L, -1);
19095  stack::set_field(L, meta_function::type, type_table, t.stack_index());
19096  int upvalues = 0;
19097  upvalues += stack::push(L, nullptr);
19098  upvalues += stack::push(L, make_light(um));
19099  luaL_setfuncs(L, metaregs, upvalues);
19100 
19101  if (um.baseclasscheck != nullptr) {
19102  stack::set_field(L, detail::base_class_check_key(), um.baseclasscheck, t.stack_index());
19103  }
19104  if (um.baseclasscast != nullptr) {
19105  stack::set_field(L, detail::base_class_cast_key(), um.baseclasscast, t.stack_index());
19106  }
19107 
19110 
19111  if (mustindex) {
19112  // Basic index pushing: specialize
19113  // index and newindex to give variables and stuff
19114  stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc)), t.stack_index());
19115  stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc)), t.stack_index());
19116  }
19117  else {
19118  // If there's only functions, we can use the fast index version
19120  }
19121  // metatable on the metatable
19122  // for call constructor purposes and such
19123  lua_createtable(L, 0, 3);
19124  stack_reference metabehind(L, -1);
19125  stack::set_field(L, meta_function::type, type_table, metabehind.stack_index());
19126  if (um.callconstructfunc != nullptr) {
19127  stack::set_field(L, meta_function::call_function, make_closure(um.callconstructfunc, nullptr, make_light(um), make_light(umc)), metabehind.stack_index());
19128  }
19129  if (um.secondarymeta) {
19130  stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc)), metabehind.stack_index());
19131  stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc)), metabehind.stack_index());
19132  }
19133  // type information needs to be present on the behind-tables too
19134 
19135  stack::set_field(L, metatable_key, metabehind, t.stack_index());
19136  metabehind.pop();
19137  // We want to just leave the table
19138  // in the registry only, otherwise we return it
19139  t.pop();
19140  }
19141 
19142  // Now for the shim-table that actually gets assigned to the name
19143  luaL_newmetatable(L, &usertype_traits<T>::user_metatable()[0]);
19144  stack_reference t(L, -1);
19145  stack::set_field(L, meta_function::type, type_table, t.stack_index());
19146  int upvalues = 0;
19147  upvalues += stack::push(L, nullptr);
19148  upvalues += stack::push(L, make_light(um));
19149  luaL_setfuncs(L, value_table.data(), upvalues);
19150  {
19151  lua_createtable(L, 0, 3);
19152  stack_reference metabehind(L, -1);
19153  // type information needs to be present on the behind-tables too
19154  stack::set_field(L, meta_function::type, type_table, metabehind.stack_index());
19155  if (um.callconstructfunc != nullptr) {
19156  stack::set_field(L, meta_function::call_function, make_closure(um.callconstructfunc, nullptr, make_light(um), make_light(umc)), metabehind.stack_index());
19157  }
19158 
19159  stack::set_field(L, meta_function::index, make_closure(umt_t::meta_index_call, nullptr, make_light(um), make_light(umc), nullptr, usertype_detail::toplevel_magic), metabehind.stack_index());
19160  stack::set_field(L, meta_function::new_index, make_closure(umt_t::meta_new_index_call, nullptr, make_light(um), make_light(umc), nullptr, usertype_detail::toplevel_magic), metabehind.stack_index());
19161  stack::set_field(L, metatable_key, metabehind, t.stack_index());
19162  metabehind.pop();
19163  }
19164 
19165  lua_remove(L, type_table.stack_index());
19166 
19167  return 1;
19168  }
19169  };
19170 
19171  } // namespace stack
19172 
19173 } // namespace sol
19174 
19175 // end of sol/usertype_metatable.hpp
19176 
19177 // beginning of sol/simple_usertype_metatable.hpp
19178 
19179 namespace sol {
19180 
19181  namespace usertype_detail {
19182  inline int call_indexing_object(lua_State* L, object& f) {
19183  int before = lua_gettop(L);
19184  f.push();
19185  for (int i = 1; i <= before; ++i) {
19186  lua_pushvalue(L, i);
19187  }
19188  lua_call(L, before, LUA_MULTRET);
19189  int after = lua_gettop(L);
19190  return after - before;
19191  }
19192 
19193  template <typename T, bool is_index, bool toplevel = false, bool has_indexing = false>
19194  inline int simple_core_indexing_call(lua_State* L) {
19195  simple_map& sm = toplevel
19196  ? stack::get<user<simple_map>>(L, upvalue_index(simple_metatable_index))
19198  variable_map& variables = sm.variables;
19199  function_map& functions = sm.functions;
19200  static const int keyidx = -2 + static_cast<int>(is_index);
19201  if (toplevel) {
19202  if (type_of(L, keyidx) != type::string) {
19203  if (has_indexing) {
19204  object& indexingfunc = is_index
19205  ? sm.index
19206  : sm.newindex;
19207  return call_indexing_object(L, indexingfunc);
19208  }
19209  else {
19210  return is_index
19211  ? indexing_fail<T, is_index>(L)
19212  : metatable_new_index<T, true>(L);
19213  }
19214  }
19215  }
19216  string_view accessor = stack::get<string_view>(L, keyidx);
19217  variable_wrapper* varwrap = nullptr;
19218  {
19219 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
19220  string_view& accessorkey = accessor;
19221  auto vit = variables.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
19222 #else
19223  std::string accessorkey(accessor.data(), accessor.size());
19224  auto vit = variables.find(accessorkey);
19225 #endif // Compatible Hash
19226  if (vit != variables.cend()) {
19227  varwrap = vit->second.get();
19228  }
19229  }
19230  if (varwrap != nullptr) {
19231  return is_index ? varwrap->index(L) : varwrap->new_index(L);
19232  }
19233  bool function_failed = false;
19234  {
19235 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
19236  string_view& accessorkey = accessor;
19237  auto fit = functions.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
19238 #else
19239  std::string accessorkey(accessor.data(), accessor.size());
19240  auto fit = functions.find(accessorkey);
19241 #endif // Compatible Hash
19242  if (fit != functions.cend()) {
19243  object& func = fit->second;
19244  if (is_index) {
19245  return stack::push(L, func);
19246  }
19247  else {
19248  function_failed = true;
19249  }
19250  }
19251  }
19252  if (function_failed) {
19253  if (has_indexing && !is_toplevel(L)) {
19254  object& indexingfunc = is_index
19255  ? sm.index
19256  : sm.newindex;
19257  return call_indexing_object(L, indexingfunc);
19258  }
19259  else {
19260  return is_index
19261  ? indexing_fail<T, is_index>(L)
19262  : metatable_new_index<T, true>(L);
19263  }
19264  }
19265  /* Check table storage first for a method that works
19266  luaL_getmetatable(L, sm.metakey);
19267  if (type_of(L, -1) != type::lua_nil) {
19268  stack::get_field<false, true>(L, accessor.c_str(), lua_gettop(L));
19269  if (type_of(L, -1) != type::lua_nil) {
19270  // Woo, we found it?
19271  lua_remove(L, -2);
19272  return 1;
19273  }
19274  lua_pop(L, 1);
19275  }
19276  lua_pop(L, 1);
19277  */
19278 
19279  int ret = 0;
19280  bool found = false;
19281  // Otherwise, we need to do propagating calls through the bases
19282  if (is_index) {
19283  sm.indexbaseclasspropogation(L, found, ret, accessor);
19284  }
19285  else {
19286  sm.newindexbaseclasspropogation(L, found, ret, accessor);
19287  }
19288  if (found) {
19289  return ret;
19290  }
19291  if (toplevel) {
19292  if (has_indexing && !is_toplevel(L)) {
19293  object& indexingfunc = is_index
19294  ? sm.index
19295  : sm.newindex;
19296  return call_indexing_object(L, indexingfunc);
19297  }
19298  else {
19299  return is_index
19300  ? indexing_fail<T, is_index>(L)
19301  : metatable_new_index<T, true>(L);
19302  }
19303  }
19304  return -1;
19305  }
19306 
19307  template <typename T, bool has_indexing = false>
19308  inline int simple_real_index_call(lua_State* L) {
19309  return simple_core_indexing_call<T, true, true, has_indexing>(L);
19310  }
19311 
19312  template <typename T, bool has_indexing = false>
19313  inline int simple_real_new_index_call(lua_State* L) {
19314  return simple_core_indexing_call<T, false, true, has_indexing>(L);
19315  }
19316 
19317  template <typename T, bool has_indexing = false>
19318  inline int simple_index_call(lua_State* L) {
19319 #if defined(__clang__)
19320  return detail::trampoline(L, &simple_real_index_call<T, has_indexing>);
19321 #else
19322  return detail::typed_static_trampoline<decltype(&simple_real_index_call<T, has_indexing>), (&simple_real_index_call<T, has_indexing>)>(L);
19323 #endif
19324  }
19325 
19326  template <typename T, bool has_indexing = false>
19327  inline int simple_new_index_call(lua_State* L) {
19328 #if defined(__clang__)
19329  return detail::trampoline(L, &simple_real_new_index_call<T, has_indexing>);
19330 #else
19331  return detail::typed_static_trampoline<decltype(&simple_real_new_index_call<T, has_indexing>), (&simple_real_new_index_call<T, has_indexing>)>(L);
19332 #endif
19333  }
19334  } // namespace usertype_detail
19335 
19336  struct simple_tag {
19337  } const simple{};
19338 
19339  template <typename T>
19341  public:
19345  object indexfunc;
19347  lua_CFunction indexbase;
19348  lua_CFunction newindexbase;
19355  std::array<bool, 32> properties;
19356 
19357  template <typename N>
19358  void insert(N&& n, object&& o) {
19359  std::string key = usertype_detail::make_string(std::forward<N>(n));
19360  int is_indexer = static_cast<int>(usertype_detail::is_indexer(n));
19361  if (is_indexer == 1) {
19362  indexfunc = o;
19363  mustindex = true;
19364  }
19365  else if (is_indexer == 2) {
19366  newindexfunc = o;
19367  mustindex = true;
19368  }
19369  auto hint = registrations.find(key);
19370  if (hint == registrations.cend()) {
19371  registrations.emplace_hint(hint, std::move(key), std::move(o));
19372  return;
19373  }
19374  hint->second = std::move(o);
19375  }
19376 
19377  template <typename N, typename F, typename... Args>
19378  void insert_prepare(std::true_type, lua_State* L, N&&, F&& f, Args&&... args) {
19379  object o = make_object<F>(L, std::forward<F>(f), function_detail::call_indicator(), std::forward<Args>(args)...);
19380  callconstructfunc = std::move(o);
19381  }
19382 
19383  template <typename N, typename F, typename... Args>
19384  void insert_prepare(std::false_type, lua_State* L, N&& n, F&& f, Args&&... args) {
19385  object o = make_object<F>(L, std::forward<F>(f), std::forward<Args>(args)...);
19386  insert(std::forward<N>(n), std::move(o));
19387  }
19388 
19389  template <typename N, typename F>
19390  void add_member_function(std::true_type, lua_State* L, N&& n, F&& f) {
19391  insert_prepare(std::is_same<meta::unqualified_t<N>, call_construction>(), L, std::forward<N>(n), std::forward<F>(f), function_detail::class_indicator<T>());
19392  }
19393 
19394  template <typename N, typename F>
19395  void add_member_function(std::false_type, lua_State* L, N&& n, F&& f) {
19396  insert_prepare(std::is_same<meta::unqualified_t<N>, call_construction>(), L, std::forward<N>(n), std::forward<F>(f));
19397  }
19398 
19399  template <typename N, typename F, meta::enable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
19400  void add_function(lua_State* L, N&& n, F&& f) {
19401  object o = make_object(L, as_function_reference(std::forward<F>(f)));
19402  if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
19403  callconstructfunc = std::move(o);
19404  return;
19405  }
19406  insert(std::forward<N>(n), std::move(o));
19407  }
19408 
19409  template <typename N, typename F, meta::disable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
19410  void add_function(lua_State* L, N&& n, F&& f) {
19411  add_member_function(std::is_member_pointer<meta::unwrap_unqualified_t<F>>(), L, std::forward<N>(n), std::forward<F>(f));
19412  }
19413 
19414  template <typename N, typename F, meta::disable<is_variable_binding<meta::unqualified_t<F>>> = meta::enabler>
19415  void add(lua_State* L, N&& n, F&& f) {
19416  add_function(L, std::forward<N>(n), std::forward<F>(f));
19417  }
19418 
19419  template <typename N, typename F, meta::enable<is_variable_binding<meta::unqualified_t<F>>> = meta::enabler>
19420  void add(lua_State*, N&& n, F&& f) {
19421  mustindex = true;
19422  secondarymeta = true;
19423  std::string key = usertype_detail::make_string(std::forward<N>(n));
19424  auto o = std::make_unique<usertype_detail::callable_binding<T, std::decay_t<F>>>(std::forward<F>(f));
19425  auto hint = varmap.find(key);
19426  if (hint == varmap.cend()) {
19427  varmap.emplace_hint(hint, std::move(key), std::move(o));
19428  return;
19429  }
19430  hint->second = std::move(o);
19431  }
19432 
19433  template <typename N, typename... Fxs>
19434  void add(lua_State* L, N&& n, constructor_wrapper<Fxs...> c) {
19435  object o(L, in_place_type<detail::tagged<T, constructor_wrapper<Fxs...>>>, std::move(c));
19436  if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
19437  callconstructfunc = std::move(o);
19438  return;
19439  }
19440  insert(std::forward<N>(n), std::move(o));
19441  }
19442 
19443  template <typename N, typename... Lists>
19444  void add(lua_State* L, N&& n, constructor_list<Lists...> c) {
19445  object o(L, in_place_type<detail::tagged<T, constructor_list<Lists...>>>, std::move(c));
19446  if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
19447  callconstructfunc = std::move(o);
19448  return;
19449  }
19450  insert(std::forward<N>(n), std::move(o));
19451  }
19452 
19453  template <typename N>
19454  void add(lua_State* L, N&& n, destructor_wrapper<void> c) {
19455  object o(L, in_place_type<detail::tagged<T, destructor_wrapper<void>>>, std::move(c));
19456  if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
19457  callconstructfunc = std::move(o);
19458  return;
19459  }
19460  insert(std::forward<N>(n), std::move(o));
19461  }
19462 
19463  template <typename N, typename Fx>
19464  void add(lua_State* L, N&& n, destructor_wrapper<Fx> c) {
19465  object o(L, in_place_type<detail::tagged<T, destructor_wrapper<Fx>>>, std::move(c));
19466  if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
19467  callconstructfunc = std::move(o);
19468  return;
19469  }
19470  insert(std::forward<N>(n), std::move(o));
19471  }
19472 
19473  template <typename... Bases>
19474  void add(lua_State*, base_classes_tag, bases<Bases...>) {
19475  static_assert(sizeof(usertype_detail::base_walk) <= sizeof(void*), "size of function pointer is greater than sizeof(void*); cannot work on this platform. Please file a bug report.");
19476  static_assert(!meta::any_same<T, Bases...>::value, "base classes cannot list the original class as part of the bases");
19477  if (sizeof...(Bases) < 1) {
19478  return;
19479  }
19480  mustindex = true;
19481  (void)detail::swallow{0, ((detail::has_derived<Bases>::value = true), 0)...};
19482 
19483  static_assert(sizeof(void*) <= sizeof(detail::inheritance_check_function), "The size of this data pointer is too small to fit the inheritance checking function: Please file a bug report.");
19484  static_assert(sizeof(void*) <= sizeof(detail::inheritance_cast_function), "The size of this data pointer is too small to fit the inheritance checking function: Please file a bug report.");
19485  baseclasscheck = reinterpret_cast<void*>(&detail::inheritance<T, Bases...>::type_check);
19486  baseclasscast = reinterpret_cast<void*>(&detail::inheritance<T, Bases...>::type_cast);
19487  indexbaseclasspropogation = usertype_detail::walk_all_bases<true, Bases...>;
19488  newindexbaseclasspropogation = usertype_detail::walk_all_bases<false, Bases...>;
19489  }
19490 
19491  private:
19492  template <std::size_t... I, typename Tuple>
19493  simple_usertype_metatable(detail::verified_tag, std::index_sequence<I...>, lua_State* L, Tuple&& args)
19494  : callconstructfunc(lua_nil), indexfunc(lua_nil), newindexfunc(lua_nil), indexbase(&usertype_detail::simple_core_indexing_call<T, true>), newindexbase(&usertype_detail::simple_core_indexing_call<T, false>), indexbaseclasspropogation(usertype_detail::walk_all_bases<true>), newindexbaseclasspropogation(&usertype_detail::walk_all_bases<false>), baseclasscheck(nullptr), baseclasscast(nullptr), mustindex(false), secondarymeta(false), properties() {
19495  properties.fill(false);
19496 
19497  (void)detail::swallow{0,
19498  (add(L, detail::forward_get<I * 2>(args), detail::forward_get<I * 2 + 1>(args)), 0)...};
19499  }
19500 
19501  template <typename... Args>
19502  simple_usertype_metatable(lua_State* L, detail::verified_tag v, Args&&... args)
19503  : simple_usertype_metatable(v, std::make_index_sequence<sizeof...(Args) / 2>(), L, std::forward_as_tuple(std::forward<Args>(args)...)) {
19504  }
19505 
19506  template <typename... Args>
19508  : simple_usertype_metatable(L, detail::verified, std::forward<Args>(args)..., "__gc", default_destructor) {
19509  }
19510 
19511  template <typename... Args>
19513  : simple_usertype_metatable(L, meta::condition<meta::all<std::is_destructible<T>, meta::neg<detail::has_destructor<Args...>>>, detail::add_destructor_tag, detail::verified_tag>(), std::forward<Args>(args)...) {
19514  }
19515 
19516  public:
19518  : simple_usertype_metatable(L, meta::condition<meta::all<std::is_default_constructible<T>>, decltype(default_constructor), detail::check_destructor_tag>()) {
19519  }
19520 
19522  simple_usertype_metatable(lua_State* L, Arg&& arg, Args&&... args)
19523  : simple_usertype_metatable(L, meta::condition<meta::all<std::is_default_constructible<T>, meta::neg<detail::has_constructor<Args...>>>, decltype(default_constructor), detail::check_destructor_tag>(), std::forward<Arg>(arg), std::forward<Args>(args)...) {
19524  }
19525 
19526  template <typename... Args, typename... CArgs>
19527  simple_usertype_metatable(lua_State* L, constructors<CArgs...> constructorlist, Args&&... args)
19528  : simple_usertype_metatable(L, detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {
19529  }
19530 
19531  template <typename... Args, typename... Fxs>
19532  simple_usertype_metatable(lua_State* L, constructor_wrapper<Fxs...> constructorlist, Args&&... args)
19533  : simple_usertype_metatable(L, detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {
19534  }
19535 
19538  simple_usertype_metatable& operator=(const simple_usertype_metatable&) = default;
19539  simple_usertype_metatable& operator=(simple_usertype_metatable&&) = default;
19540 
19541  virtual int push_um(lua_State* L) override {
19542  return stack::push(L, std::move(*this));
19543  }
19544  };
19545 
19546  namespace stack {
19547  template <typename T>
19550 
19551  static usertype_detail::simple_map& make_cleanup(lua_State* L, umt_t& umx) {
19552  static int uniqueness = 0;
19554  // std::to_string doesn't exist in android still, with NDK, so this bullshit
19555  // is necessary
19556  // thanks, Android :v
19557  int appended = snprintf(nullptr, 0, "%d", uniqueness);
19558  std::size_t insertionpoint = uniquegcmetakey.length() - 1;
19559  uniquegcmetakey.append(appended, '\0');
19560  char* uniquetarget = &uniquegcmetakey[insertionpoint];
19561  snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness);
19562  ++uniqueness;
19563 
19564  const char* gcmetakey = &usertype_traits<T>::gc_table()[0];
19565  stack::push<user<usertype_detail::simple_map>>(L, metatable_key, uniquegcmetakey, &usertype_traits<T>::metatable()[0],
19567  std::move(umx.indexfunc), std::move(umx.newindexfunc),
19568  std::move(umx.varmap), std::move(umx.registrations));
19569  stack_reference stackvarmap(L, -1);
19570  stack::set_field<true>(L, gcmetakey, stackvarmap);
19571  stackvarmap.pop();
19572 
19573  stack::get_field<true>(L, gcmetakey);
19574  usertype_detail::simple_map& varmap = stack::pop<user<usertype_detail::simple_map>>(L);
19575  return varmap;
19576  }
19577 
19578  static int push(lua_State* L, umt_t&& umx) {
19579  bool hasindex = umx.indexfunc.valid();
19580  bool hasnewindex = umx.newindexfunc.valid();
19581  auto& varmap = make_cleanup(L, umx);
19582  auto& properties = umx.properties;
19583  auto sic = hasindex ? &usertype_detail::simple_index_call<T, true> : &usertype_detail::simple_index_call<T, false>;
19584  auto snic = hasnewindex ? &usertype_detail::simple_new_index_call<T, true> : &usertype_detail::simple_new_index_call<T, false>;
19585 
19586  lua_createtable(L, 0, 2);
19587  stack_reference type_table(L, -1);
19588 
19589  stack::set_field(L, "name", detail::demangle<T>(), type_table.stack_index());
19590  stack::set_field(L, "is", &usertype_detail::is_check<T>, type_table.stack_index());
19591 
19592  auto safety_check = [&](const std::string& first) {
19593  for (std::size_t j = 0; j < properties.size(); ++j) {
19594  meta_function mf = static_cast<meta_function>(j);
19595  const std::string& mfname = to_string(mf);
19596  bool& prop = properties[j];
19597  if (mfname != first)
19598  continue;
19599  switch (mf) {
19601  if (prop) {
19602 #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
19603  assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
19604 #else
19605  throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
19606 #endif
19607  }
19608  break;
19610  if (prop) {
19611 #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
19612  assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
19613 #else
19614  throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
19615 #endif
19616  }
19617  return;
19618  default:
19619  break;
19620  }
19621  prop = true;
19622  break;
19623  }
19624  };
19625 
19626  for (auto& kvp : varmap.functions) {
19627  auto& first = std::get<0>(kvp);
19628  safety_check(first);
19629  }
19630 
19631  auto register_kvp = [&](std::size_t meta_index, stack_reference& t, const std::string& first, object& second) {
19633  for (std::size_t j = 0; j < properties.size(); ++j) {
19634  mf = static_cast<meta_function>(j);
19635  const std::string& mfname = to_string(mf);
19636  bool& prop = properties[j];
19637  if (mfname != first)
19638  continue;
19639  switch (mf) {
19640  case meta_function::index:
19641  umx.indexfunc = second;
19642  break;
19644  umx.newindexfunc = second;
19645  break;
19646  default:
19647  break;
19648  }
19649  prop = true;
19650  break;
19651  }
19652  switch (meta_index) {
19653  case 0:
19654  if (mf == meta_function::garbage_collect) {
19655  return;
19656  }
19657  break;
19658  case 1:
19659  if (mf == meta_function::garbage_collect) {
19660  stack::set_field(L, first, detail::unique_destruct<T>, t.stack_index());
19661  return;
19662  }
19663  break;
19664  case 2:
19665  default:
19666  break;
19667  }
19668  stack::set_field(L, first, second, t.stack_index());
19669  };
19670  for (std::size_t i = 0; i < 3; ++i) {
19671  const char* metakey = nullptr;
19672  switch (i) {
19673  case 0:
19674  metakey = &usertype_traits<T*>::metatable()[0];
19675  break;
19676  case 1:
19677  metakey = &usertype_traits<detail::unique_usertype<T>>::metatable()[0];
19678  break;
19679  case 2:
19680  default:
19681  metakey = &usertype_traits<T>::metatable()[0];
19682  break;
19683  }
19684  luaL_newmetatable(L, metakey);
19685  stack_reference t(L, -1);
19686  stack::set_field(L, meta_function::type, type_table, t.stack_index());
19687 
19688  for (auto& kvp : varmap.functions) {
19689  auto& first = std::get<0>(kvp);
19690  auto& second = std::get<1>(kvp);
19691  register_kvp(i, t, first, second);
19692  }
19693  luaL_Reg opregs[34]{};
19694  int opregsindex = 0;
19695  auto prop_fx = [&](meta_function mf) { return !properties[static_cast<int>(mf)]; };
19696  usertype_detail::insert_default_registrations<T>(opregs, opregsindex, prop_fx);
19697  t.push();
19698  luaL_setfuncs(L, opregs, 0);
19699  t.pop();
19700 
19701  if (umx.baseclasscheck != nullptr) {
19702  stack::set_field(L, detail::base_class_check_key(), umx.baseclasscheck, t.stack_index());
19703  }
19704  if (umx.baseclasscast != nullptr) {
19705  stack::set_field(L, detail::base_class_cast_key(), umx.baseclasscast, t.stack_index());
19706  }
19707 
19708  // Base class propagation features
19711 
19712  if (umx.mustindex) {
19713  // use indexing function
19715  make_closure(sic,
19716  nullptr,
19717  make_light(varmap)),
19718  t.stack_index());
19720  make_closure(snic,
19721  nullptr,
19722  make_light(varmap)),
19723  t.stack_index());
19724  }
19725  else {
19726  // Metatable indexes itself
19728  }
19729  // metatable on the metatable
19730  // for call constructor purposes and such
19731  lua_createtable(L, 0, 2 * static_cast<int>(umx.secondarymeta) + static_cast<int>(umx.callconstructfunc.valid()));
19732  stack_reference metabehind(L, -1);
19733  stack::set_field(L, meta_function::type, type_table, metabehind.stack_index());
19734  if (umx.callconstructfunc.valid()) {
19735  stack::set_field(L, meta_function::call_function, umx.callconstructfunc, metabehind.stack_index());
19736  }
19737  if (umx.secondarymeta) {
19739  make_closure(sic,
19740  nullptr,
19741  make_light(varmap)),
19742  metabehind.stack_index());
19744  make_closure(snic,
19745  nullptr,
19746  make_light(varmap)),
19747  metabehind.stack_index());
19748  }
19749  stack::set_field(L, metatable_key, metabehind, t.stack_index());
19750  metabehind.pop();
19751 
19752  t.pop();
19753  }
19754 
19755  // Now for the shim-table that actually gets pushed
19756  luaL_newmetatable(L, &usertype_traits<T>::user_metatable()[0]);
19757  stack_reference t(L, -1);
19758  stack::set_field(L, meta_function::type, type_table, t.stack_index());
19759 
19760  for (auto& kvp : varmap.functions) {
19761  auto& first = std::get<0>(kvp);
19762  auto& second = std::get<1>(kvp);
19763  register_kvp(2, t, first, second);
19764  }
19765  {
19766  lua_createtable(L, 0, 2 + static_cast<int>(umx.callconstructfunc.valid()));
19767  stack_reference metabehind(L, -1);
19768  stack::set_field(L, meta_function::type, type_table, metabehind.stack_index());
19769  if (umx.callconstructfunc.valid()) {
19770  stack::set_field(L, meta_function::call_function, umx.callconstructfunc, metabehind.stack_index());
19771  }
19772  // use indexing function
19774  make_closure(sic,
19775  nullptr,
19776  make_light(varmap),
19777  nullptr,
19778  nullptr,
19780  metabehind.stack_index());
19782  make_closure(snic,
19783  nullptr,
19784  make_light(varmap),
19785  nullptr,
19786  nullptr,
19788  metabehind.stack_index());
19789  stack::set_field(L, metatable_key, metabehind, t.stack_index());
19790  metabehind.pop();
19791  }
19792 
19793  lua_remove(L, type_table.stack_index());
19794 
19795  // Don't pop the table when we're done;
19796  // return it
19797  return 1;
19798  }
19799  };
19800  } // namespace stack
19801 } // namespace sol
19802 
19803 // end of sol/simple_usertype_metatable.hpp
19804 
19805 namespace sol {
19806 
19807  template <typename T>
19808  class usertype {
19809  private:
19810  std::unique_ptr<usertype_detail::registrar> metatableregister;
19811 
19812  template <typename... Args>
19814  : metatableregister(std::make_unique<usertype_metatable<T, std::make_index_sequence<sizeof...(Args) / 2>, Args...>>(std::forward<Args>(args)...)) {
19815  static_assert(detail::has_destructor<Args...>::value, "this type does not have an explicit destructor declared; please pass a custom destructor function wrapped in sol::destruct, especially if the type does not have an accessible (private) destructor");
19816  }
19817 
19818  template <typename... Args>
19820  : usertype(detail::verified, std::forward<Args>(args)..., "__gc", default_destructor) {
19821  }
19822 
19823  template <typename... Args>
19825  : usertype(meta::condition<meta::all<std::is_destructible<T>, meta::neg<detail::has_destructor<Args...>>>, detail::add_destructor_tag, detail::verified_tag>(), std::forward<Args>(args)...) {
19826  }
19827 
19828  public:
19829  template <typename... Args>
19830  usertype(Args&&... args)
19831  : usertype(meta::condition<meta::all<std::is_default_constructible<T>, meta::neg<detail::has_constructor<Args...>>>, decltype(default_constructor), detail::check_destructor_tag>(), std::forward<Args>(args)...) {
19832  }
19833 
19834  template <typename... Args, typename... CArgs>
19835  usertype(constructors<CArgs...> constructorlist, Args&&... args)
19836  : usertype(detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {
19837  }
19838 
19839  template <typename... Args, typename... Fxs>
19840  usertype(constructor_wrapper<Fxs...> constructorlist, Args&&... args)
19841  : usertype(detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {
19842  }
19843 
19844  template <typename... Args>
19845  usertype(simple_tag, lua_State* L, Args&&... args)
19846  : metatableregister(std::make_unique<simple_usertype_metatable<T>>(L, std::forward<Args>(args)...)) {
19847  }
19848 
19850  return metatableregister.get();
19851  }
19852 
19853  int push(lua_State* L) {
19854  int r = metatableregister->push_um(L);
19855  metatableregister = nullptr;
19856  return r;
19857  }
19858  };
19859 
19860  template <typename T>
19861  class simple_usertype : public usertype<T> {
19862  private:
19864  lua_State* state;
19865 
19866  public:
19867  template <typename... Args>
19868  simple_usertype(lua_State* L, Args&&... args)
19869  : base_t(simple, L, std::forward<Args>(args)...), state(L) {
19870  }
19871 
19872  template <typename N, typename F>
19873  void set(N&& n, F&& f) {
19874  auto meta = static_cast<simple_usertype_metatable<T>*>(base_t::registrar_data());
19875  meta->add(state, std::forward<N>(n), std::forward<F>(f));
19876  }
19877  };
19878 
19879  namespace stack {
19880  template <typename T>
19881  struct pusher<usertype<T>> {
19882  static int push(lua_State* L, usertype<T>& user) {
19883  return user.push(L);
19884  }
19885  };
19886  } // namespace stack
19887 } // namespace sol
19888 
19889 // end of sol/usertype.hpp
19890 
19891 // beginning of sol/table_iterator.hpp
19892 
19893 namespace sol {
19894 
19895  template <typename reference_type>
19896  class basic_table_iterator : public std::iterator<std::input_iterator_tag, std::pair<object, object>> {
19897  public:
19898  typedef object key_type;
19899  typedef object mapped_type;
19900  typedef std::pair<object, object> value_type;
19901  typedef std::input_iterator_tag iterator_category;
19902  typedef std::ptrdiff_t difference_type;
19903  typedef value_type* pointer;
19904  typedef value_type& reference;
19905  typedef const value_type& const_reference;
19906 
19907  private:
19908  std::pair<object, object> kvp;
19909  reference_type ref;
19910  int tableidx = 0;
19911  int keyidx = 0;
19912  std::ptrdiff_t idx = 0;
19913 
19914  public:
19916  : keyidx(-1), idx(-1) {
19917  }
19918 
19919  basic_table_iterator(reference_type x)
19920  : ref(std::move(x)) {
19921  ref.push();
19922  tableidx = lua_gettop(ref.lua_state());
19923  stack::push(ref.lua_state(), lua_nil);
19924  this->operator++();
19925  if (idx == -1) {
19926  return;
19927  }
19928  --idx;
19929  }
19930 
19932  if (idx == -1)
19933  return *this;
19934 
19935  if (lua_next(ref.lua_state(), tableidx) == 0) {
19936  idx = -1;
19937  keyidx = -1;
19938  return *this;
19939  }
19940  ++idx;
19941  kvp.first = object(ref.lua_state(), -2);
19942  kvp.second = object(ref.lua_state(), -1);
19943  lua_pop(ref.lua_state(), 1);
19944  // leave key on the stack
19945  keyidx = lua_gettop(ref.lua_state());
19946  return *this;
19947  }
19948 
19950  auto saved = *this;
19951  this->operator++();
19952  return saved;
19953  }
19954 
19955  reference operator*() {
19956  return kvp;
19957  }
19958 
19959  const_reference operator*() const {
19960  return kvp;
19961  }
19962 
19963  bool operator==(const basic_table_iterator& right) const {
19964  return idx == right.idx;
19965  }
19966 
19967  bool operator!=(const basic_table_iterator& right) const {
19968  return idx != right.idx;
19969  }
19970 
19972  if (keyidx != -1) {
19973  stack::remove(ref.lua_state(), keyidx, 1);
19974  }
19975  if (ref.lua_state() != nullptr && ref.valid()) {
19976  stack::remove(ref.lua_state(), tableidx, 1);
19977  }
19978  }
19979  };
19980 
19981 } // namespace sol
19982 
19983 // end of sol/table_iterator.hpp
19984 
19985 namespace sol {
19986  namespace detail {
19987  template <std::size_t n>
19988  struct clean {
19989  lua_State* L;
19990  clean(lua_State* luastate)
19991  : L(luastate) {
19992  }
19994  lua_pop(L, static_cast<int>(n));
19995  }
19996  };
19997  struct ref_clean {
19998  lua_State* L;
19999  int& n;
20000  ref_clean(lua_State* luastate, int& n)
20001  : L(luastate), n(n) {
20002  }
20004  lua_pop(L, static_cast<int>(n));
20005  }
20006  };
20007  inline int fail_on_newindex(lua_State* L) {
20008  return luaL_error(L, "sol: cannot modify the elements of an enumeration table");
20009  }
20010  } // namespace detail
20011 
20013 
20014  template <bool top_level, typename base_type>
20015  class basic_table_core : public basic_object_base<base_type> {
20017  friend class state;
20018  friend class state_view;
20019 
20020  template <typename... Args>
20022 
20023  template <typename Fx>
20024  void for_each(std::true_type, Fx&& fx) const {
20025  auto pp = stack::push_pop(*this);
20026  stack::push(base_t::lua_state(), lua_nil);
20027  while (lua_next(base_t::lua_state(), -2)) {
20028  object key(base_t::lua_state(), -2);
20029  object value(base_t::lua_state(), -1);
20030  std::pair<object&, object&> keyvalue(key, value);
20031  auto pn = stack::pop_n(base_t::lua_state(), 1);
20032  fx(keyvalue);
20033  }
20034  }
20035 
20036  template <typename Fx>
20037  void for_each(std::false_type, Fx&& fx) const {
20038  auto pp = stack::push_pop(*this);
20039  stack::push(base_t::lua_state(), lua_nil);
20040  while (lua_next(base_t::lua_state(), -2)) {
20041  object key(base_t::lua_state(), -2);
20042  object value(base_t::lua_state(), -1);
20043  auto pn = stack::pop_n(base_t::lua_state(), 1);
20044  fx(key, value);
20045  }
20046  }
20047 
20048  template <bool raw, typename Ret0, typename Ret1, typename... Ret, std::size_t... I, typename Keys>
20049  auto tuple_get(types<Ret0, Ret1, Ret...>, std::index_sequence<0, 1, I...>, Keys&& keys) const
20050  -> decltype(stack::pop<std::tuple<Ret0, Ret1, Ret...>>(nullptr)) {
20051  typedef decltype(stack::pop<std::tuple<Ret0, Ret1, Ret...>>(nullptr)) Tup;
20052  return Tup(
20053  traverse_get_optional<top_level, raw, Ret0>(meta::is_optional<meta::unqualified_t<Ret0>>(), detail::forward_get<0>(keys)),
20054  traverse_get_optional<top_level, raw, Ret1>(meta::is_optional<meta::unqualified_t<Ret1>>(), detail::forward_get<1>(keys)),
20055  traverse_get_optional<top_level, raw, Ret>(meta::is_optional<meta::unqualified_t<Ret>>(), detail::forward_get<I>(keys))...);
20056  }
20057 
20058  template <bool raw, typename Ret, std::size_t I, typename Keys>
20059  decltype(auto) tuple_get(types<Ret>, std::index_sequence<I>, Keys&& keys) const {
20060  return traverse_get_optional<top_level, raw, Ret>(meta::is_optional<meta::unqualified_t<Ret>>(), detail::forward_get<I>(keys));
20061  }
20062 
20063  template <bool raw, typename Pairs, std::size_t... I>
20064  void tuple_set(std::index_sequence<I...>, Pairs&& pairs) {
20065  auto pp = stack::push_pop < top_level && (is_global<decltype(detail::forward_get<I * 2>(pairs))...>::value) > (*this);
20066  void(detail::swallow{ (stack::set_field<top_level, raw>(base_t::lua_state(),
20067  detail::forward_get<I * 2>(pairs),
20068  detail::forward_get<I * 2 + 1>(pairs),
20069  lua_gettop(base_t::lua_state())),
20070  0)... });
20071  }
20072 
20073  template <bool global, bool raw, typename T, typename Key>
20074  decltype(auto) traverse_get_deep(Key&& key) const {
20075  stack::get_field<global, raw>(base_t::lua_state(), std::forward<Key>(key));
20076  return stack::get<T>(base_t::lua_state());
20077  }
20078 
20079  template <bool global, bool raw, typename T, typename Key, typename... Keys>
20080  decltype(auto) traverse_get_deep(Key&& key, Keys&&... keys) const {
20081  stack::get_field<global, raw>(base_t::lua_state(), std::forward<Key>(key));
20082  return traverse_get_deep<false, raw, T>(std::forward<Keys>(keys)...);
20083  }
20084 
20085  template <bool global, bool raw, typename T, std::size_t I, typename Key>
20086  decltype(auto) traverse_get_deep_optional(int& popcount, Key&& key) const {
20087  typedef decltype(stack::get<T>(base_t::lua_state())) R;
20088  auto p = stack::probe_get_field<global, raw, T>(base_t::lua_state(), std::forward<Key>(key), lua_gettop(base_t::lua_state()));
20089  popcount += p.levels;
20090  if (!p.success)
20091  return R(nullopt);
20092  return stack::get<T>(base_t::lua_state());
20093  }
20094 
20095  template <bool global, bool raw, typename T, std::size_t I, typename Key, typename... Keys>
20096  decltype(auto) traverse_get_deep_optional(int& popcount, Key&& key, Keys&&... keys) const {
20097  auto p = I > 0 ? stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), -1) : stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), lua_gettop(base_t::lua_state()));
20098  popcount += p.levels;
20099  if (!p.success)
20100  return T(nullopt);
20101  return traverse_get_deep_optional<false, raw, T, I + 1>(popcount, std::forward<Keys>(keys)...);
20102  }
20103 
20104  template <bool global, bool raw, typename T, typename... Keys>
20105  decltype(auto) traverse_get_optional(std::false_type, Keys&&... keys) const {
20106  detail::clean<sizeof...(Keys)> c(base_t::lua_state());
20107  return traverse_get_deep<global, raw, T>(std::forward<Keys>(keys)...);
20108  }
20109 
20110  template <bool global, bool raw, typename T, typename... Keys>
20111  decltype(auto) traverse_get_optional(std::true_type, Keys&&... keys) const {
20112  int popcount = 0;
20113  detail::ref_clean c(base_t::lua_state(), popcount);
20114  return traverse_get_deep_optional<global, raw, T, 0>(popcount, std::forward<Keys>(keys)...);
20115  }
20116 
20117  template <bool global, bool raw, typename Key, typename Value>
20118  void traverse_set_deep(Key&& key, Value&& value) const {
20119  stack::set_field<global, raw>(base_t::lua_state(), std::forward<Key>(key), std::forward<Value>(value));
20120  }
20121 
20122  template <bool global, bool raw, typename Key, typename... Keys>
20123  void traverse_set_deep(Key&& key, Keys&&... keys) const {
20124  stack::get_field<global, raw>(base_t::lua_state(), std::forward<Key>(key));
20125  traverse_set_deep<false, raw>(std::forward<Keys>(keys)...);
20126  }
20127 
20128  basic_table_core(lua_State* L, detail::global_tag t) noexcept
20129  : base_t(L, t) {
20130  }
20131 
20132  protected:
20134  : base_t(n) {
20135  }
20136  basic_table_core(detail::no_safety_tag, lua_State* L, int index)
20137  : base_t(L, index) {
20138  }
20140  : base_t(L, index) {
20141  }
20142  template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_table_core>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
20144  : base_t(std::forward<T>(r)) {
20145  }
20146  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
20147  basic_table_core(detail::no_safety_tag, lua_State*L, T&& r) noexcept
20148  : base_t(L, std::forward<T>(r)) {
20149  }
20150 
20151  public:
20153  typedef iterator const_iterator;
20154 
20155  using base_t::lua_state;
20156 
20157  basic_table_core() noexcept = default;
20158  basic_table_core(const basic_table_core&) = default;
20159  basic_table_core(basic_table_core&&) = default;
20160  basic_table_core& operator=(const basic_table_core&) = default;
20161  basic_table_core& operator=(basic_table_core&&) = default;
20163  : basic_table_core(r.lua_state(), r.stack_index()) {
20164  }
20166  : basic_table_core(r.lua_state(), r.stack_index()) {
20167  }
20168  template <typename T, meta::enable_any<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
20169  basic_table_core(lua_State* L, T&& r)
20170  : base_t(L, std::forward<T>(r)) {
20171 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20172  auto pp = stack::push_pop(*this);
20174  stack::check<basic_table_core>(lua_state(), -1, handler);
20175 #endif // Safety
20176  }
20177  basic_table_core(lua_State* L, const new_table& nt)
20178  : base_t(L, -stack::push(L, nt)) {
20180  lua_pop(L, 1);
20181  }
20182  }
20183  basic_table_core(lua_State* L, int index = -1)
20184  : basic_table_core(detail::no_safety, L, index) {
20185 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20187  stack::check<basic_table_core>(L, index, handler);
20188 #endif // Safety
20189  }
20190  basic_table_core(lua_State* L, ref_index index)
20191  : basic_table_core(detail::no_safety, L, index) {
20192 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20193  auto pp = stack::push_pop(*this);
20195  stack::check<basic_table_core>(lua_state(), -1, handler);
20196 #endif // Safety
20197  }
20198  template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_table_core>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
20199  basic_table_core(T&& r) noexcept
20200  : basic_table_core(detail::no_safety, std::forward<T>(r)) {
20201 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20202  if (!is_table<meta::unqualified_t<T>>::value) {
20203  auto pp = stack::push_pop(*this);
20205  stack::check<basic_table_core>(base_t::lua_state(), -1, handler);
20206  }
20207 #endif // Safety
20208  }
20211  }
20212 
20213  iterator begin() const {
20214  return iterator(*this);
20215  }
20216 
20217  iterator end() const {
20218  return iterator();
20219  }
20220 
20221  const_iterator cbegin() const {
20222  return begin();
20223  }
20224 
20225  const_iterator cend() const {
20226  return end();
20227  }
20228 
20229  template <typename... Ret, typename... Keys>
20230  decltype(auto) get(Keys&&... keys) const {
20231  static_assert(sizeof...(Keys) == sizeof...(Ret), "number of keys and number of return types do not match");
20232  auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
20233  return tuple_get<false>(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), std::forward_as_tuple(std::forward<Keys>(keys)...));
20234  }
20235 
20236  template <typename T, typename Key>
20237  decltype(auto) get_or(Key&& key, T&& otherwise) const {
20238  typedef decltype(get<T>("")) U;
20239  optional<U> option = get<optional<U>>(std::forward<Key>(key));
20240  if (option) {
20241  return static_cast<U>(option.value());
20242  }
20243  return static_cast<U>(std::forward<T>(otherwise));
20244  }
20245 
20246  template <typename T, typename Key, typename D>
20247  decltype(auto) get_or(Key&& key, D&& otherwise) const {
20248  optional<T> option = get<optional<T>>(std::forward<Key>(key));
20249  if (option) {
20250  return static_cast<T>(option.value());
20251  }
20252  return static_cast<T>(std::forward<D>(otherwise));
20253  }
20254 
20255  template <typename T, typename... Keys>
20256  decltype(auto) traverse_get(Keys&&... keys) const {
20257  auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
20258  return traverse_get_optional<top_level, false, T>(meta::is_optional<meta::unqualified_t<T>>(), std::forward<Keys>(keys)...);
20259  }
20260 
20261  template <typename... Keys>
20262  basic_table_core& traverse_set(Keys&&... keys) {
20263  auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
20264  auto pn = stack::pop_n(base_t::lua_state(), static_cast<int>(sizeof...(Keys) - 2));
20265  traverse_set_deep<top_level, false>(std::forward<Keys>(keys)...);
20266  return *this;
20267  }
20268 
20269  template <typename... Args>
20270  basic_table_core& set(Args&&... args) {
20271  tuple_set<false>(std::make_index_sequence<sizeof...(Args) / 2>(), std::forward_as_tuple(std::forward<Args>(args)...));
20272  return *this;
20273  }
20274 
20275  template <typename... Ret, typename... Keys>
20276  decltype(auto) raw_get(Keys&&... keys) const {
20277  static_assert(sizeof...(Keys) == sizeof...(Ret), "number of keys and number of return types do not match");
20278  auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
20279  return tuple_get<true>(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), std::forward_as_tuple(std::forward<Keys>(keys)...));
20280  }
20281 
20282  template <typename T, typename Key>
20283  decltype(auto) raw_get_or(Key&& key, T&& otherwise) const {
20284  typedef decltype(raw_get<T>("")) U;
20285  optional<U> option = raw_get<optional<U>>(std::forward<Key>(key));
20286  if (option) {
20287  return static_cast<U>(option.value());
20288  }
20289  return static_cast<U>(std::forward<T>(otherwise));
20290  }
20291 
20292  template <typename T, typename Key, typename D>
20293  decltype(auto) raw_get_or(Key&& key, D&& otherwise) const {
20294  optional<T> option = raw_get<optional<T>>(std::forward<Key>(key));
20295  if (option) {
20296  return static_cast<T>(option.value());
20297  }
20298  return static_cast<T>(std::forward<D>(otherwise));
20299  }
20300 
20301  template <typename T, typename... Keys>
20302  decltype(auto) traverse_raw_get(Keys&&... keys) const {
20303  auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
20304  return traverse_get_optional<top_level, true, T>(meta::is_optional<meta::unqualified_t<T>>(), std::forward<Keys>(keys)...);
20305  }
20306 
20307  template <typename... Keys>
20309  auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
20310  auto pn = stack::pop_n(base_t::lua_state(), static_cast<int>(sizeof...(Keys) - 2));
20311  traverse_set_deep<top_level, true>(std::forward<Keys>(keys)...);
20312  return *this;
20313  }
20314 
20315  template <typename... Args>
20316  basic_table_core& raw_set(Args&&... args) {
20317  tuple_set<true>(std::make_index_sequence<sizeof...(Args) / 2>(), std::forward_as_tuple(std::forward<Args>(args)...));
20318  return *this;
20319  }
20320 
20321  template <typename T>
20323  return set_usertype(usertype_traits<T>::name(), user);
20324  }
20325 
20326  template <typename Key, typename T>
20328  return set(std::forward<Key>(key), user);
20329  }
20330 
20331  template <typename Class, typename... Args>
20332  basic_table_core& new_usertype(const std::string& name, Args&&... args) {
20333  usertype<Class> utype(std::forward<Args>(args)...);
20334  set_usertype(name, utype);
20335  return *this;
20336  }
20337 
20338  template <typename Class, typename CTor0, typename... CTor, typename... Args>
20339  basic_table_core& new_usertype(const std::string& name, Args&&... args) {
20340  constructors<types<CTor0, CTor...>> ctor{};
20341  return new_usertype<Class>(name, ctor, std::forward<Args>(args)...);
20342  }
20343 
20344  template <typename Class, typename... CArgs, typename... Args>
20345  basic_table_core& new_usertype(const std::string& name, constructors<CArgs...> ctor, Args&&... args) {
20346  usertype<Class> utype(ctor, std::forward<Args>(args)...);
20347  set_usertype(name, utype);
20348  return *this;
20349  }
20350 
20351  template <typename Class, typename... Args>
20352  basic_table_core& new_simple_usertype(const std::string& name, Args&&... args) {
20353  simple_usertype<Class> utype(base_t::lua_state(), std::forward<Args>(args)...);
20354  set_usertype(name, utype);
20355  return *this;
20356  }
20357 
20358  template <typename Class, typename CTor0, typename... CTor, typename... Args>
20359  basic_table_core& new_simple_usertype(const std::string& name, Args&&... args) {
20360  constructors<types<CTor0, CTor...>> ctor{};
20361  return new_simple_usertype<Class>(name, ctor, std::forward<Args>(args)...);
20362  }
20363 
20364  template <typename Class, typename... CArgs, typename... Args>
20366  simple_usertype<Class> utype(base_t::lua_state(), ctor, std::forward<Args>(args)...);
20367  set_usertype(name, utype);
20368  return *this;
20369  }
20370 
20371  template <typename Class, typename... Args>
20373  simple_usertype<Class> utype(base_t::lua_state(), std::forward<Args>(args)...);
20374  return utype;
20375  }
20376 
20377  template <typename Class, typename CTor0, typename... CTor, typename... Args>
20379  constructors<types<CTor0, CTor...>> ctor{};
20380  return create_simple_usertype<Class>(ctor, std::forward<Args>(args)...);
20381  }
20382 
20383  template <typename Class, typename... CArgs, typename... Args>
20385  simple_usertype<Class> utype(base_t::lua_state(), ctor, std::forward<Args>(args)...);
20386  return utype;
20387  }
20388 
20389  template <bool read_only = true, typename... Args>
20390  table new_enum(const string_view& name, Args&&... args) {
20391  table target = create_with(std::forward<Args>(args)...);
20392  if (read_only) {
20393  table x = create_with(
20395  meta_function::index, target);
20396  table shim = create_named(name, metatable_key, x);
20397  return shim;
20398  }
20399  else {
20400  set(name, target);
20401  return target;
20402  }
20403  }
20404 
20405  template <typename T, bool read_only = true>
20406  table new_enum(const string_view& name, std::initializer_list<std::pair<string_view, T>> items) {
20407  table target = create(static_cast<int>(items.size()), static_cast<int>(0));
20408  for (const auto& kvp : items) {
20409  target.set(kvp.first, kvp.second);
20410  }
20411  if (read_only) {
20412  table x = create_with(
20414  meta_function::index, target);
20415  table shim = create_named(name, metatable_key, x);
20416  return shim;
20417  }
20418  else {
20419  set(name, target);
20420  return target;
20421  }
20422  }
20423 
20424  template <typename Fx>
20425  void for_each(Fx&& fx) const {
20427  for_each(is_paired(), std::forward<Fx>(fx));
20428  }
20429 
20430  size_t size() const {
20431  auto pp = stack::push_pop(*this);
20432  lua_len(base_t::lua_state(), -1);
20433  return stack::pop<size_t>(base_t::lua_state());
20434  }
20435 
20436  bool empty() const {
20437  return cbegin() == cend();
20438  }
20439 
20440  template <typename T>
20442  return proxy<basic_table_core&, T>(*this, std::forward<T>(key));
20443  }
20444 
20445  template <typename T>
20447  return proxy<const basic_table_core&, T>(*this, std::forward<T>(key));
20448  }
20449 
20450  template <typename T>
20452  return proxy<basic_table_core, T>(*this, std::forward<T>(key));
20453  }
20454 
20455  template <typename Sig, typename Key, typename... Args>
20456  basic_table_core& set_function(Key&& key, Args&&... args) {
20457  set_fx(types<Sig>(), std::forward<Key>(key), std::forward<Args>(args)...);
20458  return *this;
20459  }
20460 
20461  template <typename Key, typename... Args>
20462  basic_table_core& set_function(Key&& key, Args&&... args) {
20463  set_fx(types<>(), std::forward<Key>(key), std::forward<Args>(args)...);
20464  return *this;
20465  }
20466 
20467  template <typename... Args>
20468  basic_table_core& add(Args&&... args) {
20469  auto pp = stack::push_pop(*this);
20470  (void)detail::swallow{ 0,
20471  (stack::set_ref(base_t::lua_state(), std::forward<Args>(args)), 0)... };
20472  return *this;
20473  }
20474 
20475  private:
20476  template <typename R, typename... Args, typename Fx, typename Key, typename = std::result_of_t<Fx(Args...)>>
20477  void set_fx(types<R(Args...)>, Key&& key, Fx&& fx) {
20478  set_resolved_function<R(Args...)>(std::forward<Key>(key), std::forward<Fx>(fx));
20479  }
20480 
20481  template <typename Fx, typename Key, meta::enable<meta::is_specialization_of<meta::unqualified_t<Fx>, overload_set>> = meta::enabler>
20482  void set_fx(types<>, Key&& key, Fx&& fx) {
20483  set(std::forward<Key>(key), std::forward<Fx>(fx));
20484  }
20485 
20486  template <typename Fx, typename Key, typename... Args, meta::disable<meta::is_specialization_of<meta::unqualified_t<Fx>, overload_set>> = meta::enabler>
20487  void set_fx(types<>, Key&& key, Fx&& fx, Args&&... args) {
20488  set(std::forward<Key>(key), as_function_reference(std::forward<Fx>(fx), std::forward<Args>(args)...));
20489  }
20490 
20491  template <typename... Sig, typename... Args, typename Key>
20492  void set_resolved_function(Key&& key, Args&&... args) {
20493  set(std::forward<Key>(key), as_function_reference<function_sig<Sig...>>(std::forward<Args>(args)...));
20494  }
20495 
20496  public:
20497  static inline table create(lua_State* L, int narr = 0, int nrec = 0) {
20498  lua_createtable(L, narr, nrec);
20499  table result(L);
20500  lua_pop(L, 1);
20501  return result;
20502  }
20503 
20504  template <typename Key, typename Value, typename... Args>
20505  static inline table create(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
20506  lua_createtable(L, narr, nrec);
20507  table result(L);
20508  result.set(std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
20509  lua_pop(L, 1);
20510  return result;
20511  }
20512 
20513  template <typename... Args>
20514  static inline table create_with(lua_State* L, Args&&... args) {
20515  static_assert(sizeof...(Args) % 2 == 0, "You must have an even number of arguments for a key, value ... list.");
20516  static const int narr = static_cast<int>(meta::count_2_for_pack<std::is_integral, Args...>::value);
20517  return create(L, narr, static_cast<int>((sizeof...(Args) / 2) - narr), std::forward<Args>(args)...);
20518  }
20519 
20520  table create(int narr = 0, int nrec = 0) {
20521  return create(base_t::lua_state(), narr, nrec);
20522  }
20523 
20524  template <typename Key, typename Value, typename... Args>
20525  table create(int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
20526  return create(base_t::lua_state(), narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
20527  }
20528 
20529  template <typename Name>
20530  table create(Name&& name, int narr = 0, int nrec = 0) {
20531  table x = create(base_t::lua_state(), narr, nrec);
20532  this->set(std::forward<Name>(name), x);
20533  return x;
20534  }
20535 
20536  template <typename Name, typename Key, typename Value, typename... Args>
20537  table create(Name&& name, int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
20538  table x = create(base_t::lua_state(), narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
20539  this->set(std::forward<Name>(name), x);
20540  return x;
20541  }
20542 
20543  template <typename... Args>
20544  table create_with(Args&&... args) {
20545  return create_with(base_t::lua_state(), std::forward<Args>(args)...);
20546  }
20547 
20548  template <typename Name, typename... Args>
20549  table create_named(Name&& name, Args&&... args) {
20550  static const int narr = static_cast<int>(meta::count_2_for_pack<std::is_integral, Args...>::value);
20551  return create(std::forward<Name>(name), narr, (sizeof...(Args) / 2) - narr, std::forward<Args>(args)...);
20552  }
20553  };
20554 } // namespace sol
20555 
20556 // end of sol/table_core.hpp
20557 
20558 namespace sol {
20559  typedef table_core<false> table;
20560 
20561  namespace stack {
20562  template <>
20564  static table get(lua_State* L, int index = -1) {
20565  if (lua_getmetatable(L, index) == 0) {
20566  return table(L, ref_index(LUA_REFNIL));
20567  }
20568  return table(L, -1);
20569  }
20570  };
20571  } // namespace stack
20572 } // namespace sol
20573 
20574 // end of sol/table.hpp
20575 
20576 // beginning of sol/environment.hpp
20577 
20578 namespace sol {
20579 
20580  template <typename base_type>
20581  struct basic_environment : basic_table<base_type> {
20582  private:
20584 
20585  public:
20586  using base_t::lua_state;
20587 
20588  basic_environment() noexcept = default;
20589  basic_environment(const basic_environment&) = default;
20590  basic_environment(basic_environment&&) = default;
20591  basic_environment& operator=(const basic_environment&) = default;
20592  basic_environment& operator=(basic_environment&&) = default;
20594  : basic_environment(r.lua_state(), r.stack_index()) {
20595  }
20597  : basic_environment(r.lua_state(), r.stack_index()) {
20598  }
20599 
20600  basic_environment(lua_State* L, new_table nt)
20601  : base_t(L, std::move(nt)) {
20602  }
20603  template <bool b>
20604  basic_environment(lua_State* L, new_table t, const basic_reference<b>& fallback)
20605  : basic_environment(L, std::move(t)) {
20606  stack_table mt(L, new_table(0, 1));
20607  mt.set(meta_function::index, fallback);
20608  this->set(metatable_key, mt);
20609  mt.pop();
20610  }
20611 
20612  basic_environment(env_t, const stack_reference& extraction_target)
20613  : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) {
20614 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20616  stack::check<env_t>(this->lua_state(), -1, handler);
20617 #endif // Safety
20618  lua_pop(this->lua_state(), 2);
20619  }
20620  template <bool b>
20621  basic_environment(env_t, const basic_reference<b>& extraction_target)
20622  : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) {
20623 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20625  stack::check<env_t>(this->lua_state(), -1, handler);
20626 #endif // Safety
20627  lua_pop(this->lua_state(), 2);
20628  }
20629  basic_environment(lua_State* L, int index = -1)
20630  : base_t(detail::no_safety, L, index) {
20631 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20633  stack::check<basic_environment>(L, index, handler);
20634 #endif // Safety
20635  }
20636  basic_environment(lua_State* L, ref_index index)
20637  : base_t(detail::no_safety, L, index) {
20638 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20639  auto pp = stack::push_pop(*this);
20641  stack::check<basic_environment>(L, -1, handler);
20642 #endif // Safety
20643  }
20644  template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_environment>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
20645  basic_environment(T&& r) noexcept
20646  : base_t(detail::no_safety, std::forward<T>(r)) {
20647 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20648  if (!is_environment<meta::unqualified_t<T>>::value) {
20649  auto pp = stack::push_pop(*this);
20651  stack::check<basic_environment>(lua_state(), -1, handler);
20652  }
20653 #endif // Safety
20654  }
20656  : base_t(detail::no_safety, r) {
20657  }
20658 
20659  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
20660  basic_environment(lua_State* L, T&& r) noexcept
20661  : base_t(detail::no_safety, L, std::forward<T>(r)) {
20662 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
20663  if (!is_environment<meta::unqualified_t<T>>::value) {
20664  auto pp = stack::push_pop(*this);
20666  stack::check<basic_environment>(lua_state(), -1, handler);
20667  }
20668 #endif // Safety
20669  }
20670 
20671  template <typename T>
20672  void set_on(const T& target) const {
20673  lua_State* L = target.lua_state();
20674  auto pp = stack::push_pop(target);
20675 #if SOL_LUA_VERSION < 502
20676  // Use lua_setfenv
20677  this->push();
20678  lua_setfenv(L, -2);
20679 #else
20680  // Use upvalues as explained in Lua 5.2 and beyond's manual
20681  this->push();
20682  const char* name = lua_setupvalue(L, -2, 1);
20683  if (name == nullptr) {
20684  this->pop();
20685  }
20686 #endif
20687  }
20688  };
20689 
20690  template <typename T, typename E>
20691  void set_environment(const basic_environment<E>& env, const T& target) {
20692  env.set_on(target);
20693  }
20694 
20695  template <typename E = reference, typename T>
20697  lua_State* L = target.lua_state();
20698  auto pp = stack::pop_n(L, stack::push_environment_of(target));
20699  return basic_environment<E>(L, -1);
20700  }
20701 
20704 
20706  : env(nullopt) {
20707  }
20709  : env(std::move(e)) {
20710  }
20711  this_environment(const this_environment&) = default;
20712  this_environment(this_environment&&) = default;
20713  this_environment& operator=(const this_environment&) = default;
20714  this_environment& operator=(this_environment&&) = default;
20715 
20716  explicit operator bool() const {
20717  return static_cast<bool>(env);
20718  }
20719 
20721  return env;
20722  }
20723 
20724  operator const optional<environment>&() const {
20725  return env;
20726  }
20727 
20728  operator environment&() {
20729  return env.value();
20730  }
20731 
20732  operator const environment&() const {
20733  return env.value();
20734  }
20735  };
20736 
20737  namespace stack {
20738  template <>
20739  struct getter<env_t> {
20740  static environment get(lua_State* L, int index, record& tracking) {
20741  tracking.use(1);
20742  return get_environment(stack_reference(L, raw_index(index)));
20743  }
20744  };
20745 
20746  template <>
20748  static this_environment get(lua_State* L, int, record& tracking) {
20749  tracking.use(0);
20750  lua_Debug info;
20751  // Level 0 means current function (this C function, which may or may not be useful for us?)
20752  // Level 1 means next call frame up the stack. (Can be nothing if function called directly from C++ with lua_p/call)
20753  int pre_stack_size = lua_gettop(L);
20754  if (lua_getstack(L, 1, &info) != 1) {
20755  if (lua_getstack(L, 0, &info) != 1) {
20756  lua_settop(L, pre_stack_size);
20757  return this_environment();
20758  }
20759  }
20760  if (lua_getinfo(L, "f", &info) == 0) {
20761  lua_settop(L, pre_stack_size);
20762  return this_environment();
20763  }
20764 
20765  stack_reference f(L, -1);
20766  environment env(env_key, f);
20767  if (!env.valid()) {
20768  lua_settop(L, pre_stack_size);
20769  return this_environment();
20770  }
20771  return this_environment(std::move(env));
20772  }
20773  };
20774  } // namespace stack
20775 } // namespace sol
20776 
20777 // end of sol/environment.hpp
20778 
20779 // beginning of sol/load_result.hpp
20780 
20781 namespace sol {
20782  struct load_result : public proxy_base<load_result> {
20783  private:
20784  lua_State* L;
20785  int index;
20789 
20790  template <typename T>
20791  decltype(auto) tagged_get(types<optional<T>>) const {
20792  if (!valid()) {
20793  return optional<T>(nullopt);
20794  }
20795  return stack::get<optional<T>>(L, index);
20796  }
20797 
20798  template <typename T>
20799  decltype(auto) tagged_get(types<T>) const {
20800 #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES != 0
20801  if (!valid()) {
20802  type_panic_c_str(L, index, type_of(L, index), type::none);
20803  }
20804 #endif // Check Argument Safety
20805  return stack::get<T>(L, index);
20806  }
20807 
20809  if (valid()) {
20810  return nullopt;
20811  }
20812  return error(detail::direct_error, stack::get<std::string>(L, index));
20813  }
20814 
20816 #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES != 0
20817  if (valid()) {
20818  type_panic_c_str(L, index, type_of(L, index), type::none, "expecting an error type (a string, from Lua)");
20819  }
20820 #endif // Check Argument Safety
20821  return error(detail::direct_error, stack::get<std::string>(L, index));
20822  }
20823 
20824  public:
20825  load_result() = default;
20826  load_result(lua_State* Ls, int stackindex = -1, int retnum = 0, int popnum = 0, load_status lerr = load_status::ok) noexcept
20827  : L(Ls), index(stackindex), returncount(retnum), popcount(popnum), err(lerr) {
20828  }
20829  load_result(const load_result&) = default;
20830  load_result& operator=(const load_result&) = default;
20831  load_result(load_result&& o) noexcept
20832  : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) {
20833  // Must be manual, otherwise destructor will screw us
20834  // return count being 0 is enough to keep things clean
20835  // but we will be thorough
20836  o.L = nullptr;
20837  o.index = 0;
20838  o.returncount = 0;
20839  o.popcount = 0;
20840  o.err = load_status::syntax;
20841  }
20843  L = o.L;
20844  index = o.index;
20845  returncount = o.returncount;
20846  popcount = o.popcount;
20847  err = o.err;
20848  // Must be manual, otherwise destructor will screw us
20849  // return count being 0 is enough to keep things clean
20850  // but we will be thorough
20851  o.L = nullptr;
20852  o.index = 0;
20853  o.returncount = 0;
20854  o.popcount = 0;
20855  o.err = load_status::syntax;
20856  return *this;
20857  }
20858 
20859  load_status status() const noexcept {
20860  return err;
20861  }
20862 
20863  bool valid() const noexcept {
20864  return status() == load_status::ok;
20865  }
20866 
20867  template <typename T>
20868  T get() const {
20870  }
20871 
20872  template <typename... Ret, typename... Args>
20873  decltype(auto) call(Args&&... args) {
20874 #if !defined(__clang__) && defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 191200000
20875  // MSVC is ass sometimes
20876  return get<protected_function>().call<Ret...>(std::forward<Args>(args)...);
20877 #else
20878  return get<protected_function>().template call<Ret...>(std::forward<Args>(args)...);
20879 #endif
20880  }
20881 
20882  template <typename... Args>
20883  decltype(auto) operator()(Args&&... args) {
20884  return call<>(std::forward<Args>(args)...);
20885  }
20886 
20887  lua_State* lua_state() const noexcept {
20888  return L;
20889  };
20890  int stack_index() const noexcept {
20891  return index;
20892  };
20893 
20895  stack::remove(L, index, popcount);
20896  }
20897  };
20898 } // namespace sol
20899 
20900 // end of sol/load_result.hpp
20901 
20902 // beginning of sol/state_handling.hpp
20903 
20904 #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
20905 #endif
20906 
20907 namespace sol {
20908  inline void register_main_thread(lua_State* L) {
20909 #if SOL_LUA_VERSION < 502
20910  if (L == nullptr) {
20911  lua_pushnil(L);
20912  lua_setglobal(L, detail::default_main_thread_name());
20913  return;
20914  }
20915  lua_pushthread(L);
20916  lua_setglobal(L, detail::default_main_thread_name());
20917 #else
20918  (void)L;
20919 #endif
20920  }
20921 
20922  inline int default_at_panic(lua_State* L) {
20923 #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
20924  (void)L;
20925  return -1;
20926 #else
20927  size_t messagesize;
20928  const char* message = lua_tolstring(L, -1, &messagesize);
20929  if (message) {
20930  std::string err(message, messagesize);
20931  lua_settop(L, 0);
20932 #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
20933  std::cerr << "[sol2] An error occurred and panic has been invoked: ";
20934  std::cerr << err;
20935  std::cerr << std::endl;
20936 #endif
20937  throw error(err);
20938  }
20939  lua_settop(L, 0);
20940  throw error(std::string("An unexpected error occurred and panic has been invoked"));
20941 #endif // Printing Errors
20942  }
20943 
20944  inline int default_traceback_error_handler(lua_State* L) {
20945  std::string msg = "An unknown error has triggered the default error handler";
20946  optional<string_view> maybetopmsg = stack::check_get<string_view>(L, 1);
20947  if (maybetopmsg) {
20948  const string_view& topmsg = maybetopmsg.value();
20949  msg.assign(topmsg.data(), topmsg.size());
20950  }
20951  luaL_traceback(L, L, msg.c_str(), 1);
20952  optional<string_view> maybetraceback = stack::check_get<string_view>(L, -1);
20953  if (maybetraceback) {
20954  const string_view& traceback = maybetraceback.value();
20955  msg.assign(traceback.data(), traceback.size());
20956  }
20957 #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
20958  //std::cerr << "[sol2] An error occurred and was caught in traceback: ";
20959  //std::cerr << msg;
20960  //std::cerr << std::endl;
20961 #endif // Printing
20962  return stack::push(L, msg);
20963  }
20964 
20965  inline void set_default_state(lua_State* L, lua_CFunction panic_function = &default_at_panic, lua_CFunction traceback_function = c_call<decltype(&default_traceback_error_handler), &default_traceback_error_handler>, exception_handler_function exf = detail::default_exception_handler) {
20966  lua_atpanic(L, panic_function);
20967  protected_function::set_default_handler(object(L, in_place, traceback_function));
20971  }
20972 
20973  inline std::size_t total_memory_used(lua_State* L) {
20974  std::size_t kb = lua_gc(L, LUA_GCCOUNT, 0);
20975  kb *= 1024;
20976  kb += lua_gc(L, LUA_GCCOUNTB, 0);
20977  return kb;
20978  }
20979 
20981  return result;
20982  }
20983 
20985  type t = type_of(L, result.stack_index());
20986  std::string err = "sol: ";
20987  err += to_string(result.status());
20988  err += " error";
20989 #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
20990  std::exception_ptr eptr = std::current_exception();
20991  if (eptr) {
20992  err += " with a ";
20993  try {
20994  std::rethrow_exception(eptr);
20995  }
20996  catch (const std::exception& ex) {
20997  err += "std::exception -- ";
20998  err.append(ex.what());
20999  }
21000  catch (const std::string& message) {
21001  err += "thrown message -- ";
21002  err.append(message);
21003  }
21004  catch (const char* message) {
21005  err += "thrown message -- ";
21006  err.append(message);
21007  }
21008  catch (...) {
21009  err.append("thrown but unknown type, cannot serialize into error message");
21010  }
21011  }
21012 #endif // serialize exception information if possible
21013  if (t == type::string) {
21014  err += ": ";
21015  string_view serr = stack::get<string_view>(L, result.stack_index());
21016  err.append(serr.data(), serr.size());
21017  }
21018 #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
21019  std::cerr << "[sol2] An error occurred and has been passed to an error handler: ";
21020  std::cerr << err;
21021  std::cerr << std::endl;
21022 #endif
21023  // replacing information of stack error into pfr
21024  int target = result.stack_index();
21025  if (result.pop_count() > 0) {
21026  stack::remove(L, target, result.pop_count());
21027  }
21028  stack::push(L, err);
21029  int top = lua_gettop(L);
21030  int towards = top - target;
21031  if (towards != 0) {
21032  lua_rotate(L, top, towards);
21033  }
21034 #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
21035  return result;
21036 #else
21037  // just throw our error
21038  throw error(detail::direct_error, err);
21039 #endif // If exceptions are allowed
21040  }
21041 
21043 #if defined(SOL_DEFAULT_PASS_ON_ERROR) && SOL_DEFAULT_PASS_ON_ERROR
21044  return script_pass_on_error(L, std::move(pfr));
21045 #else
21046  return script_throw_on_error(L, std::move(pfr));
21047 #endif
21048  }
21049 } // namespace sol
21050 
21051 // end of sol/state_handling.hpp
21052 
21053 namespace sol {
21054 
21055  class state_view {
21056  private:
21057  lua_State* L;
21060 
21062  auto loaded = reg.traverse_get<optional<object>>("_LOADED", key);
21063  bool is53mod = loaded && !(loaded->is<bool>() && !loaded->as<bool>());
21064  if (is53mod)
21065  return loaded;
21066 #if SOL_LUA_VERSION <= 501
21067  auto loaded51 = global.traverse_get<optional<object>>("package", "loaded", key);
21068  bool is51mod = loaded51 && !(loaded51->is<bool>() && !loaded51->as<bool>());
21069  if (is51mod)
21070  return loaded51;
21071 #endif
21072  return nullopt;
21073  }
21074 
21075  template <typename T>
21076  void ensure_package(const std::string& key, T&& sr) {
21077 #if SOL_LUA_VERSION <= 501
21078  auto pkg = global["package"];
21079  if (!pkg.valid()) {
21080  pkg = create_table_with("loaded", create_table_with(key, sr));
21081  }
21082  else {
21083  auto ld = pkg["loaded"];
21084  if (!ld.valid()) {
21085  ld = create_table_with(key, sr);
21086  }
21087  else {
21088  ld[key] = sr;
21089  }
21090  }
21091 #endif
21092  auto loaded = reg["_LOADED"];
21093  if (!loaded.valid()) {
21094  loaded = create_table_with(key, sr);
21095  }
21096  else {
21097  loaded[key] = sr;
21098  }
21099  }
21100 
21101  template <typename Fx>
21102  object require_core(const std::string& key, Fx&& action, bool create_global = true) {
21103  optional<object> loaded = is_loaded_package(key);
21104  if (loaded && loaded->valid())
21105  return std::move(*loaded);
21106  action();
21107  stack_reference sr(L, -1);
21108  if (create_global)
21109  set(key, sr);
21110  ensure_package(key, sr);
21111  return stack::pop<object>(L);
21112  }
21113 
21114  public:
21117 
21118  state_view(lua_State* Ls)
21119  : L(Ls), reg(Ls, LUA_REGISTRYINDEX), global(Ls, detail::global_) {
21120  }
21121 
21123  : state_view(Ls.L) {
21124  }
21125 
21126  lua_State* lua_state() const {
21127  return L;
21128  }
21129 
21130  template <typename... Args>
21131  void open_libraries(Args&&... args) {
21132  static_assert(meta::all_same<lib, Args...>::value, "all types must be libraries");
21133  if (sizeof...(args) == 0) {
21134  luaL_openlibs(L);
21135  return;
21136  }
21137 
21138  lib libraries[1 + sizeof...(args)] = {lib::count, std::forward<Args>(args)...};
21139 
21140  for (auto&& library : libraries) {
21141  switch (library) {
21142 #if SOL_LUA_VERSION <= 501 && defined(SOL_LUAJIT)
21143  case lib::coroutine:
21144 #endif // luajit opens coroutine base stuff
21145  case lib::base:
21146  luaL_requiref(L, "base", luaopen_base, 1);
21147  lua_pop(L, 1);
21148  break;
21149  case lib::package:
21150  luaL_requiref(L, "package", luaopen_package, 1);
21151  lua_pop(L, 1);
21152  break;
21153 #if !defined(SOL_LUAJIT)
21154  case lib::coroutine:
21155 #if SOL_LUA_VERSION > 501
21156  luaL_requiref(L, "coroutine", luaopen_coroutine, 1);
21157  lua_pop(L, 1);
21158 #endif // Lua 5.2+ only
21159  break;
21160 #endif // Not LuaJIT - comes builtin
21161  case lib::string:
21162  luaL_requiref(L, "string", luaopen_string, 1);
21163  lua_pop(L, 1);
21164  break;
21165  case lib::table:
21166  luaL_requiref(L, "table", luaopen_table, 1);
21167  lua_pop(L, 1);
21168  break;
21169  case lib::math:
21170  luaL_requiref(L, "math", luaopen_math, 1);
21171  lua_pop(L, 1);
21172  break;
21173  case lib::bit32:
21174 #ifdef SOL_LUAJIT
21175  luaL_requiref(L, "bit32", luaopen_bit, 1);
21176  lua_pop(L, 1);
21177 #elif (SOL_LUA_VERSION == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2)
21178  luaL_requiref(L, "bit32", luaopen_bit32, 1);
21179  lua_pop(L, 1);
21180 #else
21181 #endif // Lua 5.2 only (deprecated in 5.3 (503)) (Can be turned on with Compat flags)
21182  break;
21183  case lib::io:
21184  luaL_requiref(L, "io", luaopen_io, 1);
21185  lua_pop(L, 1);
21186  break;
21187  case lib::os:
21188  luaL_requiref(L, "os", luaopen_os, 1);
21189  lua_pop(L, 1);
21190  break;
21191  case lib::debug:
21192  luaL_requiref(L, "debug", luaopen_debug, 1);
21193  lua_pop(L, 1);
21194  break;
21195  case lib::utf8:
21196 #if SOL_LUA_VERSION > 502 && !defined(SOL_LUAJIT)
21197  luaL_requiref(L, "utf8", luaopen_utf8, 1);
21198  lua_pop(L, 1);
21199 #endif // Lua 5.3+ only
21200  break;
21201  case lib::ffi:
21202 #ifdef SOL_LUAJIT
21203  luaL_requiref(L, "ffi", luaopen_ffi, 1);
21204  lua_pop(L, 1);
21205 #endif // LuaJIT only
21206  break;
21207  case lib::jit:
21208 #ifdef SOL_LUAJIT
21209  luaL_requiref(L, "jit", luaopen_jit, 0);
21210  lua_pop(L, 1);
21211 #endif // LuaJIT Only
21212  break;
21213  case lib::count:
21214  default:
21215  break;
21216  }
21217  }
21218  }
21219 
21220  object require(const std::string& key, lua_CFunction open_function, bool create_global = true) {
21221  luaL_requiref(L, key.c_str(), open_function, create_global ? 1 : 0);
21222  return stack::pop<object>(L);
21223  }
21224 
21225  object require_script(const std::string& key, const string_view& code, bool create_global = true, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
21226  auto action = [this, &code, &chunkname, &mode]() {
21227  stack::script(L, code, chunkname, mode);
21228  };
21229  return require_core(key, action, create_global);
21230  }
21231 
21232  object require_file(const std::string& key, const std::string& filename, bool create_global = true, load_mode mode = load_mode::any) {
21233  auto action = [this, &filename, &mode]() {
21234  stack::script_file(L, filename, mode);
21235  };
21236  return require_core(key, action, create_global);
21237  }
21238 
21239  template <typename E>
21241  detail::typical_chunk_name_t basechunkname = {};
21242  const char* chunknametarget = detail::make_chunk_name(code, chunkname, basechunkname);
21243  load_status x = static_cast<load_status>(luaL_loadbufferx(L, code.data(), code.size(), chunknametarget, to_string(mode).c_str()));
21244  if (x != load_status::ok) {
21245  return protected_function_result(L, absolute_index(L, -1), 0, 1, static_cast<call_status>(x));
21246  }
21248  set_environment(env, pf);
21249  return pf();
21250  }
21251 
21252  template <typename E>
21254  load_status x = static_cast<load_status>(luaL_loadfilex(L, filename.c_str(), to_string(mode).c_str()));
21255  if (x != load_status::ok) {
21256  return protected_function_result(L, absolute_index(L, -1), 0, 1, static_cast<call_status>(x));
21257  }
21259  set_environment(env, pf);
21260  return pf();
21261  }
21262 
21264  detail::typical_chunk_name_t basechunkname = {};
21265  const char* chunknametarget = detail::make_chunk_name(code, chunkname, basechunkname);
21266  load_status x = static_cast<load_status>(luaL_loadbufferx(L, code.data(), code.size(), chunknametarget, to_string(mode).c_str()));
21267  if (x != load_status::ok) {
21268  return protected_function_result(L, absolute_index(L, -1), 0, 1, static_cast<call_status>(x));
21269  }
21271  return pf();
21272  }
21273 
21275  load_status x = static_cast<load_status>(luaL_loadfilex(L, filename.c_str(), to_string(mode).c_str()));
21276  if (x != load_status::ok) {
21277  return protected_function_result(L, absolute_index(L, -1), 0, 1, static_cast<call_status>(x));
21278  }
21280  return pf();
21281  }
21282 
21283  template <typename Fx, meta::disable_any<meta::is_string_constructible<meta::unqualified_t<Fx>>, meta::is_specialization_of<meta::unqualified_t<Fx>, basic_environment>> = meta::enabler>
21285  protected_function_result pfr = do_string(code, chunkname, mode);
21286  if (!pfr.valid()) {
21287  return on_error(L, std::move(pfr));
21288  }
21289  return pfr;
21290  }
21291 
21292  template <typename Fx, typename E>
21294  protected_function_result pfr = do_string(code, env, chunkname, mode);
21295  if (!pfr.valid()) {
21296  return on_error(L, std::move(pfr));
21297  }
21298  return pfr;
21299  }
21300 
21301  template <typename E>
21303  return safe_script(code, env, script_default_on_error, chunkname, mode);
21304  }
21305 
21307  return safe_script(code, script_default_on_error, chunkname, mode);
21308  }
21309 
21310  template <typename Fx, meta::disable_any<meta::is_string_constructible<meta::unqualified_t<Fx>>, meta::is_specialization_of<meta::unqualified_t<Fx>, basic_environment>> = meta::enabler>
21312  protected_function_result pfr = do_file(filename, mode);
21313  if (!pfr.valid()) {
21314  return on_error(L, std::move(pfr));
21315  }
21316  return pfr;
21317  }
21318 
21319  template <typename Fx, typename E>
21321  protected_function_result pfr = do_file(filename, env, mode);
21322  if (!pfr.valid()) {
21323  return on_error(L, std::move(pfr));
21324  }
21325  return pfr;
21326  }
21327 
21328  template <typename E>
21330  return safe_script_file(filename, env, script_default_on_error, mode);
21331  }
21332 
21334  return safe_script_file(filename, script_default_on_error, mode);
21335  }
21336 
21337  template <typename E>
21339  detail::typical_chunk_name_t basechunkname = {};
21340  const char* chunknametarget = detail::make_chunk_name(code, chunkname, basechunkname);
21341  int index = lua_gettop(L);
21342  if (luaL_loadbufferx(L, code.data(), code.size(), chunknametarget, to_string(mode).c_str())) {
21343  lua_error(L);
21344  }
21345  set_environment(env, stack_reference(L, raw_index(index + 1)));
21346  if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
21347  lua_error(L);
21348  }
21349  int postindex = lua_gettop(L);
21350  int returns = postindex - index;
21351  return unsafe_function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
21352  }
21353 
21355  int index = lua_gettop(L);
21356  stack::script(L, code, chunkname, mode);
21357  int postindex = lua_gettop(L);
21358  int returns = postindex - index;
21359  return unsafe_function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
21360  }
21361 
21362  template <typename E>
21364  int index = lua_gettop(L);
21365  if (luaL_loadfilex(L, filename.c_str(), to_string(mode).c_str())) {
21366  lua_error(L);
21367  }
21368  set_environment(env, stack_reference(L, raw_index(index + 1)));
21369  if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
21370  lua_error(L);
21371  }
21372  int postindex = lua_gettop(L);
21373  int returns = postindex - index;
21374  return unsafe_function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
21375  }
21376 
21378  int index = lua_gettop(L);
21379  stack::script_file(L, filename, mode);
21380  int postindex = lua_gettop(L);
21381  int returns = postindex - index;
21382  return unsafe_function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
21383  }
21384 
21385  template <typename Fx, meta::disable_any<meta::is_string_constructible<meta::unqualified_t<Fx>>, meta::is_specialization_of<meta::unqualified_t<Fx>, basic_environment>> = meta::enabler>
21387  return safe_script(code, std::forward<Fx>(on_error), chunkname, mode);
21388  }
21389 
21390  template <typename Fx, meta::disable_any<meta::is_string_constructible<meta::unqualified_t<Fx>>, meta::is_specialization_of<meta::unqualified_t<Fx>, basic_environment>> = meta::enabler>
21392  return safe_script_file(filename, std::forward<Fx>(on_error), mode);
21393  }
21394 
21395  template <typename Fx, typename E>
21397  return safe_script(code, env, std::forward<Fx>(on_error), chunkname, mode);
21398  }
21399 
21400  template <typename Fx, typename E>
21402  return safe_script_file(filename, env, std::forward<Fx>(on_error), mode);
21403  }
21404 
21406  return safe_script(code, env, script_default_on_error, chunkname, mode);
21407  }
21408 
21410  return safe_script_file(filename, env, script_default_on_error, mode);
21411  }
21412 
21413 #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION
21415  return safe_script(code, chunkname, mode);
21416  }
21417 
21419  return safe_script_file(filename, mode);
21420  }
21421 #else
21423  return unsafe_script(code, chunkname, mode);
21424  }
21425 
21427  return unsafe_script_file(filename, mode);
21428  }
21429 #endif
21431  detail::typical_chunk_name_t basechunkname = {};
21432  const char* chunknametarget = detail::make_chunk_name(code, chunkname, basechunkname);
21433  load_status x = static_cast<load_status>(luaL_loadbufferx(L, code.data(), code.size(), chunknametarget, to_string(mode).c_str()));
21434  return load_result(L, absolute_index(L, -1), 1, 1, x);
21435  }
21436 
21437  load_result load_buffer(const char* buff, size_t size, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
21438  return load(string_view(buff, size), chunkname, mode);
21439  }
21440 
21442  load_status x = static_cast<load_status>(luaL_loadfilex(L, filename.c_str(), to_string(mode).c_str()));
21443  return load_result(L, absolute_index(L, -1), 1, 1, x);
21444  }
21445 
21446  load_result load(lua_Reader reader, void* data, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
21447  detail::typical_chunk_name_t basechunkname = {};
21448  const char* chunknametarget = detail::make_chunk_name("lua_Reader", chunkname, basechunkname);
21449  load_status x = static_cast<load_status>(lua_load(L, reader, data, chunknametarget, to_string(mode).c_str()));
21450  return load_result(L, absolute_index(L, -1), 1, 1, x);
21451  }
21452 
21453  iterator begin() const {
21454  return global.begin();
21455  }
21456 
21457  iterator end() const {
21458  return global.end();
21459  }
21460 
21461  const_iterator cbegin() const {
21462  return global.cbegin();
21463  }
21464 
21465  const_iterator cend() const {
21466  return global.cend();
21467  }
21468 
21470  return global;
21471  }
21472 
21473  table registry() const {
21474  return reg;
21475  }
21476 
21477  std::size_t memory_used() const {
21478  return total_memory_used(lua_state());
21479  }
21480 
21481  int stack_top() const {
21482  return stack::top(L);
21483  }
21484 
21485  int stack_clear() {
21486  int s = stack_top();
21487  lua_pop(L, s);
21488  return s;
21489  }
21490 
21492  lua_gc(lua_state(), LUA_GCCOLLECT, 0);
21493  }
21494 
21495  operator lua_State*() const {
21496  return lua_state();
21497  }
21498 
21499  void set_panic(lua_CFunction panic) {
21500  lua_atpanic(lua_state(), panic);
21501  }
21502 
21504  set_default_exception_handler(lua_state(), handler);
21505  }
21506 
21507  template <typename... Args, typename... Keys>
21508  decltype(auto) get(Keys&&... keys) const {
21509  return global.get<Args...>(std::forward<Keys>(keys)...);
21510  }
21511 
21512  template <typename T, typename Key>
21513  decltype(auto) get_or(Key&& key, T&& otherwise) const {
21514  return global.get_or(std::forward<Key>(key), std::forward<T>(otherwise));
21515  }
21516 
21517  template <typename T, typename Key, typename D>
21518  decltype(auto) get_or(Key&& key, D&& otherwise) const {
21519  return global.get_or<T>(std::forward<Key>(key), std::forward<D>(otherwise));
21520  }
21521 
21522  template <typename... Args>
21523  state_view& set(Args&&... args) {
21524  global.set(std::forward<Args>(args)...);
21525  return *this;
21526  }
21527 
21528  template <typename T, typename... Keys>
21529  decltype(auto) traverse_get(Keys&&... keys) const {
21530  return global.traverse_get<T>(std::forward<Keys>(keys)...);
21531  }
21532 
21533  template <typename... Args>
21534  state_view& traverse_set(Args&&... args) {
21535  global.traverse_set(std::forward<Args>(args)...);
21536  return *this;
21537  }
21538 
21539  template <typename T>
21541  return set_usertype(usertype_traits<T>::name(), user);
21542  }
21543 
21544  template <typename Key, typename T>
21546  global.set_usertype(std::forward<Key>(key), user);
21547  return *this;
21548  }
21549 
21550  template <typename Class, typename... Args>
21551  state_view& new_usertype(const std::string& name, Args&&... args) {
21552  global.new_usertype<Class>(name, std::forward<Args>(args)...);
21553  return *this;
21554  }
21555 
21556  template <typename Class, typename CTor0, typename... CTor, typename... Args>
21557  state_view& new_usertype(const std::string& name, Args&&... args) {
21558  global.new_usertype<Class, CTor0, CTor...>(name, std::forward<Args>(args)...);
21559  return *this;
21560  }
21561 
21562  template <typename Class, typename... CArgs, typename... Args>
21563  state_view& new_usertype(const std::string& name, constructors<CArgs...> ctor, Args&&... args) {
21564  global.new_usertype<Class>(name, ctor, std::forward<Args>(args)...);
21565  return *this;
21566  }
21567 
21568  template <typename Class, typename... Args>
21569  state_view& new_simple_usertype(const std::string& name, Args&&... args) {
21570  global.new_simple_usertype<Class>(name, std::forward<Args>(args)...);
21571  return *this;
21572  }
21573 
21574  template <typename Class, typename CTor0, typename... CTor, typename... Args>
21575  state_view& new_simple_usertype(const std::string& name, Args&&... args) {
21576  global.new_simple_usertype<Class, CTor0, CTor...>(name, std::forward<Args>(args)...);
21577  return *this;
21578  }
21579 
21580  template <typename Class, typename... CArgs, typename... Args>
21582  global.new_simple_usertype<Class>(name, ctor, std::forward<Args>(args)...);
21583  return *this;
21584  }
21585 
21586  template <typename Class, typename... Args>
21588  return global.create_simple_usertype<Class>(std::forward<Args>(args)...);
21589  }
21590 
21591  template <typename Class, typename CTor0, typename... CTor, typename... Args>
21593  return global.create_simple_usertype<Class, CTor0, CTor...>(std::forward<Args>(args)...);
21594  }
21595 
21596  template <typename Class, typename... CArgs, typename... Args>
21598  return global.create_simple_usertype<Class>(ctor, std::forward<Args>(args)...);
21599  }
21600 
21601  template <bool read_only = true, typename... Args>
21602  state_view& new_enum(const string_view& name, Args&&... args) {
21603  global.new_enum<read_only>(name, std::forward<Args>(args)...);
21604  return *this;
21605  }
21606 
21607  template <typename T, bool read_only = true>
21608  state_view& new_enum(const string_view& name, std::initializer_list<std::pair<string_view, T>> items) {
21609  global.new_enum<T, read_only>(name, std::move(items));
21610  return *this;
21611  }
21612 
21613  template <typename Fx>
21614  void for_each(Fx&& fx) {
21615  global.for_each(std::forward<Fx>(fx));
21616  }
21617 
21618  template <typename T>
21620  return global[std::forward<T>(key)];
21621  }
21622 
21623  template <typename T>
21625  return global[std::forward<T>(key)];
21626  }
21627 
21628  template <typename Sig, typename... Args, typename Key>
21629  state_view& set_function(Key&& key, Args&&... args) {
21630  global.set_function<Sig>(std::forward<Key>(key), std::forward<Args>(args)...);
21631  return *this;
21632  }
21633 
21634  template <typename... Args, typename Key>
21635  state_view& set_function(Key&& key, Args&&... args) {
21636  global.set_function(std::forward<Key>(key), std::forward<Args>(args)...);
21637  return *this;
21638  }
21639 
21640  template <typename Name>
21641  table create_table(Name&& name, int narr = 0, int nrec = 0) {
21642  return global.create(std::forward<Name>(name), narr, nrec);
21643  }
21644 
21645  template <typename Name, typename Key, typename Value, typename... Args>
21646  table create_table(Name&& name, int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
21647  return global.create(std::forward<Name>(name), narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
21648  }
21649 
21650  template <typename Name, typename... Args>
21651  table create_named_table(Name&& name, Args&&... args) {
21652  table x = global.create_with(std::forward<Args>(args)...);
21653  global.set(std::forward<Name>(name), x);
21654  return x;
21655  }
21656 
21657  table create_table(int narr = 0, int nrec = 0) {
21658  return create_table(lua_state(), narr, nrec);
21659  }
21660 
21661  template <typename Key, typename Value, typename... Args>
21662  table create_table(int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
21663  return create_table(lua_state(), narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
21664  }
21665 
21666  template <typename... Args>
21667  table create_table_with(Args&&... args) {
21668  return create_table_with(lua_state(), std::forward<Args>(args)...);
21669  }
21670 
21671  static inline table create_table(lua_State* L, int narr = 0, int nrec = 0) {
21672  return global_table::create(L, narr, nrec);
21673  }
21674 
21675  template <typename Key, typename Value, typename... Args>
21676  static inline table create_table(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
21677  return global_table::create(L, narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
21678  }
21679 
21680  template <typename... Args>
21681  static inline table create_table_with(lua_State* L, Args&&... args) {
21682  return global_table::create_with(L, std::forward<Args>(args)...);
21683  }
21684  };
21685 } // namespace sol
21686 
21687 // end of sol/state_view.hpp
21688 
21689 // beginning of sol/thread.hpp
21690 
21691 namespace sol {
21693  lua_State* L;
21694 
21695  lua_thread_state(lua_State* Ls)
21696  : L(Ls) {
21697  }
21698 
21699  lua_State* lua_state() const noexcept {
21700  return L;
21701  }
21702  operator lua_State*() const noexcept {
21703  return lua_state();
21704  }
21705  lua_State* operator->() const noexcept {
21706  return lua_state();
21707  }
21708  };
21709 
21710  namespace stack {
21711  template <>
21713  int push(lua_State*, lua_thread_state lts) {
21714  lua_pushthread(lts.L);
21715  return 1;
21716  }
21717  };
21718 
21719  template <>
21721  lua_thread_state get(lua_State* L, int index, record& tracking) {
21722  tracking.use(1);
21723  lua_thread_state lts( lua_tothread(L, index) );
21724  return lts;
21725  }
21726  };
21727 
21728  template <>
21730  template <typename Handler>
21731  optional<lua_thread_state> get(lua_State* L, int index, Handler&& handler, record& tracking) {
21732  lua_thread_state lts( lua_tothread(L, index) );
21733  if (lts.lua_state() == nullptr) {
21734  handler(L, index, type::thread, type_of(L, index), "value is not a valid thread type");
21735  return nullopt;
21736  }
21737  tracking.use(1);
21738  return lts;
21739  }
21740  };
21741  } // namespace stack
21742 
21743  template <typename base_t>
21744  class basic_thread : public base_t {
21745  public:
21746  using base_t::lua_state;
21747 
21748  basic_thread() noexcept = default;
21749  basic_thread(const basic_thread&) = default;
21750  basic_thread(basic_thread&&) = default;
21751  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_thread>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
21753  : base_t(std::forward<T>(r)) {
21754 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
21755  auto pp = stack::push_pop(*this);
21757  stack::check<basic_thread>(lua_state(), -1, handler);
21758 #endif // Safety
21759  }
21761  : basic_thread(r.lua_state(), r.stack_index()){};
21763  : basic_thread(r.lua_state(), r.stack_index()){};
21764  basic_thread& operator=(const basic_thread&) = default;
21765  basic_thread& operator=(basic_thread&&) = default;
21766  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
21767  basic_thread(lua_State* L, T&& r)
21768  : base_t(L, std::forward<T>(r)) {
21769 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
21770  auto pp = stack::push_pop(*this);
21772  stack::check<basic_thread>(lua_state(), -1, handler);
21773 #endif // Safety
21774  }
21775  basic_thread(lua_State* L, int index = -1)
21776  : base_t(L, index) {
21777 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
21779  stack::check<basic_thread>(L, index, handler);
21780 #endif // Safety
21781  }
21782  basic_thread(lua_State* L, ref_index index)
21783  : base_t(L, index) {
21784 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
21785  auto pp = stack::push_pop(*this);
21787  stack::check<basic_thread>(lua_state(), -1, handler);
21788 #endif // Safety
21789  }
21790  basic_thread(lua_State* L, lua_State* actualthread)
21791  : basic_thread(L, lua_thread_state{ actualthread }) {
21792  }
21793  basic_thread(lua_State* L, this_state actualthread)
21794  : basic_thread(L, lua_thread_state{ actualthread.L }) {
21795  }
21796  basic_thread(lua_State* L, lua_thread_state actualthread)
21797  : base_t(L, -stack::push(L, actualthread)) {
21798 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
21800  stack::check<basic_thread>(lua_state(), -1, handler);
21801 #endif // Safety
21803  lua_pop(lua_state(), 1);
21804  }
21805  }
21806 
21807  state_view state() const {
21808  return state_view(this->thread_state());
21809  }
21810 
21811  bool is_main_thread() const {
21812  return stack::is_main_thread(this->thread_state());
21813  }
21814 
21815  lua_State* thread_state() const {
21816  auto pp = stack::push_pop(*this);
21817  lua_State* lthread = lua_tothread(lua_state(), -1);
21818  return lthread;
21819  }
21820 
21822  lua_State* lthread = thread_state();
21823  auto lstat = static_cast<thread_status>(lua_status(lthread));
21824  if (lstat == thread_status::ok) {
21825  lua_Debug ar;
21826  if (lua_getstack(lthread, 0, &ar) > 0)
21827  return thread_status::ok;
21828  else if (lua_gettop(lthread) == 0)
21829  return thread_status::dead;
21830  else
21831  return thread_status::yielded;
21832  }
21833  return lstat;
21834  }
21835 
21837  return create(lua_state());
21838  }
21839 
21840  static basic_thread create(lua_State* L) {
21841  lua_newthread(L);
21842  basic_thread result(L);
21844  lua_pop(L, 1);
21845  }
21846  return result;
21847  }
21848  };
21849 
21852 } // namespace sol
21853 
21854 // end of sol/thread.hpp
21855 
21856 namespace sol {
21857 
21858  class state : private std::unique_ptr<lua_State, detail::state_deleter>, public state_view {
21859  private:
21860  typedef std::unique_ptr<lua_State, detail::state_deleter> unique_base;
21861 
21862  public:
21863  state(lua_CFunction panic = default_at_panic)
21864  : unique_base(luaL_newstate()), state_view(unique_base::get()) {
21866  }
21867 
21868  state(lua_CFunction panic, lua_Alloc alfunc, void* alpointer = nullptr)
21869  : unique_base(lua_newstate(alfunc, alpointer)), state_view(unique_base::get()) {
21871  }
21872 
21873  state(const state&) = delete;
21874  state(state&&) = default;
21875  state& operator=(const state&) = delete;
21876  state& operator=(state&& that) {
21877  state_view::operator=(std::move(that));
21878  unique_base::operator=(std::move(that));
21879  return *this;
21880  }
21881 
21882  using state_view::get;
21883 
21885  }
21886  };
21887 } // namespace sol
21888 
21889 // end of sol/state.hpp
21890 
21891 // beginning of sol/coroutine.hpp
21892 
21893 namespace sol {
21894  template <typename base_t>
21895  class basic_coroutine : public base_t {
21896  public:
21898  handler_t error_handler;
21899 
21900  private:
21902 
21903  void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) {
21904 #if SOL_LUA_VERSION >= 504
21905  int nres;
21906  stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount), &nres));
21907 #else
21908  stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount)));
21909 #endif
21910  }
21911 
21912  template <std::size_t... I, typename... Ret>
21913  auto invoke(types<Ret...>, std::index_sequence<I...>, std::ptrdiff_t n) {
21914  luacall(n, sizeof...(Ret));
21915  return stack::pop<std::tuple<Ret...>>(lua_state());
21916  }
21917 
21918  template <std::size_t I, typename Ret>
21919  Ret invoke(types<Ret>, std::index_sequence<I>, std::ptrdiff_t n) {
21920  luacall(n, 1);
21921  return stack::pop<Ret>(lua_state());
21922  }
21923 
21924  template <std::size_t I>
21925  void invoke(types<void>, std::index_sequence<I>, std::ptrdiff_t n) {
21926  luacall(n, 0);
21927  }
21928 
21929  protected_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n) {
21930  int firstreturn = 1;
21931  luacall(n, LUA_MULTRET);
21932  int poststacksize = lua_gettop(this->lua_state());
21933  int returncount = poststacksize - (firstreturn - 1);
21934  if (error()) {
21935  if (error_handler.valid()) {
21936  string_view err = stack::get<string_view>(this->lua_state(), poststacksize);
21937  error_handler.push();
21938  stack::push(this->lua_state(), err);
21939  lua_call(lua_state(), 1, 1);
21940  }
21941  return protected_function_result(this->lua_state(), lua_absindex(this->lua_state(), -1), 1, returncount, status());
21942  }
21943  return protected_function_result(this->lua_state(), firstreturn, returncount, returncount, status());
21944  }
21945 
21946  public:
21947  using base_t::lua_state;
21948 
21949  basic_coroutine() = default;
21950  template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_coroutine>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
21951  basic_coroutine(T&& r) noexcept
21952  : base_t(std::forward<T>(r)), error_handler(detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
21953 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
21954  if (!is_function<meta::unqualified_t<T>>::value) {
21955  auto pp = stack::push_pop(*this);
21957  stack::check<basic_coroutine>(lua_state(), -1, handler);
21958  }
21959 #endif // Safety
21960  }
21961  basic_coroutine(const basic_coroutine&) = default;
21962  basic_coroutine& operator=(const basic_coroutine&) = default;
21963  basic_coroutine(basic_coroutine&&) = default;
21964  basic_coroutine& operator=(basic_coroutine&&) = default;
21966  : basic_coroutine(b, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
21967  }
21969  : basic_coroutine(std::move(b), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
21970  }
21971  basic_coroutine(const basic_function<base_t>& b, handler_t eh)
21972  : base_t(b), error_handler(std::move(eh)) {
21973  }
21975  : base_t(std::move(b)), error_handler(std::move(eh)) {
21976  }
21978  : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
21979  }
21981  : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
21982  }
21983  basic_coroutine(const stack_reference& r, handler_t eh)
21984  : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
21985  }
21987  : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
21988  }
21989 
21990  template <typename Super>
21992  : basic_coroutine(p, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
21993  }
21994  template <typename Super>
21996  : basic_coroutine(std::move(p), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
21997  }
21998  template <typename Proxy, typename Handler, meta::enable<std::is_base_of<proxy_base_tag, meta::unqualified_t<Proxy>>, meta::neg<is_lua_index<meta::unqualified_t<Handler>>>> = meta::enabler>
21999  basic_coroutine(Proxy&& p, Handler&& eh)
22000  : basic_coroutine(detail::force_cast<base_t>(p), std::forward<Handler>(eh)) {
22001  }
22002 
22003  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
22004  basic_coroutine(lua_State* L, T&& r)
22005  : basic_coroutine(L, std::forward<T>(r), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
22006  }
22007  template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
22008  basic_coroutine(lua_State* L, T&& r, handler_t eh)
22009  : base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
22010 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
22011  auto pp = stack::push_pop(*this);
22013  stack::check<basic_coroutine>(lua_state(), -1, handler);
22014 #endif // Safety
22015  }
22016 
22018  : base_t(n), error_handler(n) {
22019  }
22020 
22021  basic_coroutine(lua_State* L, int index = -1)
22022  : basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
22023  }
22024  basic_coroutine(lua_State* L, int index, handler_t eh)
22025  : base_t(L, index), error_handler(std::move(eh)) {
22026 #ifdef SOL_SAFE_REFERENCES
22028  stack::check<basic_coroutine>(L, index, handler);
22029 #endif // Safety
22030  }
22031  basic_coroutine(lua_State* L, absolute_index index)
22032  : basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
22033  }
22034  basic_coroutine(lua_State* L, absolute_index index, handler_t eh)
22035  : base_t(L, index), error_handler(std::move(eh)) {
22036 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
22038  stack::check<basic_coroutine>(L, index, handler);
22039 #endif // Safety
22040  }
22041  basic_coroutine(lua_State* L, raw_index index)
22042  : basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
22043  }
22044  basic_coroutine(lua_State* L, raw_index index, handler_t eh)
22045  : base_t(L, index), error_handler(std::move(eh)) {
22046 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
22048  stack::check<basic_coroutine>(L, index, handler);
22049 #endif // Safety
22050  }
22051  basic_coroutine(lua_State* L, ref_index index)
22052  : basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
22053  }
22054  basic_coroutine(lua_State* L, ref_index index, handler_t eh)
22055  : base_t(L, index), error_handler(std::move(eh)) {
22056 #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
22057  auto pp = stack::push_pop(*this);
22059  stack::check<basic_coroutine>(lua_state(), -1, handler);
22060 #endif // Safety
22061  }
22062 
22063  call_status status() const noexcept {
22064  return stats;
22065  }
22066 
22067  bool error() const noexcept {
22068  call_status cs = status();
22069  return cs != call_status::ok && cs != call_status::yielded;
22070  }
22071 
22072  bool runnable() const noexcept {
22073  return base_t::valid()
22074  && (status() == call_status::yielded);
22075  }
22076 
22077  explicit operator bool() const noexcept {
22078  return runnable();
22079  }
22080 
22081  template <typename... Args>
22083  return call<>(std::forward<Args>(args)...);
22084  }
22085 
22086  template <typename... Ret, typename... Args>
22087  decltype(auto) operator()(types<Ret...>, Args&&... args) {
22088  return call<Ret...>(std::forward<Args>(args)...);
22089  }
22090 
22091  template <typename... Ret, typename... Args>
22092  decltype(auto) call(Args&&... args) {
22093  // some users screw up coroutine.create
22094  // and try to use it with sol::coroutine without ever calling the first resume in Lua
22095  // this makes the stack incompatible with other kinds of stacks: protect against this
22096  // make sure coroutines don't screw us over
22097  base_t::push();
22098  int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
22099  return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount);
22100  }
22101  };
22102 } // namespace sol
22103 
22104 // end of sol/coroutine.hpp
22105 
22106 // beginning of sol/variadic_results.hpp
22107 
22108 // beginning of sol/as_returns.hpp
22109 
22110 namespace sol {
22111  template <typename T>
22112  struct as_returns_t {
22113  T src;
22114  };
22115 
22116  template <typename Source>
22117  auto as_returns(Source&& source) {
22118  return as_returns_t<std::decay_t<Source>>{ std::forward<Source>(source) };
22119  }
22120 
22121  namespace stack {
22122  template <typename T>
22123  struct pusher<as_returns_t<T>> {
22124  int push(lua_State* L, const as_returns_t<T>& e) {
22125  auto& src = detail::unwrap(e.src);
22126  int p = 0;
22127  for (const auto& i : src) {
22128  p += stack::push(L, i);
22129  }
22130  return p;
22131  }
22132  };
22133  } // namespace stack
22134 } // namespace sol
22135 
22136 // end of sol/as_returns.hpp
22137 
22138 namespace sol {
22139 
22140  struct variadic_results : public std::vector<object> {
22141  using std::vector<object>::vector;
22142  };
22143 
22144  namespace stack {
22145  template <>
22147  int push(lua_State* L, const variadic_results& e) {
22148  int p = 0;
22149  for (const auto& i : e) {
22150  p += stack::push(L, i);
22151  }
22152  return p;
22153  }
22154  };
22155  } // namespace stack
22156 
22157 } // namespace sol
22158 
22159 // end of sol/variadic_results.hpp
22160 
22161 #if defined(__GNUC__)
22162 #pragma GCC diagnostic pop
22163 #elif defined _MSC_VER
22164 #pragma warning( push )
22165 #endif // g++
22166 
22167 #if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL
22168 #if defined(SOL_INSIDE_UNREAL_REMOVED_CHECK) && SOL_INSIDE_UNREAL_REMOVED_CHECK
22169 #if defined(DO_CHECK) && DO_CHECK
22170 #define check(expr) { if(UNLIKELY(!(expr))) { FDebug::LogAssertFailedMessage( #expr, __FILE__, __LINE__ ); _DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, __FILE__, __LINE__ ); CA_ASSUME(false); } }
22171 #else
22172 #define check(expr) { CA_ASSUME(expr); }
22173 #endif
22174 #endif
22175 #endif // Unreal Engine 4 Bullshit
22176 
22177 #endif // SOL_HPP
22178 // end of sol.hpp
22179 
22180 #endif // SOL_SINGLE_INCLUDE_HPP
Definition: sol.hpp:21692
usertype< T > base_t
Definition: sol.hpp:19863
std::size_t code_units_size
Definition: sol.hpp:8933
Definition: sol.hpp:4470
void set_default_state(lua_State *L, lua_CFunction panic_function=&default_at_panic, lua_CFunction traceback_function=c_call< decltype(&default_traceback_error_handler), &default_traceback_error_handler >, exception_handler_function exf=detail::default_exception_handler)
Definition: sol.hpp:20965
int push() const
Definition: sol.hpp:12136
static bool type_check(const std::string &ti)
Definition: sol.hpp:6245
Definition: sol.hpp:280
constexpr constexpr_optional_base(const T &v)
Definition: sol.hpp:3575
basic_userdata(lua_State *L, int index=-1)
Definition: sol.hpp:15861
Definition: sol.hpp:12406
stack_iterator & operator-=(difference_type idx)
Definition: sol.hpp:12041
Definition: sol.hpp:4659
static int defer_call(std::false_type, lua_State *L, F &&f, Args &&... args)
Definition: sol.hpp:13669
std::integral_constant< bool, meta::count_for< is_variadic_arguments, typename base_t::args_list >::value !=0 > runtime_variadics_t
Definition: sol.hpp:5734
closure c_closure
Definition: sol.hpp:4955
static int real_empty_call(lua_State *L)
Definition: sol.hpp:17890
usertype(Args &&... args)
Definition: sol.hpp:19830
bool operator!=(const basic_string_view &r) const
Definition: sol.hpp:1134
virtual int push_um(lua_State *L) override
Definition: sol.hpp:19006
Definition: sol.hpp:544
reverse_iterator rend()
Definition: sol.hpp:16038
auto deref(T &&item) -> decltype(std::forward< T >(item))
Definition: sol.hpp:1842
stack_proxy_base()
Definition: sol.hpp:12110
protected_function_result safe_script(const string_view &code, const basic_environment< E > &env, Fx &&on_error, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21293
object require(const std::string &key, lua_CFunction open_function, bool create_global=true)
Definition: sol.hpp:21220
lua_CFunction c_function
Definition: sol.hpp:4948
error(detail::direct_error_tag, const std::string &str)
Definition: sol.hpp:426
bool operator==(const Char *r) const
Definition: sol.hpp:1126
proxy< const basic_table_core &, T > operator[](T &&key) const &
Definition: sol.hpp:20446
static int push(lua_State *L, const T &ref)
Definition: sol.hpp:10658
static int push(lua_State *L, umt_t &&umx)
Definition: sol.hpp:19049
meta::boolean< has_find_test< T >::value > has_find
Definition: sol.hpp:16580
constructor_wrapper(Arg &&arg, Args &&... args)
Definition: sol.hpp:4509
void for_each(Fx &&fx) const
Definition: sol.hpp:20425
handler_t error_handler
Definition: sol.hpp:21898
simple_usertype_metatable< T > umt_t
Definition: sol.hpp:19549
bool valid() const noexcept
Definition: sol.hpp:6534
state & operator=(state &&that)
Definition: sol.hpp:21876
const Char * cbegin() const
Definition: sol.hpp:1098
lua_State * lua_state() const noexcept
Definition: sol.hpp:21699
static bool type_unique_cast_bases(void *, void *, const string_view &)
Definition: sol.hpp:6265
Definition: sol.hpp:10855
factory_wrapper(Arg &&arg, Args &&... args)
Definition: sol.hpp:4523
Definition: sol.hpp:12212
stack_iterator(lua_State *luastate, int idx, int topidx)
Definition: sol.hpp:11992
const_reverse_iterator rbegin() const
Definition: sol.hpp:16041
Definition: sol.hpp:5378
reference operator*()
Definition: sol.hpp:11996
static int push(lua_State *L, const new_table &nt)
Definition: sol.hpp:11316
Definition: sol.hpp:4699
implicit_wrapper(T &item)
Definition: sol.hpp:4664
nested< T > as_nested_ref(T &&container)
Definition: sol.hpp:5038
bool check_usertype(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:7868
static void select_convertible(std::false_type, types< Sig... >, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14442
void traverse_set_deep(Key &&key, Keys &&... keys) const
Definition: sol.hpp:20123
~optional_base()
Definition: sol.hpp:3555
iterator begin()
Definition: sol.hpp:12465
type get_type(difference_type index_offset=0) const noexcept
Definition: sol.hpp:16075
int default_at_panic(lua_State *L)
Definition: sol.hpp:20922
Definition: sol.hpp:12926
meta::tuple_types< typename fx_t::return_type > return_types
Definition: sol.hpp:15458
Definition: sol.hpp:13025
lua_State * lua_state() const noexcept
Definition: sol.hpp:6530
const auto call_constructor
Definition: sol.hpp:4503
int popcount
Definition: sol.hpp:12217
lua_State * L
Definition: sol.hpp:6603
Definition: sol.hpp:4709
usertype_metatable(Args &&... args)
Definition: sol.hpp:18859
static int call_assign(std::false_type, lua_State *L, Args &&...)
Definition: sol.hpp:13288
std::conditional_t< is_associative::value||is_matched_lookup::value, std::add_lvalue_reference_t< V >, std::conditional_t< is_lookup::value, V, iterator_return > > captured_type
Definition: sol.hpp:16804
std::tuple< Tn... > RawTuple
Definition: sol.hpp:18736
basic_reference(basic_reference &&o) noexcept
Definition: sol.hpp:6886
meta::unqualified_t< T > Tu
Definition: sol.hpp:9259
std::array< char, 2 > two
Definition: sol.hpp:16292
static int push(lua_State *L, const wchar_t(&str)[N], std::size_t sz)
Definition: sol.hpp:11188
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8645
void swap(optional< T > &rhs) noexcept(::std::is_nothrow_move_constructible< T >::value &&noexcept(swap(::std::declval< T &>(), ::std::declval< T &>())))
Definition: sol.hpp:3792
const_iterator end() const
Definition: sol.hpp:12474
virtual int push_um(lua_State *L) override
Definition: sol.hpp:19541
T source
Definition: sol.hpp:4983
void move_assign(basic_reference< r_main_only > &&r)
Definition: sol.hpp:6753
Definition: sol.hpp:346
static decltype(auto) pop(lua_State *L)
Definition: sol.hpp:11375
basic_coroutine(proxy_base< Super > &&p)
Definition: sol.hpp:21995
stack_proxy * pointer
Definition: sol.hpp:12415
static int push(lua_State *L, const char32_t *str)
Definition: sol.hpp:11163
optional(optional &&rhs) noexcept(::std::is_nothrow_move_constructible< T >::value)
Definition: sol.hpp:3710
basic_object(std::integral_constant< bool, invert_and_pop >, lua_State *L, int index=-1) noexcept
Definition: sol.hpp:16148
Definition: sol.hpp:1065
void swap(optional< T &> &rhs) noexcept
Definition: sol.hpp:4013
static int real_erase_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17894
const auto direct_error
Definition: sol.hpp:411
Definition: sol.hpp:5673
as_container_t(T value)
Definition: sol.hpp:16255
void_tuple_element_t< i, args_tuple > arg_at
Definition: sol.hpp:1023
Definition: sol.hpp:7629
std::hash< string_view > string_view_hash
Definition: sol.hpp:1190
std::array< C, 4 > code_units
Definition: sol.hpp:8934
static const std::string & gc_table()
Definition: sol.hpp:6185
void operator()()
Definition: sol.hpp:17989
static decltype(auto) eval(types<>, std::index_sequence<>, lua_State *, int, record &, Fx &&fx, Args &&... args)
Definition: sol.hpp:11772
Definition: sol.hpp:389
Definition: sol.hpp:13115
as_container_t(T &value)
Definition: sol.hpp:16272
Definition: sol.hpp:5649
Definition: sol.hpp:8931
const_iterator cend() const
Definition: sol.hpp:12339
const_iterator cbegin() const
Definition: sol.hpp:16028
static int push(lua_State *, const this_state &)
Definition: sol.hpp:11302
static int push(lua_State *L, const char16_t *str, std::size_t len)
Definition: sol.hpp:11097
void make_regs(regs_t &, int &, call_construction, F &&)
Definition: sol.hpp:18785
Definition: sol.hpp:1029
closure< Args... > make_closure(lua_CFunction f, Args &&... args)
Definition: sol.hpp:4958
static auto call(object_type &mem) -> detail::array_return_type< decltype(mem.*fx)>
Definition: sol.hpp:12671
int call(lua_State *L)
Definition: sol.hpp:12872
static int real_get_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17766
stack_reference(lua_State *L, absolute_index i) noexcept
Definition: sol.hpp:6465
static int real_pairs_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17798
simple_usertype< Class > create_simple_usertype(constructors< CArgs... > ctor, Args &&... args)
Definition: sol.hpp:21597
tie_t< std::remove_reference_t< Tn >... > tie(Tn &&... argn)
Definition: sol.hpp:7090
int & operator[](std::size_t i)
Definition: sol.hpp:4581
Definition: sol.hpp:3216
std::array< char, 1 > one
Definition: sol.hpp:16546
static bool type_unique_cast(void *source_data, void *target_data, const string_view &ti, const string_view &rebind_ti)
Definition: sol.hpp:6287
auto deref_non_pointer(T &&item) -> decltype(std::forward< T >(item))
Definition: sol.hpp:1852
static void select(lua_State *L, Fx &&fx)
Definition: sol.hpp:14611
state(lua_CFunction panic, lua_Alloc alfunc, void *alpointer=nullptr)
Definition: sol.hpp:21868
static int push(lua_State *L, const wchar_t *str)
Definition: sol.hpp:11005
error tagged_get(types< error >) const
Definition: sol.hpp:20815
int push() const noexcept
Definition: sol.hpp:6492
static void set_fx(lua_State *L, Args &&... args)
Definition: sol.hpp:14617
traits_type::args_list args_list
Definition: sol.hpp:12710
auto make_string_view(string_view s)
Definition: sol.hpp:18497
static int push(lua_State *L, function_arguments< T, Args... > &&fp)
Definition: sol.hpp:14669
static int push(lua_State *L, const char32_t(&str)[N])
Definition: sol.hpp:11206
as_table_t(Arg &&arg)
Definition: sol.hpp:4991
int stackindex
Definition: sol.hpp:15063
meta::unqualified_t< T > U
Definition: sol.hpp:10388
std::remove_pointer_t< free_function_pointer_type > signature_type
Definition: sol.hpp:577
static int set_call(lua_State *L)
Definition: sol.hpp:17966
proxy< basic_table_core &, T > operator[](T &&key) &
Definition: sol.hpp:20441
lightuserdata_value(void *data)
Definition: sol.hpp:4853
member_function(function_type f, Args &&... args)
Definition: sol.hpp:14179
static int push(lua_State *, const stack_proxy &ref)
Definition: sol.hpp:12202
Definition: sol.hpp:11975
Definition: sol.hpp:14435
static bool max_size_check(std::false_type, T &, std::size_t)
Definition: sol.hpp:9282
Definition: sol.hpp:1734
static S get_into(lua_State *L, int index, record &tracking)
Definition: sol.hpp:9686
const_iterator cbegin() const
Definition: sol.hpp:20221
optional< object > is_loaded_package(const std::string &key)
Definition: sol.hpp:21061
closure(lua_CFunction f, Upvalues... targetupvalues)
Definition: sol.hpp:4941
Definition: sol.hpp:7032
static int real_index_get_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17710
std::conditional_t< is_const, const proxy_t, proxy_t > reference
Definition: sol.hpp:11976
static int call(lua_State *L)
Definition: sol.hpp:14049
static bool check(lua_State *, int, Handler &&, record &tracking)
Definition: sol.hpp:8357
table registry() const
Definition: sol.hpp:21473
int ref
Definition: sol.hpp:6719
const void * pointer() const noexcept
Definition: sol.hpp:6520
std::size_t size_type
Definition: sol.hpp:12266
constexpr constexpr_optional_base(T &&v)
Definition: sol.hpp:3580
struct sol::simple_tag simple
basic_coroutine(lua_State *L, int index, handler_t eh)
Definition: sol.hpp:22024
Definition: sol.hpp:381
int type_panic_string(lua_State *L, int index, type expected, type actual, const std::string &message="") noexcept(false)
Definition: sol.hpp:6334
void luajit_exception_off(lua_State *L)
Definition: sol.hpp:11917
int runtime_object_call(lua_State *L, void *, usertype_metatable_core &umc, int runtimetarget)
Definition: sol.hpp:18542
static int push(lua_State *L, const overload_set< Functions... > &set)
Definition: sol.hpp:14717
stack_iterator< proxy_t, is_const > operator+(typename stack_iterator< proxy_t, is_const >::difference_type n, const stack_iterator< proxy_t, is_const > &r)
Definition: sol.hpp:12092
this_main_state(lua_State *Ls)
Definition: sol.hpp:5070
meta::boolean< has_traits_insert_test< T >::value > has_traits_insert
Definition: sol.hpp:16628
load_status status() const noexcept
Definition: sol.hpp:20859
basic_reference(lua_State *L, lua_nil_t) noexcept
Definition: sol.hpp:6872
static int push(lua_State *, stack_count st)
Definition: sol.hpp:10685
static int new_index_call(lua_State *L)
Definition: sol.hpp:17974
basic_function(lua_State *L, ref_index index)
Definition: sol.hpp:15016
static void select_member_function(std::false_type, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14544
protected_handler(const target_t &target)
Definition: sol.hpp:15080
T src
Definition: sol.hpp:22113
basic_environment(env_t, const stack_reference &extraction_target)
Definition: sol.hpp:20612
static int push(lua_State *L, const char32_t *str, std::size_t len)
Definition: sol.hpp:11175
static T & get(lua_State *L, int index, record &tracking)
Definition: sol.hpp:9220
const bool default_safe_function_calls
Definition: sol.hpp:4399
push_popper_n(lua_State *, int)
Definition: sol.hpp:6631
bool valid() const noexcept
Definition: sol.hpp:6965
Definition: sol.hpp:5421
constexpr T value_or(V &&v) const
Definition: sol.hpp:3935
const int metatable_index
Definition: sol.hpp:18380
usertype_detail::variable_map varmap
Definition: sol.hpp:19343
static int push(lua_State *L, constructor_list< Lists... >)
Definition: sol.hpp:14830
meta::boolean< meta_detail::has_size_test< T >::value||meta_detail::has_size_test< const T >::value > has_size
Definition: sol.hpp:1725
int call(lua_State *L)
Definition: sol.hpp:14149
Definition: sol.hpp:14433
overloaded_function(Functions... fxs)
Definition: sol.hpp:14261
int count
Definition: sol.hpp:6605
std::tuple_element_t< N, std::remove_reference_t< Tuple >> tuple_element_t
Definition: sol.hpp:512
bool operator()(A &&, B &&) const
Definition: sol.hpp:18127
stack_iterator< stack_proxy, true > const_iterator
Definition: sol.hpp:12419
reverse_iterator rbegin()
Definition: sol.hpp:12343
void_tuple_element_t< i, args_tuple > arg_at
Definition: sol.hpp:579
static int index_call(lua_State *L)
Definition: sol.hpp:18990
basic_protected_function(basic_function< base_t > &&b, handler_t eh)
Definition: sol.hpp:15261
Definition: sol.hpp:5367
static int meta_index_call(lua_State *L)
Definition: sol.hpp:18998
Definition: sol.hpp:3494
basic_table_iterator(reference_type x)
Definition: sol.hpp:19919
static constexpr char32_t decode(unsigned char b0, unsigned char b1, unsigned char b2)
Definition: sol.hpp:8982
int member_default_to_string(std::false_type, lua_State *L)
Definition: sol.hpp:18144
static int push(lua_State *L, destructor_wrapper< Fx > &&c)
Definition: sol.hpp:14877
void set_on(const T &target) const
Definition: sol.hpp:20672
basic_object_base(T &&arg, Args &&... args)
Definition: sol.hpp:15803
bool valid() const
Definition: sol.hpp:15622
auto initializers(Functions &&... functions)
Definition: sol.hpp:4515
basic_thread< stack_reference > stack_thread
Definition: sol.hpp:362
lua_State * lua_state() const
Definition: sol.hpp:16083
filter_wrapper< F, Filters... > P
Definition: sol.hpp:14915
overloaded_function(overload_list set)
Definition: sol.hpp:14257
state_view & new_enum(const string_view &name, std::initializer_list< std::pair< string_view, T >> items)
Definition: sol.hpp:21608
void operator()() const
Definition: sol.hpp:18344
T type
Definition: sol.hpp:16641
basic_object(const stack_reference &r) noexcept
Definition: sol.hpp:16170
void * value
Definition: sol.hpp:4862
iterator end()
Definition: sol.hpp:16019
auto as_function(Args &&... args)
Definition: sol.hpp:4972
constexpr in_place_tag in_place_of(detail::in_place_of_tag)
Definition: sol.hpp:3235
std::array< char, 2 > two
Definition: sol.hpp:16547
Definition: sol.hpp:15060
int indexing_fail(lua_State *L)
Definition: sol.hpp:18549
Definition: sol.hpp:5622
stack_iterator< stack_proxy, false > iterator
Definition: sol.hpp:12267
stack_guard(lua_State *L, int top, std::function< void(int, int)> fx=detail::stack_fail)
Definition: sol.hpp:7124
lua_State * main_thread(lua_State *L, lua_State *backup_if_unsupported=nullptr)
Definition: sol.hpp:6676
types< object_type &, FArgs... > free_args_list
Definition: sol.hpp:12711
std::array< char, 1 > one
Definition: sol.hpp:16291
simple_usertype_metatable(lua_State *L, detail::verified_tag v, Args &&... args)
Definition: sol.hpp:19502
std::array< char, 1 > one
Definition: sol.hpp:16561
Definition: sol.hpp:16289
static int pairs(lua_State *L)
Definition: sol.hpp:16756
meta::boolean< has_traits_set_test< T >::value > has_traits_set
Definition: sol.hpp:16595
protected_function_result safe_script(const string_view &code, Fx &&on_error, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21284
meta::function_args_t< function_type > args_lists
Definition: sol.hpp:14174
Definition: sol.hpp:8937
static int push(lua_State *L, P &&p)
Definition: sol.hpp:14925
static int push(lua_State *L, c_closure cc)
Definition: sol.hpp:10734
constexpr const T & storage() const
Definition: sol.hpp:3548
call_status luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, detail::protected_handler< b, handler_t > &h) const
Definition: sol.hpp:15146
function_map functions
Definition: sol.hpp:18437
Definition: sol.hpp:19896
static int push(lua_State *, const stack_proxy_base &ref)
Definition: sol.hpp:12163
Definition: sol.hpp:1731
basic_table< base_type > base_t
Definition: sol.hpp:15826
basic_table_core(detail::no_safety_tag, lua_nil_t n)
Definition: sol.hpp:20133
int operator()(lua_State *L)
Definition: sol.hpp:14271
const int newindex_function_index
Definition: sol.hpp:18387
Definition: sol.hpp:6207
Definition: sol.hpp:1212
int simple_real_new_index_call(lua_State *L)
Definition: sol.hpp:19313
difference_type operator-(const stack_iterator &r) const
Definition: sol.hpp:12046
const lua_nil_t lua_nil
Definition: sol.hpp:4683
protected_function_result script_file(const std::string &filename, const basic_environment< E > &env, Fx &&on_error, load_mode mode=load_mode::any)
Definition: sol.hpp:21401
std::string make_string(Arg &&arg)
Definition: sol.hpp:18514
void abandon() noexcept
Definition: sol.hpp:12374
static int real_clear_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17874
int push_reference(lua_State *L, T &&t, Args &&... args)
Definition: sol.hpp:7781
lib
Definition: sol.hpp:5102
constexpr result_type operator()(argument_type const &arg) const
Definition: sol.hpp:4349
basic_coroutine(lua_State *L, ref_index index, handler_t eh)
Definition: sol.hpp:22054
typename strip_extensible< T >::type strip_extensible_t
Definition: sol.hpp:7682
Definition: sol.hpp:5660
static int push(lua_State *L, T &&t)
Definition: sol.hpp:11260
basic_coroutine(const proxy_base< Super > &p)
Definition: sol.hpp:21991
bool is_valid(std::false_type)
Definition: sol.hpp:15521
std::size_t memory_used() const
Definition: sol.hpp:21477
static int call(lua_State *L)
Definition: sol.hpp:18981
int multi_push_reference(lua_State *L, T &&t, Args &&... args)
Definition: sol.hpp:7808
std::array< char, 2 > two
Definition: sol.hpp:16487
Definition: sol.hpp:7151
static int push(lua_State *L, userdata_value data)
Definition: sol.hpp:10847
std::initializer_list< int > swallow
Definition: sol.hpp:462
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8428
call_information(member_search index, member_search newindex)
Definition: sol.hpp:18397
Definition: sol.hpp:19336
Definition: sol.hpp:12732
meta::boolean< has_traits_size_test< T >::value > has_traits_size
Definition: sol.hpp:16616
auto as_args(Source &&source)
Definition: sol.hpp:15945
static int push(lua_State *L, lua_nil_t)
Definition: sol.hpp:10677
static int real_index_set_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17786
stack_safe_function stack_protected_function
Definition: sol.hpp:316
decltype(auto) get_key(std::true_type, T &&t)
Definition: sol.hpp:16658
std::remove_cv< std::remove_reference_t< T >> unqualified
Definition: sol.hpp:482
static int push(lua_State *L, C &&c)
Definition: sol.hpp:14860
int leftover_count() const
Definition: sol.hpp:16089
value_type * pointer
Definition: sol.hpp:19903
meta::boolean< has_traits_index_set_test< T >::value > has_traits_index_set
Definition: sol.hpp:16601
basic_protected_function(const basic_function< base_t > &b, handler_t eh)
Definition: sol.hpp:15258
Definition: sol.hpp:13005
static void select_reference_member_variable(std::false_type, lua_State *L, Fx &&fx, T &&obj, Args &&... args)
Definition: sol.hpp:14470
lua_bind_traits< meta::unqualified_t< F > > traits_type
Definition: sol.hpp:12610
basic_function(lua_State *L, int index=-1)
Definition: sol.hpp:15009
void set_fx(types< R(Args...)>, Key &&key, Fx &&fx)
Definition: sol.hpp:20477
Definition: sol.hpp:1299
std::reference_wrapper< T > source
Definition: sol.hpp:16270
void make_length_op_const(std::false_type, Regs &l, int &index)
Definition: sol.hpp:18249
pointer operator->()
Definition: sol.hpp:12004
Definition: sol.hpp:9624
constexpr ::std::remove_reference< T >::type && constexpr_move(T &&t) noexcept
Definition: sol.hpp:3443
Definition: sol.hpp:4387
int stack_index() const noexcept
Definition: sol.hpp:20890
basic_table_iterator()
Definition: sol.hpp:19915
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8526
auto as_returns(Source &&source)
Definition: sol.hpp:22117
std::conditional_t< std::is_array< meta::unqualified_t< T > >::value, T &, std::decay_t< T > > type
Definition: sol.hpp:18722
Definition: sol.hpp:6699
decltype(meta_detail::supports_op_equal_test(std::declval< T & >(), std::declval< U & >())) supports_op_equal
Definition: sol.hpp:1680
char32_t codepoint
Definition: sol.hpp:8926
error(std::string &&str)
Definition: sol.hpp:423
Definition: sol.hpp:7603
std::enable_if_t<!value, T > disable_if_t
Definition: sol.hpp:1317
static int push(lua_State *L, Arg0 &&arg0, Args &&... args)
Definition: sol.hpp:14627
handler_t error_handler
Definition: sol.hpp:15234
Definition: sol.hpp:6635
undefined_metatable(lua_State *l, const char *k)
Definition: sol.hpp:18340
reverse_iterator rend()
Definition: sol.hpp:12487
reference operator*() const
Definition: sol.hpp:12000
state_view & set_usertype(Key &&key, usertype< T > &user)
Definition: sol.hpp:21545
basic_table_core & set(Args &&... args)
Definition: sol.hpp:20270
int operator()(lua_State *L)
Definition: sol.hpp:14093
T & contained_val()
Definition: sol.hpp:3660
meta::unqualified_t< T > C
Definition: sol.hpp:18027
T value_type
Definition: sol.hpp:3686
static R invoke(O &mem, Args &&... args)
Definition: sol.hpp:12715
stack_proxy get(types< Args... >, index_value< 0 >, index_value< I >, const T &fr)
Definition: sol.hpp:12556
load_status err
Definition: sol.hpp:20788
decoded_result< It > utf32_to_code_point(It it, It last)
Definition: sol.hpp:9185
basic_protected_function(lua_State *L, int index, handler_t eh)
Definition: sol.hpp:15311
Definition: sol.hpp:6374
void deref() const noexcept
Definition: sol.hpp:6790
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:13927
Definition: sol.hpp:16249
void * align_user(void *ptr)
Definition: sol.hpp:7279
static int push(lua_State *L, protect_t< T > &&pw)
Definition: sol.hpp:14727
basic_reference(lua_State *L, detail::global_tag) noexcept
Definition: sol.hpp:6780
void tuple_set(std::index_sequence< I... >, Pairs &&pairs)
Definition: sol.hpp:20064
simple_usertype_metatable(lua_State *L)
Definition: sol.hpp:19517
std::array< char, 2 > two
Definition: sol.hpp:16412
error(detail::direct_error_tag, std::string &&str)
Definition: sol.hpp:429
static int push(lua_State *L, const char32_t *u32str)
Definition: sol.hpp:11126
void initialize(Args &&... args) noexcept(noexcept(T(::std::forward< Args >(args)...)))
Definition: sol.hpp:3672
const int metatable_core_index
Definition: sol.hpp:18381
F type
Definition: sol.hpp:13874
simple_usertype< Class > create_simple_usertype(Args &&... args)
Definition: sol.hpp:20372
void get(lua_State *L, Key &&key, int tableindex=-2)
Definition: sol.hpp:11403
basic_reference(basic_reference<!main_only > &&o) noexcept
Definition: sol.hpp:6896
void call_from_top(types< void > tr, types< Args... > ta, lua_State *L, Fx &&fx, FxArgs &&... args)
Definition: sol.hpp:11840
Definition: sol.hpp:7623
type
Definition: sol.hpp:5173
Definition: sol.hpp:18434
static const std::string & name()
Definition: sol.hpp:6165
basic_coroutine(lua_nil_t n)
Definition: sol.hpp:22017
static constexpr char32_t decode(unsigned char b0, unsigned char b1, unsigned char b2, unsigned char b3)
Definition: sol.hpp:8985
stack_proxy reference_type
Definition: sol.hpp:12262
int upvalues
Definition: sol.hpp:4949
Definition: sol.hpp:4821
call_information(member_search index, member_search newindex, int runtimetarget)
Definition: sol.hpp:18400
static int push(lua_State *L, const char16_t *str)
Definition: sol.hpp:11085
int push_reference(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7786
table create(int narr, int nrec, Key &&key, Value &&value, Args &&... args)
Definition: sol.hpp:20525
int push(lua_State *target) const
Definition: sol.hpp:16058
int typed_static_trampoline(lua_State *L)
Definition: sol.hpp:5993
Definition: sol.hpp:7042
lua_State * thread_state() const
Definition: sol.hpp:21815
basic_string_view< char32_t > u32string_view
Definition: sol.hpp:1189
basic_table_iterator & operator++()
Definition: sol.hpp:19931
Definition: sol.hpp:1346
static handler_t get_default_handler(lua_State *L)
Definition: sol.hpp:15135
variadic_args(lua_State *luastate, int stackindex=-1)
Definition: sol.hpp:15986
stack_iterator operator++(int)
Definition: sol.hpp:12019
Definition: sol.hpp:278
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t)
Definition: sol.hpp:21903
decltype(auto) property(std::true_type, R &&read, W &&write)
Definition: sol.hpp:12942
Definition: sol.hpp:4559
meta::bind_traits< Signature > base_t
Definition: sol.hpp:5731
static int real_empty_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17886
T * usertype_allocate(lua_State *L)
Definition: sol.hpp:7333
std::array< char, 2 > two
Definition: sol.hpp:16532
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8328
static int index_set(lua_State *L)
Definition: sol.hpp:16720
basic_coroutine(const stack_reference &r)
Definition: sol.hpp:21977
~push_popper_at()
Definition: sol.hpp:6609
void copy_assign(const basic_reference< r_main_only > &r)
Definition: sol.hpp:6729
static void walk_all_bases(lua_State *L, bool &found, int &ret, string_view &accessor)
Definition: sol.hpp:18711
int push() const
Definition: sol.hpp:16054
static int push(lua_State *L, ref_index ri)
Definition: sol.hpp:10975
Definition: sol.hpp:16672
constexpr auto resolve_i(types< R(Args...)>, F &&) -> R(meta::unqualified_t< F >::*)(Args...)
Definition: sol.hpp:14290
std::input_iterator_tag iterator_category
Definition: sol.hpp:19901
object mapped_type
Definition: sol.hpp:19899
typename at_in_pack< I, Args... >::type at_in_pack_t
Definition: sol.hpp:1358
Definition: sol.hpp:13873
static int push(std::index_sequence< I... >, lua_State *L, T &&t)
Definition: sol.hpp:11253
int(* member_search)(lua_State *, void *, usertype_metatable_core &, int)
Definition: sol.hpp:18390
basic_reference & operator=(const basic_reference &r) noexcept
Definition: sol.hpp:6907
bool operator>(const stack_iterator &r) const
Definition: sol.hpp:12078
int push_as_upvalues(lua_State *L, T &item)
Definition: sol.hpp:11742
basic_reference(const stack_reference &r) noexcept
Definition: sol.hpp:6799
static R apply(std::index_sequence<>, lua_State *, int, record &, Args &&... args)
Definition: sol.hpp:10024
meta_function meta_method
Definition: sol.hpp:5314
Definition: sol.hpp:5747
int operator()(lua_State *L)
Definition: sol.hpp:14193
reference_type ref
Definition: sol.hpp:19909
void add(lua_State *L, N &&n, destructor_wrapper< void > c)
Definition: sol.hpp:19454
static int push(lua_State *L, const char16_t *strb, const char16_t *stre)
Definition: sol.hpp:11091
Definition: sol.hpp:6697
type get_type() const noexcept
Definition: sol.hpp:12132
std::conditional_t< std::is_array< T >::value, std::add_lvalue_reference_t< T >, T > array_return_type
Definition: sol.hpp:12605
void script(lua_State *L, const string_view &code, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:11889
Definition: sol.hpp:4861
static int push(lua_State *L, lua_CFunction func, int n=0)
Definition: sol.hpp:10708
Definition: sol.hpp:466
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8384
bool empty() const
Definition: sol.hpp:20436
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8309
basic_lightuserdata(lua_State *L, int index=-1)
Definition: sol.hpp:15915
bool mustindex
Definition: sol.hpp:19353
basic_reference(lua_State *L, const stack_reference &r) noexcept
Definition: sol.hpp:6845
protected_function_result safe_script_file(const std::string &filename, load_mode mode=load_mode::any)
Definition: sol.hpp:21333
has_empty< T > has_traits_empty
Definition: sol.hpp:16622
int no_construction_error(lua_State *L)
Definition: sol.hpp:13088
static int real_index_set_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17790
optional_base(in_place_t, ::std::initializer_list< U > il, Args &&... args)
Definition: sol.hpp:3536
unsafe_function_result & operator=(const unsafe_function_result &)=default
static bool value
Definition: sol.hpp:6208
basic_string_view< Ch, Tr > argument_type
Definition: sol.hpp:1149
stack_proxy()
Definition: sol.hpp:12176
typename T::type invoke_t
Definition: sol.hpp:1287
typename ::std::remove_const< T >::type * dataptr()
Definition: sol.hpp:3630
std::unique_ptr< lua_State, detail::state_deleter > unique_base
Definition: sol.hpp:21860
typename ::std::conditional< ::std::is_trivially_destructible< T >::value, constexpr_optional_base< typename ::std::remove_const< T >::type >, optional_base< typename ::std::remove_const< T >::type >>::type OptionalBase
Definition: sol.hpp:3620
static int push(lua_State *L, char c)
Definition: sol.hpp:10918
int call_wrapper_function(std::true_type, lua_State *L)
Definition: sol.hpp:13827
static int push(lua_State *L, detail::yield_tag_t, Args &&... args)
Definition: sol.hpp:14634
basic_table_core & add(Args &&... args)
Definition: sol.hpp:20468
static int ipairs(lua_State *L)
Definition: sol.hpp:16760
basic_object(lua_State *L, absolute_index index) noexcept
Definition: sol.hpp:16190
Vector2< T > operator*(T n, Vector2< T > &vector2)
int index
Definition: sol.hpp:4822
as_table_t< meta::unqualified_t< T > > as_table(T &&container)
Definition: sol.hpp:5033
static int empty(lua_State *L)
Definition: sol.hpp:16744
constexpr in_place_tag in_place_type(detail::in_place_of_t< T >)
Definition: sol.hpp:3239
simple_usertype_metatable(lua_State *L, constructor_wrapper< Fxs... > constructorlist, Args &&... args)
Definition: sol.hpp:19532
int operator()(lua_State *L, int index, type expected, type actual, const std::string &message) const noexcept(false)
Definition: sol.hpp:6383
table reg
Definition: sol.hpp:21058
usertype_detail::mapping_t mapping
Definition: sol.hpp:18450
table create(Name &&name, int narr, int nrec, Key &&key, Value &&value, Args &&... args)
Definition: sol.hpp:20537
boolean< T::value > invoke_b
Definition: sol.hpp:1290
static basic_thread create(lua_State *L)
Definition: sol.hpp:21840
int index
Definition: sol.hpp:4800
static void convert(const char *strb, const char *stre, F &&f)
Definition: sol.hpp:9668
constexpr T const & value() const
Definition: sol.hpp:3885
Definition: sol.hpp:4810
typename bind_traits< Signature >::return_type function_return_t
Definition: sol.hpp:1038
int simple_new_index_call(lua_State *L)
Definition: sol.hpp:19327
std::add_lvalue_reference_t< meta::unwrapped_t< std::remove_reference_t< decltype(detail::deref(member))> > > M
Definition: sol.hpp:14206
T & storage()
Definition: sol.hpp:3601
static int push(lua_State *, const this_main_state &)
Definition: sol.hpp:11309
in_place_tag(&)(detail::in_place_of_t< T >) in_place_type_t
Definition: sol.hpp:3249
T & storage()
Definition: sol.hpp:3544
Definition: sol.hpp:1396
static void call(Fx &&fx, object_type &mem, Arg &&arg, Args &&...)
Definition: sol.hpp:12686
int trampoline(lua_State *L, Fx &&f, Args &&... args)
Definition: sol.hpp:5946
std::tuple< Functions... > functions
Definition: sol.hpp:4507
encoded_result< char16_t > code_point_to_utf16(char32_t codepoint)
Definition: sol.hpp:9038
void collect_garbage()
Definition: sol.hpp:21491
Definition: sol.hpp:5803
int simple_index_call(lua_State *L)
Definition: sol.hpp:19318
typename detail::tuple_types_< Args... >::type tuple_types
Definition: sol.hpp:488
basic_object< reference > object
Definition: sol.hpp:350
constexpr T const * operator->() const
Definition: sol.hpp:3813
Definition: sol.hpp:18721
Definition: sol.hpp:22140
stack_proxy operator[](difference_type index_offset) const
Definition: sol.hpp:12320
Definition: sol.hpp:13362
static int real_set_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17778
usertype(detail::verified_tag, Args &&... args)
Definition: sol.hpp:19813
Definition: sol.hpp:298
table new_enum(const string_view &name, Args &&... args)
Definition: sol.hpp:20390
usertype_detail::registrar * registrar_data()
Definition: sol.hpp:19849
nested(Arg0 &&arg0, Arg1 &&arg1, Args &&... args)
Definition: sol.hpp:5018
static void insert_at_end(std::false_type, types< V >, lua_State *L, T &arr, std::size_t idx)
Definition: sol.hpp:9278
probe get(lua_State *L, Key &&key, int tableindex=-2)
Definition: sol.hpp:11651
basic_coroutine(lua_State *L, raw_index index, handler_t eh)
Definition: sol.hpp:22044
table new_enum(const string_view &name, std::initializer_list< std::pair< string_view, T >> items)
Definition: sol.hpp:20406
Definition: sol.hpp:16364
load_result load(const string_view &code, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21430
Definition: sol.hpp:1218
Definition: sol.hpp:13762
Definition: sol.hpp:1305
std::size_t s
Definition: sol.hpp:1066
bool check(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:7829
const_iterator end() const
Definition: sol.hpp:16025
meta::condition< meta::is_specialization_of< Key, std::tuple >, Key, std::tuple< meta::condition< std::is_array< meta::unqualified_t< Key > >, Key &, meta::unqualified_t< Key > > > > key_type
Definition: sol.hpp:15503
std::array< char, 1 > one
Definition: sol.hpp:16486
void invoke(types< void >, std::index_sequence< I >, std::ptrdiff_t n)
Definition: sol.hpp:21925
T actual_type
Definition: sol.hpp:4737
stack_proxy value_type
Definition: sol.hpp:15976
basic_protected_function(lua_nil_t n)
Definition: sol.hpp:15304
Definition: sol.hpp:19997
static umt_t & make_cleanup(lua_State *L, umt_t &&umx)
Definition: sol.hpp:19021
static void convert(const char *strb, const char *stre, F &&f)
Definition: sol.hpp:9719
T & operator*()
Definition: sol.hpp:3880
static T * get_no_lua_nil(lua_State *L, int index, record &tracking)
Definition: sol.hpp:9916
decoded_result< It > utf16_to_code_point(It it, It last)
Definition: sol.hpp:9147
void insert_prepare(std::false_type, lua_State *L, N &&n, F &&f, Args &&... args)
Definition: sol.hpp:19384
typename identity< T >::type identity_t
Definition: sol.hpp:1215
static int real_call(lua_State *L) noexcept(false)
Definition: sol.hpp:14103
static int push_rvalue(std::true_type, lua_State *L, C &&cont)
Definition: sol.hpp:18039
int multi_push_reference(lua_State *)
Definition: sol.hpp:7802
~protected_function_result()
Definition: sol.hpp:12381
optional_base(const T &v)
Definition: sol.hpp:3519
std::string associated_type_name(lua_State *L, int index, type t)
Definition: sol.hpp:6311
load_status
Definition: sol.hpp:5165
T v
Definition: sol.hpp:12984
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8504
bool secondarymeta
Definition: sol.hpp:19354
basic_coroutine(lua_State *L, T &&r, handler_t eh)
Definition: sol.hpp:22008
stack_iterator< stack_proxy, false > iterator
Definition: sol.hpp:15980
T object_type
Definition: sol.hpp:570
bool is_toplevel(lua_State *L, int index=magic_index)
Definition: sol.hpp:18536
void reserve(T &, std::size_t)
Definition: sol.hpp:7583
static int push(lua_State *L, const T &tablecont)
Definition: sol.hpp:10543
static int pairs_call(lua_State *L)
Definition: sol.hpp:17946
void * align_usertype_pointer(void *ptr)
Definition: sol.hpp:7200
std::string short_demangle_once()
Definition: sol.hpp:6108
variable_map variables
Definition: sol.hpp:18436
meta::any< is_constructor< meta::unqualified_t< Args >>... > has_constructor
Definition: sol.hpp:5800
basic_table_core & new_simple_usertype(const std::string &name, constructors< CArgs... > ctor, Args &&... args)
Definition: sol.hpp:20365
bool error() const noexcept
Definition: sol.hpp:22067
static int push(lua_State *L, const char *strb, const char *stre)
Definition: sol.hpp:10890
int call_lua(lua_State *L, int start, Fx &&fx, FxArgs &&... fxargs)
Definition: sol.hpp:11870
decltype(&inheritance< void >::type_unique_cast< void >) inheritance_unique_cast_function
Definition: sol.hpp:6301
T * obj
Definition: sol.hpp:13116
global_table::iterator iterator
Definition: sol.hpp:21115
T value
Definition: sol.hpp:4483
stack_iterator(const stack_iterator< proxy_t, true > &r)
Definition: sol.hpp:11989
static int push(lua_State *L, lightuserdata_value userdata)
Definition: sol.hpp:10772
unique_usertype_traits< T >::type P
Definition: sol.hpp:10007
basic_thread(lua_State *L, lua_thread_state actualthread)
Definition: sol.hpp:21796
const value_type & const_reference
Definition: sol.hpp:19905
types< Args... > type
Definition: sol.hpp:475
basic_thread(lua_State *L, int index=-1)
Definition: sol.hpp:21775
int pop_count() const noexcept
Definition: sol.hpp:12371
stack_proxy value_type
Definition: sol.hpp:12263
std::conditional_t< can_write::value, W, no_prop > Write
Definition: sol.hpp:12930
basic_reference & operator=(basic_reference<!main_only > &&r) noexcept
Definition: sol.hpp:6912
static void select_function(std::true_type, lua_State *L, lua_CFunction f)
Definition: sol.hpp:14592
value_type & reference
Definition: sol.hpp:19904
basic_lightuserdata(lua_State *L, ref_index index)
Definition: sol.hpp:15922
void modify_unique_usertype(const stack_reference &obj, F &&f)
Definition: sol.hpp:8140
static int push(std::true_type, lua_State *L, const T &tablecont)
Definition: sol.hpp:10548
void add_member_function(std::false_type, lua_State *L, N &&n, F &&f)
Definition: sol.hpp:19395
basic_reference & operator=(const basic_reference<!main_only > &r) noexcept
Definition: sol.hpp:6917
decltype(auto) get_or(Key &&key, T &&otherwise) const
Definition: sol.hpp:20237
key_type key
Definition: sol.hpp:15530
constexpr bool operator!=(const optional< T > &x, const optional< T > &y)
Definition: sol.hpp:4057
protected_function_result do_string(const string_view &code, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21263
basic_protected_function(const stack_reference &r)
Definition: sol.hpp:15264
void set(lua_State *L, Key &&key, Value &&value, int tableindex=-3)
Definition: sol.hpp:11530
stack_proxy value_type
Definition: sol.hpp:12414
state_view(this_state Ls)
Definition: sol.hpp:21122
static int push(lua_State *L, bool b)
Definition: sol.hpp:10669
lua_nil_t nil_t
Definition: sol.hpp:4690
state_view & new_simple_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:21569
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8413
boolean<!T::value > neg
Definition: sol.hpp:1293
int call(lua_State *L)
Definition: sol.hpp:14213
U value
Definition: sol.hpp:4900
static int push_sized(lua_State *L, const char *str, std::size_t len)
Definition: sol.hpp:10856
const_reverse_iterator crbegin() const
Definition: sol.hpp:12496
Definition: sol.hpp:3219
static int length_call(lua_State *L)
Definition: sol.hpp:17942
std::array< char, 2 > two
Definition: sol.hpp:16382
std::conditional_t< Condition::value, Then, Else > condition
Definition: sol.hpp:1296
functor_function(function_type f, Args &&... args)
Definition: sol.hpp:14145
lua_State * lua_state() const noexcept
Definition: sol.hpp:12362
Definition: sol.hpp:4705
lua_State * lua_state() const
Definition: sol.hpp:15648
Definition: sol.hpp:340
const_iterator cbegin() const
Definition: sol.hpp:12336
iterator begin() const
Definition: sol.hpp:20213
int oss_default_to_string(std::false_type, lua_State *L)
Definition: sol.hpp:18168
auto invoke(types< Ret... >, std::index_sequence< I... >, std::ptrdiff_t n) const
Definition: sol.hpp:14947
static int push(lua_State *L, C &&c)
Definition: sol.hpp:14848
void insert_default_registrations(std::true_type, Regs &l, int &index, Fx &&fx)
Definition: sol.hpp:18297
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:14038
Definition: sol.hpp:12983
basic_reference(const basic_reference<!main_only > &o) noexcept
Definition: sol.hpp:6892
meta::boolean< has_traits_at_test< T >::value > has_traits_at
Definition: sol.hpp:16592
simple_usertype_metatable(lua_State *L, detail::check_destructor_tag, Args &&... args)
Definition: sol.hpp:19512
constexpr optional(const T &v)
Definition: sol.hpp:3718
std::conditional_t< std::is_void< T >::value, args_list, types< first_type, Args... > > free_args_list
Definition: sol.hpp:574
std::tuple< Args... > args_tuple
Definition: sol.hpp:569
Definition: sol.hpp:394
basic_environment(lua_State *L, int index=-1)
Definition: sol.hpp:20629
int overload_match_arity(Match &&matchfx, lua_State *L, int fxarity, int start, Args &&... args)
Definition: sol.hpp:13195
meta::bind_traits< function_type >::args_list args_lists
Definition: sol.hpp:14203
virtual int index(lua_State *L) override
Definition: sol.hpp:18422
static void select_member_variable(std::true_type, lua_State *L, Fx &&fx)
Definition: sol.hpp:14512
lua_bind_traits< F > traits_type
Definition: sol.hpp:12709
bool valid() const noexcept
Definition: sol.hpp:20863
static int real_find_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17910
state_view & new_simple_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:21575
bool init_
Definition: sol.hpp:3514
int push(lua_State *L, T &&t, Args &&... args)
Definition: sol.hpp:7770
decltype(auto) get_value(std::true_type, T &&t)
Definition: sol.hpp:16668
Definition: sol.hpp:1224
static int push(lua_State *L, absolute_index ai)
Definition: sol.hpp:10959
usertype_detail::base_walk indexbaseclasspropogation
Definition: sol.hpp:19349
Definition: sol.hpp:583
static int call(lua_State *L)
Definition: sol.hpp:13910
static constexprbool has_assign(...)
Definition: sol.hpp:3391
std::ptrdiff_t difference_type
Definition: sol.hpp:12416
call_status status() const noexcept
Definition: sol.hpp:22063
static optional< R > get(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:10157
constexpr in_place_tag in_place(detail::in_place_of_tag)
Definition: sol.hpp:3223
static int push_func(std::index_sequence< I... >, lua_State *L, FP &&fp)
Definition: sol.hpp:14661
lua_CFunction indexfunc
Definition: sol.hpp:18451
std::reverse_iterator< iterator > reverse_iterator
Definition: sol.hpp:12420
variadic_args(lua_State *luastate, int stackindex, int lastindex)
Definition: sol.hpp:15989
auto make_string_view(base_classes_tag)
Definition: sol.hpp:18509
void script_file(lua_State *L, const std::string &filename, load_mode mode=load_mode::any)
Definition: sol.hpp:11897
table create_with(Args &&... args)
Definition: sol.hpp:20544
basic_userdata(stack_reference &&r)
Definition: sol.hpp:15849
void add(lua_State *L, N &&n, constructor_wrapper< Fxs... > c)
Definition: sol.hpp:19434
meta::bind_traits< Signature > fx_t
Definition: sol.hpp:15456
T * static_addressof(T &ref)
Definition: sol.hpp:3477
meta::boolean< has_traits_pairs_test< T >::value > has_traits_pairs
Definition: sol.hpp:16604
protected_function_result safe_script_file(const std::string &filename, Fx &&on_error, load_mode mode=load_mode::any)
Definition: sol.hpp:21311
int is_indexer(base_classes_tag)
Definition: sol.hpp:18493
std::array< char, 1 > one
Definition: sol.hpp:16366
const auto base_classes
Definition: sol.hpp:6202
Definition: sol.hpp:4675
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: sol.hpp:12270
void emplace(T &v) noexcept
Definition: sol.hpp:4007
int returncount
Definition: sol.hpp:12410
error_result(const char *fmt_, const char *msg)
Definition: sol.hpp:16683
lua_State * pick_main_thread(lua_State *L, lua_State *backup_if_unsupported=nullptr)
Definition: sol.hpp:6703
Definition: sol.hpp:4436
decltype(auto) base_class_new_index_propogation_key()
Definition: sol.hpp:6229
void * align_usertype_unique_destructor(void *ptr)
Definition: sol.hpp:7217
static int real_at_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17754
Definition: sol.hpp:5715
basic_coroutine(stack_reference &&r)
Definition: sol.hpp:21980
static int call(lua_State *L)
Definition: sol.hpp:13876
static int push(lua_State *L, const std::initializer_list< T > &il)
Definition: sol.hpp:10648
static int real_pairs_call(lua_State *L)
Definition: sol.hpp:17806
lua_State * lua_state() const
Definition: sol.hpp:12145
probe(bool s, int l)
Definition: sol.hpp:7633
stack_table_core< true > stack_global_table
Definition: sol.hpp:296
simple_usertype< Class > create_simple_usertype(Args &&... args)
Definition: sol.hpp:21592
static table create(lua_State *L, int narr, int nrec, Key &&key, Value &&value, Args &&... args)
Definition: sol.hpp:20505
static int next_call(lua_State *L)
Definition: sol.hpp:17954
Definition: sol.hpp:7039
basic_protected_function< reference, false, reference > safe_function
Definition: sol.hpp:307
static int push(lua_State *L, T *obj)
Definition: sol.hpp:10406
tie_t & operator=(T &&value)
Definition: sol.hpp:7078
table create(Name &&name, int narr=0, int nrec=0)
Definition: sol.hpp:20530
iterator begin()
Definition: sol.hpp:12324
sol::optional< T > argument_type
Definition: sol.hpp:4347
basic_object_base< base_type > base_t
Definition: sol.hpp:15880
basic_function(lua_State *L, T &&r)
Definition: sol.hpp:15001
void add(lua_State *, N &&n, F &&f)
Definition: sol.hpp:19420
std::enable_if_t< any< Args... >::value, enable_t > enable_any
Definition: sol.hpp:1326
std::ptrdiff_t difference_type
Definition: sol.hpp:12265
stack_proxy(lua_State *L, int index)
Definition: sol.hpp:12179
basic_table_core(lua_State *L, detail::global_tag t) noexcept
Definition: sol.hpp:20128
decltype(auto) tagged_get(types< T >, lua_State *L, int index, record &tracking)
Definition: sol.hpp:7964
function_arguments(Arg &&arg, Args &&... args)
Definition: sol.hpp:4966
static void destroy(T &&obj)
Definition: sol.hpp:4452
basic_environment(lua_State *L, new_table t, const basic_reference< b > &fallback)
Definition: sol.hpp:20604
char[32] typical_chunk_name_t
Definition: sol.hpp:11708
Definition: sol.hpp:14200
Definition: sol.hpp:4938
static int real_find_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17906
static bool check(types< T, Args... >, lua_State *L, int firstargument, Handler &&handler, record &tracking)
Definition: sol.hpp:7972
static void call(Args...)
Definition: sol.hpp:13110
Definition: sol.hpp:3424
unsigned char u8
~clean()
Definition: sol.hpp:19993
static int real_insert_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17862
static int push(std::false_type, lua_State *L, const T &tablecont)
Definition: sol.hpp:10553
std::bitset< 32 > properties
Definition: sol.hpp:18750
static int push_lvalue(std::true_type, lua_State *L, const C &cont)
Definition: sol.hpp:18029
static int push(lua_State *L, const var_wrapper< T > &vw)
Definition: sol.hpp:14779
const_iterator end() const
Definition: sol.hpp:12333
static constexprbool has_assign(bool)
Definition: sol.hpp:3397
static void select_reference_member_variable(std::true_type, lua_State *L, Fx &&fx, T &&obj, Args &&... args)
Definition: sol.hpp:14477
Definition: sol.hpp:12104
typename unwrapped< T >::type unwrapped_t
Definition: sol.hpp:1237
Definition: sol.hpp:3493
int operator()(lua_State *L)
Definition: sol.hpp:14059
OPTIONAL_CONSTEXPR_INIT_LIST optional(in_place_t, ::std::initializer_list< U > il, Args &&... args)
Definition: sol.hpp:3732
int returncount
Definition: sol.hpp:12216
traits_type::args_list args_list
Definition: sol.hpp:12611
this_state(lua_State *Ls)
Definition: sol.hpp:5050
basic_environment(stack_reference &&r)
Definition: sol.hpp:20596
const_iterator cend() const
Definition: sol.hpp:16031
basic_thread(lua_State *L, this_state actualthread)
Definition: sol.hpp:21793
static int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:10807
int push() const noexcept
Definition: sol.hpp:15629
decltype(auto) unqualified_get(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:8047
static void select_member_function(std::true_type, lua_State *L, Fx &&fx)
Definition: sol.hpp:14565
Definition: sol.hpp:7611
const char * key
Definition: sol.hpp:18338
static int real_ipairs_call(lua_State *L)
Definition: sol.hpp:17818
protected_function_result script_file(const std::string &filename, const environment &env, load_mode mode=load_mode::any)
Definition: sol.hpp:21409
static int push(lua_State *L, const function_arguments< T, Args... > &fp)
Definition: sol.hpp:14665
static int push(lua_State *L, raw_index ri)
Definition: sol.hpp:10967
Definition: sol.hpp:7621
std::basic_string< wchar_t, Traits, Al > S
Definition: sol.hpp:9654
int operator()(types< Fx >, index_value< I >, types< R... >, types< Args... >, lua_State *L, int, int, F &fx)
Definition: sol.hpp:13618
static int push(lua_State *L, const char *str, std::size_t len)
Definition: sol.hpp:10896
unsafe_function_result(unsafe_function_result &&o)
Definition: sol.hpp:12429
int operator()(types< Fx >, index_value< I >, types< R... >, types< Args... >, lua_State *L, int, int, F &fx)
Definition: sol.hpp:13601
static int real_call_with(lua_State *L, usertype_metatable &um)
Definition: sol.hpp:18969
std::string w
Definition: sol.hpp:417
usertype_metatable< T, std::index_sequence< I... >, Args... > umt_t
Definition: sol.hpp:19018
std::conditional_t< can_read::value, R, no_prop > Read
Definition: sol.hpp:12929
lua_State * L
Definition: sol.hpp:5068
Definition: sol.hpp:12707
Definition: sol.hpp:344
bool check_stack(int modification=0) const
Definition: sol.hpp:7127
const destructor_wrapper< void > default_destructor
Definition: sol.hpp:4544
std::make_index_sequence< sizeof...(Args)> indices
Definition: sol.hpp:467
lua_State * L
Definition: sol.hpp:21057
static int push(lua_State *L, const char *str, std::size_t len)
Definition: sol.hpp:10871
Definition: sol.hpp:305
protected_function_result script_default_on_error(lua_State *L, protected_function_result pfr)
Definition: sol.hpp:21042
int stack_index() const
Definition: sol.hpp:12514
lua_State * luastate
Definition: sol.hpp:6718
std::integral_constant< bool, B > boolean
Definition: sol.hpp:1284
constexpr nullopt_t(init)
Definition: sol.hpp:3495
Definition: sol.hpp:4499
static int find_call(lua_State *L)
Definition: sol.hpp:17938
basic_object(lua_State *L, in_place_t, T &&arg, Args &&... args) noexcept
Definition: sol.hpp:16204
static int core_indexing_call(lua_State *L)
Definition: sol.hpp:18899
meta::unqualified_t< typename traits_type::template arg_at< 0 > > object_type
Definition: sol.hpp:13635
basic_environment(lua_nil_t r) noexcept
Definition: sol.hpp:20655
static int real_meta_index_call(lua_State *L)
Definition: sol.hpp:18954
static int push(lua_State *L, const char16_t(&str)[N])
Definition: sol.hpp:11195
void get_field(lua_State *L, Key &&key)
Definition: sol.hpp:8069
static table create_table(lua_State *L, int narr=0, int nrec=0)
Definition: sol.hpp:21671
static void * type_cast_bases(types<>, T *, const std::string &)
Definition: sol.hpp:6249
traits_type::returns_list returns_list
Definition: sol.hpp:12613
Definition: sol.hpp:6197
int return_count() const
Definition: sol.hpp:12517
static void select_reference_member_function(std::true_type, lua_State *L, Fx &&fx, T &&obj, Args &&... args)
Definition: sol.hpp:14530
Definition: sol.hpp:5414
optional< error > tagged_get(types< optional< error >>) const
Definition: sol.hpp:20808
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:13901
static int real_next_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17822
Definition: sol.hpp:5067
object index
Definition: sol.hpp:18438
void add(lua_State *L, N &&n, destructor_wrapper< Fx > c)
Definition: sol.hpp:19464
lua_State * state
Definition: sol.hpp:19864
bool valid() const noexcept
Definition: sol.hpp:12307
basic_environment(T &&r) noexcept
Definition: sol.hpp:20645
static int push(lua_State *L, usertype< T > &user)
Definition: sol.hpp:19882
lua_State * L
Definition: sol.hpp:19998
load_result & operator=(load_result &&o) noexcept
Definition: sol.hpp:20842
meta::boolean< has_clear_test< T >::value > has_clear
Definition: sol.hpp:16574
basic_function< main_reference, false > main_unsafe_function
Definition: sol.hpp:308
static iterator begin(lua_State *L, T &)
Definition: sol.hpp:16764
basic_coroutine(T &&r) noexcept
Definition: sol.hpp:21951
std::unordered_map< K, V, H, E > map_t
Definition: sol.hpp:4644
static int push(lua_State *L, const char(&str)[N], std::size_t sz)
Definition: sol.hpp:10910
function_type var
Definition: sol.hpp:14204
void for_each(Fx &&fx)
Definition: sol.hpp:21614
std::remove_pointer_t< T > P
Definition: sol.hpp:18336
int set_ref(lua_State *L, T &&arg, int tableindex=-2)
Definition: sol.hpp:11806
T type
Definition: sol.hpp:7658
int returncount
Definition: sol.hpp:20786
types< Arg > args_list
Definition: sol.hpp:1016
decltype(auto) call(Args &&... args)
void invoke(types< void >, std::index_sequence< I >, std::ptrdiff_t n) const
Definition: sol.hpp:14959
protected_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n)
Definition: sol.hpp:21929
static int push(std::index_sequence< I... >, lua_State *L, T &&c)
Definition: sol.hpp:10743
static int push_sized(lua_State *L, const char *str, std::size_t len)
Definition: sol.hpp:10878
object require_script(const std::string &key, const string_view &code, bool create_global=true, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21225
global_table global
Definition: sol.hpp:21059
basic_object(lua_nil_t r)
Definition: sol.hpp:16165
#define OPTIONAL_CONSTEXPR_INIT_LIST
Definition: sol.hpp:3334
basic_object & operator=(const proxy_base< Super > &r)
Definition: sol.hpp:16218
proxy & operator=(U &&other)
Definition: sol.hpp:15550
T member
Definition: sol.hpp:14176
types< T, Arg > free_args_list
Definition: sol.hpp:1017
Definition: sol.hpp:7657
thread_status status() const
Definition: sol.hpp:21821
bool is() const
Definition: sol.hpp:12123
static const std::string & qualified_name()
Definition: sol.hpp:6169
T member
Definition: sol.hpp:14205
static int push(lua_State *L, const char32_t *strb, const char32_t *stre)
Definition: sol.hpp:11134
static int real_insert_call(lua_State *L)
Definition: sol.hpp:17866
static int real_pairs_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17802
basic_coroutine(Proxy &&p, Handler &&eh)
Definition: sol.hpp:21999
static int real_clear_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17870
wrapper< meta::unqualified_t< F > > wrap
Definition: sol.hpp:13238
void make_regs(regs_t &, int &, base_classes_tag, bases< Bases... >)
Definition: sol.hpp:18791
static table create(lua_State *L, int narr=0, int nrec=0)
Definition: sol.hpp:20497
metatable_registry_key(T key)
Definition: sol.hpp:4926
unique_usertype_traits< T >::actual_type Real
Definition: sol.hpp:10438
const yield_tag_t yield_tag
Definition: sol.hpp:4679
int is_check(lua_State *L)
Definition: sol.hpp:18133
Definition: sol.hpp:7609
static void select_reference_member_function(std::false_type, lua_State *L, Fx &&fx, T &&obj, Args &&... args)
Definition: sol.hpp:14523
static int real_call(lua_State *L) noexcept(traits_type::is_noexcept)
Definition: sol.hpp:13963
tagged(Arg &&arg, Args &&... args)
Definition: sol.hpp:4485
std::add_pointer_t< meta::unqualified_t< std::remove_pointer_t< T > > > C
Definition: sol.hpp:18059
const type_panic_t type_panic
Definition: sol.hpp:6364
hash< T >::result_type result_type
Definition: sol.hpp:4346
basic_reference & operator=(basic_reference &&r) noexcept
Definition: sol.hpp:6902
load_result load(lua_Reader reader, void *data, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21446
stack_reference(lua_nil_t) noexcept
Definition: sol.hpp:6457
void type_error(lua_State *L, int expected, int actual) noexcept(false)
Definition: sol.hpp:6406
basic_table_core & new_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:20332
stack_iterator operator--(int)
Definition: sol.hpp:12030
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8181
static int defer_call(std::true_type, lua_State *L, F &&f, Args &&... args)
Definition: sol.hpp:13674
int simple_real_index_call(lua_State *L)
Definition: sol.hpp:19308
const_reverse_iterator crbegin() const
Definition: sol.hpp:16047
static bool type_check_bases(types<>, const std::string &)
Definition: sol.hpp:6236
static char32_t combine_surrogates(char16_t lead, char16_t trail)
Definition: sol.hpp:8997
std::enable_if_t< neg< all< Args... >>::value, enable_t > disable
Definition: sol.hpp:1323
container_detail::container_traits_default< T > default_traits
Definition: sol.hpp:17708
int is_indexer(string_view s)
Definition: sol.hpp:18469
static int push_keyed(lua_State *L, K &&k, T *obj)
Definition: sol.hpp:10401
object require_file(const std::string &key, const std::string &filename, bool create_global=true, load_mode mode=load_mode::any)
Definition: sol.hpp:21232
void * baseclasscheck
Definition: sol.hpp:19351
basic_protected_function(lua_State *L, raw_index index, handler_t eh)
Definition: sol.hpp:15331
static int push(lua_State *L, const protect_t< T > &pw)
Definition: sol.hpp:14735
Definition: sol.hpp:1278
const no_metatable_t no_metatable
Definition: sol.hpp:4706
Definition: sol.hpp:7605
std::shared_ptr< T > actual_type
Definition: sol.hpp:4757
probe apply(std::index_sequence< I, I1, In... >, int sofar, lua_State *L, Keys &&keys, int tableindex)
Definition: sol.hpp:11685
basic_environment(lua_State *L, ref_index index)
Definition: sol.hpp:20636
decltype(auto) unchecked_unqualified_get(lua_State *L, int index, record &tracking)
Definition: sol.hpp:7696
static std::function< Signature > get_std_func(types< void >, types< FxArgs... >, lua_State *L, int index)
Definition: sol.hpp:15470
static constexpr bool is_surrogate(char32_t u)
Definition: sol.hpp:8956
usertype(constructor_wrapper< Fxs... > constructorlist, Args &&... args)
Definition: sol.hpp:19840
bool xmovable(lua_State *leftL, lua_State *rightL)
Definition: sol.hpp:6435
static int at(lua_State *L)
Definition: sol.hpp:16704
bool maybe_indexable(lua_State *L, int index=-1)
Definition: sol.hpp:7738
basic_table_core & new_simple_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:20359
decltype(auto) writeonly_property(F &&f)
Definition: sol.hpp:12978
static int push(lua_State *L, const char16_t *u16str)
Definition: sol.hpp:11047
static int meta_new_index_call(lua_State *L)
Definition: sol.hpp:19002
Definition: sol.hpp:348
Definition: sol.hpp:5742
int overload_match_arity_single(types< Fx, Fx1, Fxs... >, std::index_sequence< I, I1, In... >, std::index_sequence< M... >, Match &&matchfx, lua_State *L, int fxarity, int start, Args &&... args)
Definition: sol.hpp:13175
basic_table_core(detail::no_safety_tag, T &&r) noexcept
Definition: sol.hpp:20143
stack_detail::strip_extensible_t< U > T
Definition: sol.hpp:9211
int operator()(types< Fx >, index_value< I >, types< R... > r, types< Args... > a, lua_State *L, int, int start, F &f)
Definition: sol.hpp:13537
T ** usertype_allocate_pointer(lua_State *L)
Definition: sol.hpp:7296
ref_index(int idx)
Definition: sol.hpp:4834
lua_State * operator->() const noexcept
Definition: sol.hpp:5058
std::pair< T, int > get_as_upvalues(lua_State *L, int index=2)
Definition: sol.hpp:11760
basic_table_core(detail::no_safety_tag, lua_State *L, T &&r) noexcept
Definition: sol.hpp:20147
static int clear(lua_State *L)
Definition: sol.hpp:16740
stack_iterator operator+(difference_type idx) const
Definition: sol.hpp:12050
T key
Definition: sol.hpp:4924
Definition: sol.hpp:12724
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:14100
Definition: sol.hpp:4542
void make_call_op(Regs &l, int &index)
Definition: sol.hpp:18223
auto destructor(Fx &&fx)
Definition: sol.hpp:4547
const std::string & to_string(call_status c)
Definition: sol.hpp:5190
decltype(auto) tuplefy(X &&... x)
Definition: sol.hpp:1791
basic_string_view(const Char *ptr, std::size_t sz)
Definition: sol.hpp:1075
Definition: sol.hpp:18729
bool mustindex
Definition: sol.hpp:18454
simple_usertype_metatable(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:19522
Definition: sol.hpp:4947
Definition: sol.hpp:20702
auto operator=(U &&v) -> typename ::std::enable_if< ::std::is_same< typename ::std::decay< U >::type, T >::value, optional &>::type
Definition: sol.hpp:3766
state_view & set_function(Key &&key, Args &&... args)
Definition: sol.hpp:21635
static bool is_null(const actual_type &p)
Definition: sol.hpp:4766
static bool max_size_check(std::true_type, T &arr, std::size_t idx)
Definition: sol.hpp:9286
static int real_set_call(lua_State *L)
Definition: sol.hpp:17782
Definition: sol.hpp:1698
Definition: sol.hpp:4506
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:13960
Function fx
Definition: sol.hpp:4535
decltype(auto) base_class_cast_key()
Definition: sol.hpp:6219
int results
Definition: sol.hpp:16673
basic_reference & operator=(const lua_nil_t &) noexcept
Definition: sol.hpp:6922
closure(lua_CFunction f, int upvalue_count=0)
Definition: sol.hpp:4950
int call_exception_handler(lua_State *L, optional< const std::exception &> maybe_ex, string_view what)
Definition: sol.hpp:5850
optional(const optional< T &> &rhs)
Definition: sol.hpp:3702
usertype(constructors< CArgs... > constructorlist, Args &&... args)
Definition: sol.hpp:19835
probe probe_get_field(lua_State *L, Key &&key, int tableindex)
Definition: sol.hpp:8094
basic_protected_function(const basic_function< base_t > &b)
Definition: sol.hpp:15252
usertype(simple_tag, lua_State *L, Args &&... args)
Definition: sol.hpp:19845
call_syntax
Definition: sol.hpp:5133
std::random_access_iterator_tag iterator_category
Definition: sol.hpp:11980
int cannot_destruct(lua_State *L)
Definition: sol.hpp:7578
basic_protected_function(lua_State *L, int index=-1)
Definition: sol.hpp:15308
static int real_next_call(lua_State *L)
Definition: sol.hpp:17830
Definition: sol.hpp:8877
static auto get(U &&value)
Definition: sol.hpp:4749
Definition: sol.hpp:5767
constexpr optional_base() noexcept
Definition: sol.hpp:3516
std::size_t length() const
Definition: sol.hpp:1114
void operator()(T &&obj) const
Definition: sol.hpp:4458
load_result(load_result &&o) noexcept
Definition: sol.hpp:20831
int stack_index() const noexcept
Definition: sol.hpp:6516
const int & operator[](std::size_t i) const
Definition: sol.hpp:4585
static int push(lua_State *L, const std::basic_string< Ch, Traits, Al > &wstr, std::size_t sz)
Definition: sol.hpp:11245
void top_apply(std::index_sequence< I0, I... >, lua_State *L, Keys &&keys, Value &&value, int tableindex)
Definition: sol.hpp:11619
map_t< std::string, call_information > mapping_t
Definition: sol.hpp:18405
static int push_keyed(lua_State *L, K &&k, Args &&... args)
Definition: sol.hpp:10375
decltype(auto) get_usertype(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:8036
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:18095
usertype_detail::function_map registrations
Definition: sol.hpp:19342
static void * type_cast_bases(types< Base, Args... >, T *data, const std::string &ti)
Definition: sol.hpp:6254
protected_function_result script_throw_on_error(lua_State *L, protected_function_result result)
Definition: sol.hpp:20984
Definition: sol.hpp:14171
basic_table_core(lua_State *L, T &&r)
Definition: sol.hpp:20169
Definition: sol.hpp:4794
basic_object(T &&r)
Definition: sol.hpp:16158
variadic_args & operator=(variadic_args &&o)
Definition: sol.hpp:16003
auto invoke(types< Ret... >, std::index_sequence< I... >, std::ptrdiff_t n)
Definition: sol.hpp:21913
bool check_metatable(lua_State *L, int index=-2)
Definition: sol.hpp:8164
Definition: sol.hpp:13765
state_view & new_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:21551
void front_type
Definition: sol.hpp:498
static int real_set_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17774
basic_protected_function(lua_State *L, T &&r)
Definition: sol.hpp:15291
table create(int narr=0, int nrec=0)
Definition: sol.hpp:20520
void handle_filter(P &&p, lua_State *L, int &pushed)
Definition: sol.hpp:13082
static bool is_null(const actual_type &p)
Definition: sol.hpp:4784
const_iterator cbegin() const
Definition: sol.hpp:21461
static table create_with(lua_State *L, Args &&... args)
Definition: sol.hpp:20514
decltype(auto) overload(Args &&... args)
Definition: sol.hpp:8890
const Char * end() const
Definition: sol.hpp:1094
protected_handler(std::false_type, const target_t &target)
Definition: sol.hpp:15065
int type_panic_c_str(lua_State *L, int index, type expected, type actual, const char *message=nullptr) noexcept(false)
Definition: sol.hpp:6343
int call_into_lua(types< Ret0, Ret... >, types< Args... > ta, lua_State *L, int start, Fx &&fx, FxArgs &&... fxargs)
Definition: sol.hpp:11855
const_reverse_iterator rend() const
Definition: sol.hpp:12352
std::conditional_t< std::is_void< T >::value, R(*)(Args...), R(*)(first_type, Args...)> free_function_pointer_type
Definition: sol.hpp:576
basic_table_core & set_function(Key &&key, Args &&... args)
Definition: sol.hpp:20462
optional & operator=(optional &&rhs) noexcept(::std::is_nothrow_move_assignable< T >::value &&::std::is_nothrow_move_constructible< T >::value)
Definition: sol.hpp:3755
static bool check(lua_State *, int, Handler &&, record &tracking)
Definition: sol.hpp:8339
meta::boolean< has_traits_ipairs_test< T >::value > has_traits_ipairs
Definition: sol.hpp:16607
var_wrapper(Args &&... args)
Definition: sol.hpp:13008
callable_binding(Arg &&arg)
Definition: sol.hpp:18418
int operator()(lua_State *L, int index, type expected, type actual) const noexcept(false)
Definition: sol.hpp:6353
static int add(lua_State *L)
Definition: sol.hpp:16724
Definition: sol.hpp:6602
std::conditional_t< is_const, const proxy_t *, proxy_t * > pointer
Definition: sol.hpp:11977
Definition: sol.hpp:385
static int call(lua_State *L)
Definition: sol.hpp:14083
constexpr T const & operator*() const
Definition: sol.hpp:3876
void set_field(lua_State *L, Key &&key, Value &&value)
Definition: sol.hpp:8109
basic_object(stack_reference &&r) noexcept
Definition: sol.hpp:16173
Definition: sol.hpp:12174
static int get_call(lua_State *L)
Definition: sol.hpp:17962
std::shared_ptr< X > rebind_base
Definition: sol.hpp:4762
std::size_t size() const
Definition: sol.hpp:16092
auto setup_table(std::true_type)
Definition: sol.hpp:15515
std::array< luaL_Reg, sizeof...(Tn)/2+1+31 > regs_t
Definition: sol.hpp:18735
basic_object & operator=(proxy_base< Super > &&r)
Definition: sol.hpp:16223
tuple_types< R > returns_list
Definition: sol.hpp:572
int call_set_assignable(std::true_type, lua_State *L, T &&mem)
Definition: sol.hpp:13787
void insert(N &&n, object &&o)
Definition: sol.hpp:19358
std::conditional_t< std::is_void< T >::value, R(Args...), R(first_type, Args...)> free_function_type
Definition: sol.hpp:575
const_iterator begin() const
Definition: sol.hpp:16022
load_result(lua_State *Ls, int stackindex=-1, int retnum=0, int popnum=0, load_status lerr=load_status::ok) noexcept
Definition: sol.hpp:20826
unsafe_function_result script(const string_view &code, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21422
const_iterator cend() const
Definition: sol.hpp:20225
Definition: sol.hpp:4566
Definition: sol.hpp:22112
void ensure_package(const std::string &key, T &&sr)
Definition: sol.hpp:21076
simple_usertype_metatable(lua_State *L, detail::add_destructor_tag, Args &&... args)
Definition: sol.hpp:19507
basic_protected_function< main_reference, false, reference > main_safe_function
Definition: sol.hpp:309
void * align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space, std::size_t &required_space)
Definition: sol.hpp:7166
int stack_index() const
Definition: sol.hpp:12148
void make_destructor(Regs &l, int &index)
Definition: sol.hpp:18272
lua_State * L
Definition: sol.hpp:20784
#define SOL_DEPRECATED
Definition: sol.hpp:15745
static int push(lua_State *L, const property_wrapper< F, G > &pw)
Definition: sol.hpp:14749
static int convert_into(lua_State *L, char *start, std::size_t, const char16_t *strb, const char16_t *stre)
Definition: sol.hpp:11026
basic_object(lua_State *L, ref_index index) noexcept
Definition: sol.hpp:16196
decltype(auto) property(F &&f, G &&g)
Definition: sol.hpp:12960
encoded_result< char > code_point_to_utf8(char32_t codepoint)
Definition: sol.hpp:9004
stack_proxy reference_type
Definition: sol.hpp:15975
static int push(lua_State *L, destructor_wrapper< Fx > &&c)
Definition: sol.hpp:14896
bool operator==(const basic_table_iterator &right) const
Definition: sol.hpp:19963
const_reverse_iterator crend() const
Definition: sol.hpp:12499
const_iterator cbegin() const
Definition: sol.hpp:12477
T func
Definition: sol.hpp:4710
basic_object_base< base_type > base_t
Definition: sol.hpp:20016
static constexpr char32_t decode(unsigned char b0, unsigned char b1)
Definition: sol.hpp:8979
Definition: sol.hpp:11770
std::tuple< Arg > args_tuple
Definition: sol.hpp:1015
basic_object(lua_State *L, lua_nil_t r) noexcept
Definition: sol.hpp:16184
int usertype_alloc_destruct(lua_State *L)
Definition: sol.hpp:7537
protected_function_result script(const string_view &code, const basic_environment< E > &env, Fx &&on_error, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21396
void(* base_walk)(lua_State *, bool &, int &, string_view &)
Definition: sol.hpp:18389
proxy(Table table, T &&k)
Definition: sol.hpp:15533
int operator()(types< Fx >, index_value< I >, types< R... > r, types< Args... > a, lua_State *L, int, int start) const
Definition: sol.hpp:13123
Definition: sol.hpp:7642
Definition: sol.hpp:5616
std::remove_pointer_t< lua_CFunction > lua_CFunction_ref
Definition: sol.hpp:4732
static int push(lua_State *L, const T &value)
Definition: sol.hpp:10489
static int empty_call(lua_State *L)
Definition: sol.hpp:17934
std::array< char, 2 > two
Definition: sol.hpp:16307
static int index_get(lua_State *L)
Definition: sol.hpp:16712
table create_named(Name &&name, Args &&... args)
Definition: sol.hpp:20549
basic_string_view(const Char *ptr)
Definition: sol.hpp:1072
Definition: sol.hpp:1349
stack_proxy * pointer
Definition: sol.hpp:12264
static int push(lua_State *L, no_metatable_t, user< T > &&u)
Definition: sol.hpp:10839
static int real_call(lua_State *L) noexcept(traits_type::is_noexcept)
Definition: sol.hpp:13930
encoded_result< char32_t > code_point_to_utf32(char32_t codepoint)
Definition: sol.hpp:9060
meta::tuple_types< return_type > returns_list
Definition: sol.hpp:1018
Definition: sol.hpp:12609
optional & operator=(nullopt_t) noexcept
Definition: sol.hpp:3740
std::unique_ptr< usertype_detail::registrar > metatableregister
Definition: sol.hpp:19810
constructor_list< L0, Lists... > cl_t
Definition: sol.hpp:14838
types< Args... > type
Definition: sol.hpp:505
table create_named_table(Name &&name, Args &&... args)
Definition: sol.hpp:21651
basic_reference(lua_State *L, basic_reference< r_main_only > &&r) noexcept
Definition: sol.hpp:6825
int SOL_INTERNAL_UNSPECIALIZED_MARKER_
Definition: sol.hpp:5633
R return_type
Definition: sol.hpp:571
lua_State * lua_state() const
Definition: sol.hpp:21126
decltype(auto) base_class_check_key()
Definition: sol.hpp:6214
auto filters(F &&f, Args &&... args)
Definition: sol.hpp:4613
call_status
Definition: sol.hpp:5144
virtual ~registrar()
Definition: sol.hpp:18532
void emplace(Args &&... args)
Definition: sol.hpp:3780
object callconstructfunc
Definition: sol.hpp:19344
static int real_length_call(lua_State *L)
Definition: sol.hpp:17842
Definition: sol.hpp:19340
lua_thread_state(lua_State *Ls)
Definition: sol.hpp:21695
decltype(auto) base_class_index_propogation_key()
Definition: sol.hpp:6224
stack_proxy operator[](difference_type index_offset) const
Definition: sol.hpp:16079
Definition: sol.hpp:1246
int unique_destruct(lua_State *L)
Definition: sol.hpp:7548
int simple_core_indexing_call(lua_State *L)
Definition: sol.hpp:19194
static bool check(types< U >, lua_State *L, int index, type indextype, Handler &&handler, record &tracking)
Definition: sol.hpp:8568
table create_table(Name &&name, int narr, int nrec, Key &&key, Value &&value, Args &&... args)
Definition: sol.hpp:21646
static int real_index_get_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17714
static constexpr bool is_trail_surrogate(char32_t u)
Definition: sol.hpp:8953
auto invoke(types< Ret... >, std::index_sequence< I... >, std::ptrdiff_t n, detail::protected_handler< b, handler_t > &h) const
Definition: sol.hpp:15151
Ret invoke(types< Ret >, std::index_sequence< I >, std::ptrdiff_t n)
Definition: sol.hpp:21919
auto var(V &&v)
Definition: sol.hpp:13018
basic_object(lua_State *L, T &&r)
Definition: sol.hpp:16162
overload_set(Arg &&arg, Args &&... args)
Definition: sol.hpp:8880
protected_function_result safe_script_file(const std::string &filename, const basic_environment< E > &env, load_mode mode=load_mode::any)
Definition: sol.hpp:21329
virtual int new_index(lua_State *L) override
Definition: sol.hpp:18426
bool init_
Definition: sol.hpp:3570
static int real_new_index_call(lua_State *L)
Definition: sol.hpp:18950
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8701
int return_count() const noexcept
Definition: sol.hpp:12368
static int call(lua_State *L)
Definition: sol.hpp:13983
optional(const optional &rhs)
Definition: sol.hpp:3694
unsafe_function_result script_file(const std::string &filename, load_mode mode=load_mode::any)
Definition: sol.hpp:21426
basic_object(proxy_base< Super > &&r) noexcept
Definition: sol.hpp:16181
protected_function_result script(const string_view &code, Fx &&on_error, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21386
Definition: sol.hpp:3943
T value
Definition: sol.hpp:12897
Definition: sol.hpp:266
static int push(lua_State *L, const wchar_t *strb, const wchar_t *stre)
Definition: sol.hpp:10991
lua_State * operator->() const noexcept
Definition: sol.hpp:5078
void operator()(lua_State *L) const
Definition: sol.hpp:4471
const env_t env_key
Definition: sol.hpp:4703
#define COMPAT53_API
Definition: sol.hpp:1967
basic_object(const proxy_base< Super > &r) noexcept
Definition: sol.hpp:16177
static int push(lua_State *L, const property_wrapper< void, F > &pw)
Definition: sol.hpp:14769
basic_protected_function< stack_reference, false, reference > stack_safe_function
Definition: sol.hpp:311
protected_handler(std::true_type, const target_t &target)
Definition: sol.hpp:15073
stack_iterator< stack_proxy, true > const_iterator
Definition: sol.hpp:12268
static int push(lua_State *L, const property_wrapper< F, void > &pw)
Definition: sol.hpp:14759
T type
Definition: sol.hpp:1228
lua_CFunction newindexbase
Definition: sol.hpp:19348
const nil_t nil
Definition: sol.hpp:4692
Definition: sol.hpp:7036
protected_function_result operator()(Args &&... args)
Definition: sol.hpp:22082
std::integral_constant< std::size_t, I > index_value
Definition: sol.hpp:1205
constexpr optional(T &v) noexcept
Definition: sol.hpp:3958
main_safe_function main_protected_function
Definition: sol.hpp:315
static int real_meta_call(lua_State *L, void *um, int)
Definition: sol.hpp:18893
stack_iterator< stack_proxy, true > const_iterator
Definition: sol.hpp:15981
basic_lightuserdata(lua_State *L, T &&r)
Definition: sol.hpp:15907
Definition: sol.hpp:19988
lua_State * L
Definition: sol.hpp:19989
static int push(lua_State *L, const std::basic_string< char, Traits, Al > &str)
Definition: sol.hpp:10926
std::array< char, 2 > sfinae_no_t
Definition: sol.hpp:1209
constexpr T * operator->() const
Definition: sol.hpp:4018
as_table_t(Arg0 &&arg0, Arg1 &&arg1, Args &&... args)
Definition: sol.hpp:4995
Definition: sol.hpp:7600
hash< T >::result_type result_type
Definition: sol.hpp:4356
state_view state() const
Definition: sol.hpp:21807
const_reverse_iterator crbegin() const
Definition: sol.hpp:12355
T value
Definition: sol.hpp:13006
int operator()(types< Fx >, index_value< I >, types< R >, types< Args... >, lua_State *L, int, int) const
Definition: sol.hpp:13839
static T & get(lua_State *L, int index, record &tracking)
Definition: sol.hpp:9977
constexpr U convert(U v)
Definition: sol.hpp:3483
static int push(std::false_type, std::integral_constant< bool, is_nested >, lua_State *L, const T &tablecont)
Definition: sol.hpp:10575
std::array< int, 64 > stack_indices
Definition: sol.hpp:4571
bool is_indeterminate_call_failure(call_status c)
Definition: sol.hpp:5226
static int push(lua_State *L, const char *str)
Definition: sol.hpp:10861
int(*)(lua_State *, optional< const std::exception & >, string_view) exception_handler_function
Definition: sol.hpp:5831
std::array< char, 1 > one
Definition: sol.hpp:16336
static int push(lua_State *L, const T &value)
Definition: sol.hpp:10497
iterator const_iterator
Definition: sol.hpp:20153
static int push(lua_State *L, T &&t)
Definition: sol.hpp:11268
static int push(lua_State *L, std::function< Signature > &&fx)
Definition: sol.hpp:14680
state_view & traverse_set(Args &&... args)
Definition: sol.hpp:21534
Definition: sol.hpp:4702
std::conditional_t< std::is_void< T >::value, int, T > & first_type
Definition: sol.hpp:560
basic_table_iterator< base_type > iterator
Definition: sol.hpp:20152
int push(lua_State *L, const variadic_results &e)
Definition: sol.hpp:22147
constexpr T & value_or(V &&v) const
Definition: sol.hpp:4040
int push() const noexcept
Definition: sol.hpp:6937
~protected_handler()
Definition: sol.hpp:15088
int & n
Definition: sol.hpp:19999
stack_reference(lua_State *L, const stack_reference &r) noexcept
Definition: sol.hpp:6473
static bool is_null(U &&)
Definition: sol.hpp:4744
reference handler_t
Definition: sol.hpp:21897
~push_popper()
Definition: sol.hpp:6649
Definition: sol.hpp:375
static int push(lua_State *L, no_metatable_t, Args &&... args)
Definition: sol.hpp:10813
Definition: sol.hpp:5670
static std::function< Signature > get_std_func(types< Ret... >, types< Args... >, lua_State *L, int index)
Definition: sol.hpp:15461
main_table_core< true > main_global_table
Definition: sol.hpp:294
static int real_get_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17762
static const std::string & metatable()
Definition: sol.hpp:6173
bool valid() const noexcept
Definition: sol.hpp:12507
constexpr bool initialized() const noexcept
Definition: sol.hpp:3627
basic_table_core & new_usertype(const std::string &name, constructors< CArgs... > ctor, Args &&... args)
Definition: sol.hpp:20345
probe apply(std::index_sequence< I >, int sofar, lua_State *L, Keys &&keys, int tableindex)
Definition: sol.hpp:11679
const void * pointer() const noexcept
Definition: sol.hpp:6969
void swap(optional< T > &x, optional< T > &y) noexcept(noexcept(x.swap(y)))
Definition: sol.hpp:4327
Definition: sol.hpp:7157
Definition: sol.hpp:5398
const_reverse_iterator rend() const
Definition: sol.hpp:12493
typename bind_traits< Signature >::signature_type function_signature_t
Definition: sol.hpp:1035
Definition: sol.hpp:5759
static int push(lua_State *L, lua_CFunction func, int n=0)
Definition: sol.hpp:10700
static int push(lua_State *L, T &&c)
Definition: sol.hpp:10749
static std::function< Signature > get_std_func(types<>, types< FxArgs... > t, lua_State *L, int index)
Definition: sol.hpp:15479
constexpr struct sol::trivial_init_t trivial_init
Definition: sol.hpp:3501
Definition: sol.hpp:5637
static int real_find_call(lua_State *L)
Definition: sol.hpp:17914
T src
Definition: sol.hpp:15941
void tuple_set(std::index_sequence< I... >, T &&value)
Definition: sol.hpp:15511
error_code
Definition: sol.hpp:8903
basic_thread(stack_reference &&r)
Definition: sol.hpp:21762
int index
Definition: sol.hpp:12215
variadic_args(variadic_args &&o)
Definition: sol.hpp:15994
Ret invoke(types< Ret >, std::index_sequence< I >, std::ptrdiff_t n) const
Definition: sol.hpp:14953
int operator()(lua_State *L)
Definition: sol.hpp:14237
static int push(lua_State *L, const variadic_args &ref)
Definition: sol.hpp:16111
std::size_t size() const
Definition: sol.hpp:1110
const_iterator cend() const
Definition: sol.hpp:21465
basic_protected_function(lua_State *L, T &&r, handler_t eh)
Definition: sol.hpp:15295
basic_coroutine(basic_function< base_t > &&b, handler_t eh)
Definition: sol.hpp:21974
basic_protected_function(lua_State *L, ref_index index)
Definition: sol.hpp:15338
T type
Definition: sol.hpp:1212
basic_coroutine(const basic_function< base_t > &b)
Definition: sol.hpp:21965
int call_indexing_object(lua_State *L, object &f)
Definition: sol.hpp:19182
bool is_main_thread() const
Definition: sol.hpp:21811
Definition: sol.hpp:4492
constexpr const T & contained_val() const
Definition: sol.hpp:3657
static int push(std::true_type, std::integral_constant< bool, is_nested >, lua_State *L, const T &tablecont)
Definition: sol.hpp:10559
basic_object_base< base_type > base_t
Definition: sol.hpp:16145
std::tuple< std::add_lvalue_reference_t< Tn >... > base_t
Definition: sol.hpp:7044
void add_member_function(std::true_type, lua_State *L, N &&n, F &&f)
Definition: sol.hpp:19390
int call_wrapper_variable(std::true_type, lua_State *L)
Definition: sol.hpp:13803
stack_iterator()
Definition: sol.hpp:11986
void apply(std::index_sequence< 0, I... >, lua_State *L, Keys &&keys, int tableindex)
Definition: sol.hpp:11487
typename unqualified< T >::type unqualified_t
Definition: sol.hpp:485
static int real_add_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17850
simple_usertype< Class > create_simple_usertype(Args &&... args)
Definition: sol.hpp:20378
static int push_deep(lua_State *L, Args &&... args)
Definition: sol.hpp:10454
meta::boolean< has_erase_after_test< T >::value > has_erase_after
Definition: sol.hpp:16586
basic_table_core & traverse_set(Keys &&... keys)
Definition: sol.hpp:20262
static auto call(Fx &&fx, object_type &mem) -> detail::array_return_type< decltype(mem.*fx)>
Definition: sol.hpp:12681
basic_function< reference, false > unsafe_function
Definition: sol.hpp:306
table_core< false > table
Definition: sol.hpp:291
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8637
static int push(lua_State *L, factory_wrapper< Functions... > &&set, function_detail::call_indicator)
Definition: sol.hpp:14804
auto tuple_get(types< Ret0, Ret1, Ret... >, std::index_sequence< 0, 1, I... >, Keys &&keys) const -> decltype(stack::pop< std::tuple< Ret0, Ret1, Ret... >>(nullptr))
Definition: sol.hpp:20049
call_status err
Definition: sol.hpp:12218
basic_function(stack_reference &&r)
Definition: sol.hpp:14994
void raw_set_field(lua_State *L, Key &&key, Value &&value, int tableindex)
Definition: sol.hpp:8124
type get_type() const
Definition: sol.hpp:15637
const_reverse_iterator rend() const
Definition: sol.hpp:16044
std::tuple< Functions... > functions
Definition: sol.hpp:4521
basic_table_core & new_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:20339
static int push(lua_State *L, void *userdata)
Definition: sol.hpp:10756
struct sol::detail::verified_tag verified
static int push(lua_State *L, as_container_t< T > &&as_cont)
Definition: sol.hpp:18052
static int push(lua_State *L, const unsafe_function_result &fr)
Definition: sol.hpp:12533
Definition: sol.hpp:3405
push_popper_n(lua_State *luastate, int x)
Definition: sol.hpp:6618
iterator end()
Definition: sol.hpp:12468
const char * fmt_
Definition: sol.hpp:16674
int push(lua_State *Ls) const
Definition: sol.hpp:12140
Definition: sol.hpp:5729
static int push(lua_State *L, const char32_t *u32str, std::size_t sz)
Definition: sol.hpp:11130
int push(lua_State *Ls) const noexcept
Definition: sol.hpp:6941
as_table_t< T > as_table_ref(T &&container)
Definition: sol.hpp:5028
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8562
upvalue_index(int idx)
Definition: sol.hpp:4801
std::string type_name(lua_State *L, type t)
Definition: sol.hpp:5362
basic_object(lua_State *L, raw_index index) noexcept
Definition: sol.hpp:16193
const std::string & default_chunk_name()
Definition: sol.hpp:11710
const std::array< std::string, 32 > & meta_function_names()
Definition: sol.hpp:5316
load_result load_file(const std::string &filename, load_mode mode=load_mode::any)
Definition: sol.hpp:21441
decltype(meta_detail::supports_op_less_equal_test(std::declval< T & >(), std::declval< U & >())) supports_op_less_equal
Definition: sol.hpp:1682
basic_reference(const basic_reference &o) noexcept
Definition: sol.hpp:6882
basic_object< stack_reference > stack_object
Definition: sol.hpp:359
Read read
Definition: sol.hpp:12931
auto make_light(T &l)
Definition: sol.hpp:4893
constexpr const T & storage() const
Definition: sol.hpp:3605
const lua_Integer toplevel_magic
Definition: sol.hpp:18467
Definition: sol.hpp:1272
std::enable_if_t< neg< any< Args... >>::value, enable_t > disable_any
Definition: sol.hpp:1329
proxy< const global_table &, T > operator[](T &&key) const
Definition: sol.hpp:21624
std::size_t size() const
Definition: sol.hpp:4589
absolute_index(lua_State *L, int idx)
Definition: sol.hpp:4823
static int push(lua_State *L, var_wrapper< T > &&vw)
Definition: sol.hpp:14776
optional & operator=(const optional &rhs)
Definition: sol.hpp:3745
const_reverse_iterator crend() const
Definition: sol.hpp:12358
decltype(auto) get(lua_State *L, int index, record &tracking)
Definition: sol.hpp:8053
void set_default_exception_handler(lua_State *L, exception_handler_function exf=&detail::default_exception_handler)
Definition: sol.hpp:5998
const_reverse_iterator rbegin() const
Definition: sol.hpp:12349
int stack_top() const
Definition: sol.hpp:21481
std::array< char, 1 > one
Definition: sol.hpp:16381
Definition: sol.hpp:6235
Definition: sol.hpp:3389
lua_CFunction indexbase
Definition: sol.hpp:19347
std::array< char, 1 > one
Definition: sol.hpp:16396
std::array< char, 1 > one
Definition: sol.hpp:16306
static int push(lua_State *L, const yielding_t< T > &f, Args &&... args)
Definition: sol.hpp:14644
bad_optional_access(const ::std::string &what_arg)
Definition: sol.hpp:3503
const_reverse_iterator crend() const
Definition: sol.hpp:16050
basic_lightuserdata(stack_reference &&r)
Definition: sol.hpp:15903
static int convert_into(lua_State *L, char *start, std::size_t, const char32_t *strb, const char32_t *stre)
Definition: sol.hpp:11106
stack_proxy get(types< Args... > t, const protected_function_result &fr)
Definition: sol.hpp:12588
static int push(lua_State *L, const basic_string_view< Ch, Traits > &sv)
Definition: sol.hpp:10939
constexpr T & value() const
Definition: sol.hpp:4026
std::tuple< Ps... > arguments
Definition: sol.hpp:4964
Definition: sol.hpp:10982
static int push(lua_State *L, const char *str)
Definition: sol.hpp:10884
static int push(lua_State *L, const wchar_t *str, std::size_t len)
Definition: sol.hpp:11017
std::array< char, 1 > one
Definition: sol.hpp:16426
static int push(lua_State *L, const char16_t *strb, const char16_t *stre)
Definition: sol.hpp:11055
static int push(lua_State *L, std::nullptr_t)
Definition: sol.hpp:11295
virtual ~variable_wrapper()
Definition: sol.hpp:18410
simple_map(const char *mkey, base_walk index, base_walk newindex, object i, object ni, variable_map &&vars, function_map &&funcs)
Definition: sol.hpp:18443
Definition: sol.hpp:475
static int find(lua_State *L)
Definition: sol.hpp:16732
meta::boolean< meta_detail::has_to_string_test< T >::value > supports_to_string_member
Definition: sol.hpp:1689
static const char * get(lua_State *L, int index, record &tracking)
Definition: sol.hpp:9625
Definition: sol.hpp:4482
Definition: sol.hpp:7619
member_search index
Definition: sol.hpp:18393
static S get_into(lua_State *L, int index, record &tracking)
Definition: sol.hpp:9737
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8285
void rebind_base
Definition: sol.hpp:4739
meta::boolean< has_traits_erase_test< T >::value > has_traits_erase
Definition: sol.hpp:16631
static const std::string & user_metatable()
Definition: sol.hpp:6177
static int push(lua_State *L, F &&f, Args &&... args)
Definition: sol.hpp:14688
void set_fx(types<>, Key &&key, Fx &&fx, Args &&... args)
Definition: sol.hpp:20487
static int push(lua_State *L, Arg0 &&arg0, Arg0 &&arg1, Args &&... args)
Definition: sol.hpp:10449
std::size_t total_memory_used(lua_State *L)
Definition: sol.hpp:20973
void apply(std::index_sequence< I >, lua_State *L, Key &&keys, Value &&value, int tableindex)
Definition: sol.hpp:11608
usertype(detail::add_destructor_tag, Args &&... args)
Definition: sol.hpp:19819
void set_fx(types<>, Key &&key, Fx &&fx)
Definition: sol.hpp:20482
O object_type
Definition: sol.hpp:12708
std::ptrdiff_t difference_type
Definition: sol.hpp:19902
int index
Definition: sol.hpp:4833
std::size_t size_type
Definition: sol.hpp:15979
static int push(lua_State *L, const std::function< Signature > &fx)
Definition: sol.hpp:14676
function_type invocation
Definition: sol.hpp:14175
std::size_t size_type
Definition: sol.hpp:12417
static int real_index_call(lua_State *L)
Definition: sol.hpp:17718
int default_to_string(lua_State *L)
Definition: sol.hpp:18173
std::array< char, 1 > one
Definition: sol.hpp:16321
basic_environment(lua_State *L, T &&r) noexcept
Definition: sol.hpp:20660
std::integral_constant< bool, !std::is_void< W >::value > can_write
Definition: sol.hpp:12928
basic_table_core(detail::no_safety_tag, lua_State *L, int index)
Definition: sol.hpp:20136
static constexpr bool has_overload(...)
Definition: sol.hpp:3459
static void select_convertible(std::true_type, types< R(A...)>, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14449
stack_proxy reference_type
Definition: sol.hpp:12413
protected_function_result script(const string_view &code, const environment &env, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21405
safe_function protected_function
Definition: sol.hpp:314
typename clean_type< T >::type clean_type_t
Definition: sol.hpp:18726
Definition: sol.hpp:4797
bool multi_check(lua_State *L, int index)
Definition: sol.hpp:8022
lua_State * L
Definition: sol.hpp:6616
unique_usertype_traits< T >::actual_type Real
Definition: sol.hpp:10008
simple_usertype< Class > create_simple_usertype(Args &&... args)
Definition: sol.hpp:21587
T & item
Definition: sol.hpp:4660
proxy< basic_table_core, T > operator[](T &&key) &&
Definition: sol.hpp:20451
global_table globals() const
Definition: sol.hpp:21469
void use(int count)
Definition: sol.hpp:7649
void set_exception_handler(exception_handler_function handler)
Definition: sol.hpp:21503
const_iterator begin() const
Definition: sol.hpp:12471
std::reverse_iterator< iterator > reverse_iterator
Definition: sol.hpp:12269
Definition: sol.hpp:6352
int registry_index() const noexcept
Definition: sol.hpp:6961
error_result(int results)
Definition: sol.hpp:16680
decltype(auto) readonly_property(F &&f)
Definition: sol.hpp:12973
state_view & new_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:21557
#define TR2_OPTIONAL_REQUIRES(...)
Definition: sol.hpp:3269
basic_environment< E > get_environment(const T &target)
Definition: sol.hpp:20696
#define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR)
Definition: sol.hpp:3450
std::index_sequence< I... > half_indices
Definition: sol.hpp:18734
static int convertible_call(std::true_type, lua_State *L, Fx &&f, Args &&... args)
Definition: sol.hpp:13241
Definition: sol.hpp:1728
basic_protected_function(proxy_base< Super > &&p)
Definition: sol.hpp:15282
std::array< char, 2 > two
Definition: sol.hpp:16502
usertype(detail::check_destructor_tag, Args &&... args)
Definition: sol.hpp:19824
T * ref
Definition: sol.hpp:3944
basic_coroutine(lua_State *L, absolute_index index)
Definition: sol.hpp:22031
int operator()(lua_State *L)
Definition: sol.hpp:13953
static int push(lua_State *L, const basic_string_view< Ch, Traits > &sv, std::size_t n)
Definition: sol.hpp:10943
Definition: sol.hpp:8924
basic_object(lua_State *L, in_place_type_t< T >, Args &&... args) noexcept
Definition: sol.hpp:16200
meta::tuple_types< R > returns_list
Definition: sol.hpp:12712
std::array< char, 2 > two
Definition: sol.hpp:16367
basic_thread(lua_State *L, lua_State *actualthread)
Definition: sol.hpp:21790
decltype(meta_detail::supports_adl_to_string(std::declval< T & >())) supports_adl_to_string
Definition: sol.hpp:1686
light(L &x)
Definition: sol.hpp:4875
std::string demangle_once()
Definition: sol.hpp:6102
meta::all< meta::neg< std::is_pointer< T > >, std::is_destructible< T > > is_destructible
Definition: sol.hpp:18335
stack_proxy_base(lua_State *L, int index)
Definition: sol.hpp:12113
int handle_errors(lua_State *L, const error_result &er)
Definition: sol.hpp:16688
basic_coroutine(lua_State *L, absolute_index index, handler_t eh)
Definition: sol.hpp:22034
bool operator!=(const stack_iterator &r) const
Definition: sol.hpp:12070
int static_trampoline_noexcept(lua_State *L) noexcept
Definition: sol.hpp:5940
std::array< char, 1 > one
Definition: sol.hpp:16516
stack_iterator & operator++()
Definition: sol.hpp:12014
Definition: sol.hpp:21055
struct sol::detail::global_tag global_
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8487
protected_function_result(lua_State *Ls, int idx=-1, int retnum=0, int popped=0, call_status pferr=call_status::ok) noexcept
Definition: sol.hpp:12273
push_popper_at push_pop_at(T &&x)
Definition: sol.hpp:6665
T * ptr(T &val)
Definition: sol.hpp:1862
auto factories(Functions &&... functions)
Definition: sol.hpp:4529
std::array< char, 2 > two
Definition: sol.hpp:16397
decltype(auto) as() const
Definition: sol.hpp:15808
meta::bind_traits< function_type >::return_type return_type
Definition: sol.hpp:14202
reference operator*()
Definition: sol.hpp:19955
const int simple_metatable_index
Definition: sol.hpp:18385
static int real_insert_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17858
Definition: sol.hpp:5047
bool is_main_thread(lua_State *L)
Definition: sol.hpp:7747
int used
Definition: sol.hpp:7644
basic_table< base_type > base_t
Definition: sol.hpp:20583
Definition: sol.hpp:7116
decoded_result< It > utf8_to_code_point(It it, It last)
Definition: sol.hpp:9069
Definition: sol.hpp:387
static constexpr bool has_overload(bool)
Definition: sol.hpp:3464
basic_userdata(lua_State *L, ref_index index)
Definition: sol.hpp:15868
static bool check(lua_State *L, int index, Handler &&, record &tracking)
Definition: sol.hpp:8717
protected_function_result do_file(const std::string &filename, const basic_environment< E > &env, load_mode mode=load_mode::any)
Definition: sol.hpp:21253
table create_table(int narr, int nrec, Key &&key, Value &&value, Args &&... args)
Definition: sol.hpp:21662
protected_function_result script_file(const std::string &filename, Fx &&on_error, load_mode mode=load_mode::any)
Definition: sol.hpp:21391
stack_reference(lua_State *L, int i) noexcept
Definition: sol.hpp:6462
int index
Definition: sol.hpp:6604
bool operator==(const basic_string_view &r) const
Definition: sol.hpp:1122
Definition: sol.hpp:4963
static bool contains_variable()
Definition: sol.hpp:18763
static int insert_call(lua_State *L)
Definition: sol.hpp:17926
decltype(&inheritance< void >::type_check) inheritance_check_function
Definition: sol.hpp:6299
stack_iterator< stack_proxy, false > iterator
Definition: sol.hpp:12418
decltype(auto) unqualified_check_get(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:7888
std::tuple< decltype(stack::get< Tn >nullptr, 0))... > R
Definition: sol.hpp:10021
basic_table_core & set_function(Key &&key, Args &&... args)
Definition: sol.hpp:20456
bool multi_check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:7995
static int push_fx(lua_State *L, F &&f, Args &&... args)
Definition: sol.hpp:10361
optional< environment > env
Definition: sol.hpp:20703
void add(lua_State *, base_classes_tag, bases< Bases... >)
Definition: sol.hpp:19474
protected_function_result(protected_function_result &&o) noexcept
Definition: sol.hpp:12278
protected_function_result do_string(const string_view &code, const basic_environment< E > &env, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21240
optional_base(T &&v)
Definition: sol.hpp:3524
static int push(lua_State *L, char32_t c)
Definition: sol.hpp:11233
lua_bind_traits< meta::unqualified_t< F > > traits_type
Definition: sol.hpp:12663
static int push(lua_State *L, const wchar_t *strb, const wchar_t *stre)
Definition: sol.hpp:11011
lua_State * lua_state() const
Definition: sol.hpp:12511
static int real_at_call(lua_State *L)
Definition: sol.hpp:17758
basic_reference(lua_State *L, const basic_reference< r_main_only > &r) noexcept
Definition: sol.hpp:6806
Definition: sol.hpp:4696
int operator()(lua_State *L, int index, type expected, type actual, const std::string &message) const noexcept(false)
Definition: sol.hpp:6367
basic_table_core(T &&r) noexcept
Definition: sol.hpp:20199
void set_environment(const basic_environment< E > &env, const T &target)
Definition: sol.hpp:20691
neg< is_move_only< T >> is_not_move_only
Definition: sol.hpp:1776
base_walk newindexbaseclasspropogation
Definition: sol.hpp:18441
static int push(lua_State *L, umt_t &&umx)
Definition: sol.hpp:19578
proxy & operator=(std::initializer_list< T > other)
Definition: sol.hpp:15560
basic_reference(lua_nil_t) noexcept
Definition: sol.hpp:6796
static int real_add_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17846
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: sol.hpp:12421
Definition: sol.hpp:7627
static int push(lua_State *L, T &&ref)
Definition: sol.hpp:10662
void make_regs(regs_t &l, int &index, N &&n, F &&)
Definition: sol.hpp:18808
stack_iterator & operator--()
Definition: sol.hpp:12025
lua_State * L
Definition: sol.hpp:5048
basic_protected_function(Proxy &&p, Handler &&eh)
Definition: sol.hpp:15286
static bool check(lua_State *, int, Handler &&, record &tracking)
Definition: sol.hpp:8375
int stack_index() const
Definition: sol.hpp:16086
meta::boolean< meta_detail::has_max_size_test< T >::value > has_max_size
Definition: sol.hpp:1716
result_type operator()(const argument_type &r) const
Definition: sol.hpp:1157
std::array< char, 2 > two
Definition: sol.hpp:16517
unqualified< tuple_element_t< N, Tuple >> unqualified_tuple_element
Definition: sol.hpp:515
ref_clean(lua_State *luastate, int &n)
Definition: sol.hpp:20000
in_place_tag(&)(detail::in_place_of_i< I >) in_place_index_t
Definition: sol.hpp:3251
int index
Definition: sol.hpp:15971
constexpr optional() noexcept
Definition: sol.hpp:3950
static int push(lua_State *L, const char16_t(&str)[N], std::size_t sz)
Definition: sol.hpp:11199
std::array< char, 2 > two
Definition: sol.hpp:16457
yielding_t< std::decay_t< F > > yielding(F &&f)
Definition: sol.hpp:4728
F value
Definition: sol.hpp:4598
void coroutine_create_guard(lua_State *L)
Definition: sol.hpp:7753
constexpr bool operator==(const optional< T > &x, const optional< T > &y)
Definition: sol.hpp:4052
optional & operator=(nullopt_t) noexcept
Definition: sol.hpp:3977
static table create_table(lua_State *L, int narr, int nrec, Key &&key, Value &&value, Args &&... args)
Definition: sol.hpp:21676
std::size_t result_type
Definition: sol.hpp:1150
void handle_filter(static_stack_dependencies< I, In... >, lua_State *L, int &)
Definition: sol.hpp:13042
stack_count(int cnt)
Definition: sol.hpp:4846
constructor_match(T *o)
Definition: sol.hpp:13118
const unchecked_t unchecked
Definition: sol.hpp:4676
static int push(lua_State *L, const destructor_wrapper< Fx > &c)
Definition: sol.hpp:14885
reverse_iterator rbegin()
Definition: sol.hpp:12484
static int push(lua_State *L, const std::basic_string< char, Traits, Al > &str, std::size_t sz)
Definition: sol.hpp:10931
static bool check(lua_State *L, int index, type indextype, Handler &&handler, record &tracking)
Definition: sol.hpp:8619
static int push(lua_State *L, const wchar_t *wstr)
Definition: sol.hpp:10983
basic_table_core & traverse_raw_set(Keys &&... keys)
Definition: sol.hpp:20308
bool valid() const noexcept
Definition: sol.hpp:15084
traits_type::args_list free_args_list
Definition: sol.hpp:12612
filter_wrapper(Fx &&fx, Args &&... args)
Definition: sol.hpp:4602
OPTIONAL_CONSTEXPR_INIT_LIST constexpr_optional_base(in_place_t, ::std::initializer_list< U > il, Args &&... args)
Definition: sol.hpp:3592
static int push(lua_State *L, yielding_t< T > &&f, Args &&... args)
Definition: sol.hpp:14651
object make_object(lua_State *L, T &&value)
Definition: sol.hpp:16230
types< Args... > type
Definition: sol.hpp:499
push_popper_n< top_level > pop_n(lua_State *L, int x)
Definition: sol.hpp:6671
iterator end()
Definition: sol.hpp:12327
state(lua_CFunction panic=default_at_panic)
Definition: sol.hpp:21863
void * baseclasscast
Definition: sol.hpp:19352
static int size(lua_State *L)
Definition: sol.hpp:16736
Definition: sol.hpp:3212
int operator()(lua_State *L)
Definition: sol.hpp:13920
constexpr T * static_addressof(T &ref)
Definition: sol.hpp:3472
static int real_call(lua_State *L) noexcept(traits_type::is_noexcept)
Definition: sol.hpp:14041
Definition: sol.hpp:4678
light(void *x)
Definition: sol.hpp:4881
Definition: sol.hpp:5388
static int compare(const Char *lhs_p, std::size_t lhs_sz, const Char *rhs_p, std::size_t rhs_sz)
Definition: sol.hpp:1079
int top
Definition: sol.hpp:7118
lua_State * lua_state() const
Definition: sol.hpp:11962
static int push(lua_State *L, const user< T > &u)
Definition: sol.hpp:10824
basic_object(lua_State *L, int index=-1) noexcept
Definition: sol.hpp:16187
this_environment()
Definition: sol.hpp:20705
static int real_call(lua_State *L) noexcept(traits_type::is_noexcept)
Definition: sol.hpp:13904
std::conditional_t< std::is_array< R >::value, std::add_lvalue_reference_t< T >, R > return_type
Definition: sol.hpp:1007
iterator begin()
Definition: sol.hpp:16016
bool is_stack(std::true_type) const
Definition: sol.hpp:15781
decltype(auto) pop(lua_State *L)
Definition: sol.hpp:8064
int comparsion_operator_wrap(lua_State *L)
Definition: sol.hpp:18178
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8628
static int push(lua_State *L, T *cont)
Definition: sol.hpp:18061
implicit_wrapper(T *item)
Definition: sol.hpp:4661
std::tuple< Functions... > functions
Definition: sol.hpp:8878
auto meta_registry_key(T &&key)
Definition: sol.hpp:4932
usertype_metatable_core(lua_CFunction ifx, lua_CFunction nifx)
Definition: sol.hpp:18456
static void select_member_variable(std::true_type, lua_State *L, Fx &&fx, T &&obj, Args &&... args)
Definition: sol.hpp:14496
error_result()
Definition: sol.hpp:16677
static int push(lua_State *L, no_construction)
Definition: sol.hpp:14813
const char(& default_handler_name())[9]
Definition: sol.hpp:15054
int no_panic(lua_State *, int, type, type, const char *=nullptr) noexcept
Definition: sol.hpp:6402
static int push(lua_State *L, const proxy< Table, Key > &p)
Definition: sol.hpp:15723
constexpr constexpr_optional_base() noexcept
Definition: sol.hpp:3571
basic_string_view< wchar_t > wstring_view
Definition: sol.hpp:1187
static int push(lua_State *L, property_wrapper< F, void > &&pw)
Definition: sol.hpp:14756
int finish_regs(regs_t &l, int &index)
Definition: sol.hpp:18774
bool operator!=(const char *r) const
Definition: sol.hpp:1138
basic_protected_function(lua_State *L, absolute_index index)
Definition: sol.hpp:15318
basic_coroutine(const basic_function< base_t > &b, handler_t eh)
Definition: sol.hpp:21971
meta::any< is_destructor< meta::unqualified_t< Args >>... > has_destructor
Definition: sol.hpp:5809
optional_base(in_place_t, Args &&... args)
Definition: sol.hpp:3530
static void select_convertible(types< R(A...)> t, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14456
static R call(Fx &&fx, O &mem, Args &&... args)
Definition: sol.hpp:12720
static int push(lua_State *L, const T &value)
Definition: sol.hpp:10533
Definition: sol.hpp:11941
decltype(meta_detail::supports_ostream_op(std::declval< T & >(), std::declval< U & >())) supports_ostream_op
Definition: sol.hpp:1684
basic_table_core(detail::no_safety_tag, lua_State *L, ref_index index)
Definition: sol.hpp:20139
protected_function_result operator()(Args &&... args) const
Definition: sol.hpp:15351
std::array< char, 2 > two
Definition: sol.hpp:16322
proxy_t sp
Definition: sol.hpp:11984
Definition: sol.hpp:7625
basic_table_core(stack_reference &&r)
Definition: sol.hpp:20165
meta::boolean< has_traits_index_get_test< T >::value > has_traits_index_get
Definition: sol.hpp:16598
std::array< char, 1 > one
Definition: sol.hpp:16501
bad_optional_access(const char *what_arg)
Definition: sol.hpp:3506
Definition: sol.hpp:3214
Table tbl
Definition: sol.hpp:15529
T source
Definition: sol.hpp:5006
int push(lua_State *Ls) const noexcept
Definition: sol.hpp:6496
lua_bind_traits< function_type > traits_type
Definition: sol.hpp:14039
basic_protected_function(lua_State *L, absolute_index index, handler_t eh)
Definition: sol.hpp:15321
static int push(lua_State *L, factory_wrapper< Functions... > &&fw)
Definition: sol.hpp:14792
static int push(lua_State *L, user< T > &&u)
Definition: sol.hpp:10829
Definition: sol.hpp:4520
lua_State * lua_state() const noexcept
Definition: sol.hpp:5082
Definition: sol.hpp:12923
typename bind_traits< Signature >::args_list function_args_t
Definition: sol.hpp:1032
basic_function< base_t > force_cast(T &p)
Definition: sol.hpp:15096
std::is_void< decltype(test< F >(0))> type
Definition: sol.hpp:539
constexpr optional(nullopt_t) noexcept
Definition: sol.hpp:3954
int push(lua_State *L) const noexcept
Definition: sol.hpp:15633
static void select_member_variable(std::true_type, lua_State *L, Fx &&fx, function_detail::class_indicator< C >)
Definition: sol.hpp:14502
basic_table_core & new_simple_usertype(const std::string &name, Args &&... args)
Definition: sol.hpp:20352
meta::boolean< has_traits_next_test< T >::value > has_traits_next
Definition: sol.hpp:16610
basic_reference(lua_State *L, ref_index index) noexcept
Definition: sol.hpp:6867
::std::has_trivial_destructor< T > is_trivially_destructible
Definition: sol.hpp:3368
typename strip< T >::type strip_t
Definition: sol.hpp:7673
static bool check(types< Args... >, lua_State *, int, Handler &&, record &)
Definition: sol.hpp:7987
void for_each(std::false_type, Fx &&fx) const
Definition: sol.hpp:20037
R make_reference(lua_State *L, T &&value)
Definition: sol.hpp:16123
void * align_usertype_unique_tag(void *ptr)
Definition: sol.hpp:7238
basic_protected_function< stack_reference, true, reference > stack_aligned_safe_function
Definition: sol.hpp:313
Definition: sol.hpp:15968
void set_extra(std::false_type, std::index_sequence< I... >, T &&target)
Definition: sol.hpp:7068
int index
Definition: sol.hpp:12107
int top(lua_State *L)
Definition: sol.hpp:7743
readonly_wrapper(T v)
Definition: sol.hpp:12986
#define SOL_STACK_STRING_OPTIMIZATION_SIZE
Definition: sol.hpp:252
~push_popper_n()
Definition: sol.hpp:6625
static int push(lua_State *L, metatable_t, Key &&key, Args &&... args)
Definition: sol.hpp:10819
std::unique_ptr< T, D > actual_type
Definition: sol.hpp:4778
static int push(lua_State *L, Args &&... args)
Definition: sol.hpp:10381
basic_table_core(lua_State *L, ref_index index)
Definition: sol.hpp:20190
~stack_guard()
Definition: sol.hpp:7135
metatable_setup(lua_State *L)
Definition: sol.hpp:17985
void set_panic(lua_CFunction panic)
Definition: sol.hpp:21499
static int real_at_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17750
error_code error
Definition: sol.hpp:8932
void set_extra(std::true_type, std::index_sequence< I... >, T &&target)
Definition: sol.hpp:7061
static int push(lua_State *L, const char16_t *u16str, std::size_t sz)
Definition: sol.hpp:11051
static int call(lua_State *L, F &fx, Args &&... args)
Definition: sol.hpp:13698
typename return_type< Args... >::type return_type_t
Definition: sol.hpp:1414
static int push(lua_State *L, const char(&str)[N])
Definition: sol.hpp:10905
void stack_fail(int, int)
Definition: sol.hpp:7105
static int real_erase_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17898
constexpr optional< typename ::std::decay< T >::type > make_optional(T &&v)
Definition: sol.hpp:4332
unsafe_function_result unsafe_script_file(const std::string &filename, load_mode mode=load_mode::any)
Definition: sol.hpp:21377
meta::boolean< has_empty_test< T >::value > has_empty
Definition: sol.hpp:16577
static int real_index_call(lua_State *L)
Definition: sol.hpp:18946
static int push(lua_State *L, property_wrapper< F, G > &&pw)
Definition: sol.hpp:14746
protected_function_result safe_script(const string_view &code, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21306
auto operator=(U &&rhs) noexcept -> typename ::std::enable_if< ::std::is_same< typename ::std::decay< U >::type, optional< T &>>::value, optional &>::type
Definition: sol.hpp:3993
void usertype_unique_alloc_destroy(void *memory)
Definition: sol.hpp:7570
int default_exception_handler(lua_State *L, optional< const std::exception &>, string_view what)
Definition: sol.hpp:5840
static int call(std::index_sequence< In... >, lua_State *L, P &fx)
Definition: sol.hpp:13708
global_table::const_iterator const_iterator
Definition: sol.hpp:21116
decltype(meta_detail::supports_op_less_test(std::declval< T & >(), std::declval< U & >())) supports_op_less
Definition: sol.hpp:1678
const char(& default_exception_handler_name())[11]
Definition: sol.hpp:5834
lua_State * L
Definition: sol.hpp:12214
void initialize(::std::initializer_list< U > il, Args &&... args) noexcept(noexcept(T(il, ::std::forward< Args >(args)...)))
Definition: sol.hpp:3679
Definition: sol.hpp:4563
object indexfunc
Definition: sol.hpp:19345
basic_coroutine(lua_State *L, ref_index index)
Definition: sol.hpp:22051
int index
Definition: sol.hpp:20785
void * align_usertype_unique(void *ptr)
Definition: sol.hpp:7258
nested(Arg &&arg)
Definition: sol.hpp:5014
is_stack_based< target_t > is_stack
Definition: sol.hpp:15061
static int push(lua_State *L, const std::basic_string< Ch, Traits, Al > &wstr)
Definition: sol.hpp:11241
std::array< char, 1 > sfinae_yes_t
Definition: sol.hpp:1208
void make_length_op(Regs &l, int &index)
Definition: sol.hpp:18262
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:14201
protected_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n, detail::protected_handler< b, handler_t > &h) const
Definition: sol.hpp:15168
auto & pick(std::false_type, property_wrapper< R, W > &f)
Definition: sol.hpp:13101
std::ptrdiff_t difference_type
Definition: sol.hpp:11979
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8693
simple_usertype(lua_State *L, Args &&... args)
Definition: sol.hpp:19868
basic_protected_function(lua_State *L, raw_index index)
Definition: sol.hpp:15328
std::ptrdiff_t difference_type
Definition: sol.hpp:15978
Definition: sol.hpp:392
Definition: sol.hpp:377
Definition: sol.hpp:5087
int static_trampoline(lua_State *L)
Definition: sol.hpp:5894
in_place_tag(&)(detail::in_place_of_tag) in_place_t
Definition: sol.hpp:3247
error tagged_get(types< error >, int index_offset) const
Definition: sol.hpp:12250
T t
Definition: sol.hpp:6636
std::remove_pointer_t< meta::unwrap_unqualified_t< X > > T
Definition: sol.hpp:16698
std::pair< object, object > value_type
Definition: sol.hpp:19900
static int push(lua_State *L, destructor_wrapper< void >)
Definition: sol.hpp:14869
basic_lightuserdata(const stack_reference &r)
Definition: sol.hpp:15900
Definition: sol.hpp:3489
basic_table_core(lua_State *L, int index=-1)
Definition: sol.hpp:20183
static bool check(types<>, lua_State *, int, Handler &&, record &)
Definition: sol.hpp:7979
types< Args... > args_list
Definition: sol.hpp:568
static int real_find_call(lua_State *L, void *um, usertype_metatable_core &, int)
Definition: sol.hpp:18878
std::reverse_iterator< iterator > reverse_iterator
Definition: sol.hpp:15982
unqualified_t< tuple_element_t< N, Tuple >> unqualified_tuple_element_t
Definition: sol.hpp:518
bool operator<(const stack_iterator &r) const
Definition: sol.hpp:12074
unsafe_function_result & operator=(unsafe_function_result &&o)
Definition: sol.hpp:12436
int top() const
Definition: sol.hpp:16095
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8449
static void select(lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14606
F fx
Definition: sol.hpp:18415
int stacktop
Definition: sol.hpp:15972
const auto no_constructor
Definition: sol.hpp:4500
lua_State * L
Definition: sol.hpp:17983
std::function< void(int, int)> on_mismatch
Definition: sol.hpp:7119
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8709
meta::boolean< meta_detail::has_insert_test< T >::value > has_insert
Definition: sol.hpp:1719
simple_usertype< Class > create_simple_usertype(constructors< CArgs... > ctor, Args &&... args)
Definition: sol.hpp:20384
bool operator!=(const basic_table_iterator &right) const
Definition: sol.hpp:19967
protected_function_result & operator=(const protected_function_result &)=default
basic_function(T &&r) noexcept
Definition: sol.hpp:14977
~load_result()
Definition: sol.hpp:20894
int multi_push(lua_State *L, T &&t, Args &&... args)
Definition: sol.hpp:7796
void type_assert(lua_State *L, int index, type expected, type actual) noexcept(false)
Definition: sol.hpp:6414
Definition: sol.hpp:21858
int stack_index() const noexcept
Definition: sol.hpp:6786
Definition: sol.hpp:1148
property_wrapper(Rx &&r, Wx &&w)
Definition: sol.hpp:12935
Definition: sol.hpp:4450
std::tuple_element< N, std::remove_reference_t< Tuple >> tuple_element
Definition: sol.hpp:509
~unsafe_function_result()
Definition: sol.hpp:12525
unsafe_function_result(lua_State *Ls, int idx=-1, int retnum=0)
Definition: sol.hpp:12424
int push(lua_State *, lua_thread_state lts)
Definition: sol.hpp:21713
stack_reference(lua_State *L, raw_index i) noexcept
Definition: sol.hpp:6468
static_stack_dependencies<-1, 1 > self_dependency
Definition: sol.hpp:4564
Definition: sol.hpp:4799
static int real_erase_call(lua_State *L)
Definition: sol.hpp:17902
int push(lua_State *L, const as_args_t< T > &e)
Definition: sol.hpp:15952
type get_type(difference_type index_offset=0) const noexcept
Definition: sol.hpp:12457
static int push_rvalue(std::false_type, lua_State *L, const C &cont)
Definition: sol.hpp:18044
void clear() noexcept
Definition: sol.hpp:3665
Definition: ItemStack.hpp:19
Definition: sol.hpp:4843
int index
Definition: sol.hpp:11982
clean(lua_State *luastate)
Definition: sol.hpp:19990
lua_State * lua_state() const noexcept
Definition: sol.hpp:5062
lua_State * lua_state() const noexcept
Definition: sol.hpp:6986
T & value()
Definition: sol.hpp:3896
static int index_call(lua_State *L)
Definition: sol.hpp:17970
basic_function< stack_reference, false > stack_unsafe_function
Definition: sol.hpp:310
static int push(lua_State *L, detail::tagged< T, constructor_list< Lists... >>)
Definition: sol.hpp:14825
int metatable_new_index(lua_State *L)
Definition: sol.hpp:18577
decltype(auto) get(Keys &&... keys) const
Definition: sol.hpp:20230
static int real_clear_call(lua_State *L)
Definition: sol.hpp:17878
static constexpr bool is_lead_surrogate(char32_t u)
Definition: sol.hpp:8950
Definition: sol.hpp:1428
destructor_wrapper(Function f)
Definition: sol.hpp:4536
basic_environment(lua_State *L, new_table nt)
Definition: sol.hpp:20600
std::tuple< clean_type_t< Tn >... > Tuple
Definition: sol.hpp:18737
int c_trampoline(lua_State *L, lua_CFunction f)
Definition: sol.hpp:5977
int call_set_variable(std::true_type, lua_State *L, T &&mem)
Definition: sol.hpp:13798
Definition: sol.hpp:6615
lua_bind_traits< function_type > traits_type
Definition: sol.hpp:13961
static usertype_detail::simple_map & make_cleanup(lua_State *L, umt_t &umx)
Definition: sol.hpp:19551
constexpr optional(in_place_t, Args &&... args)
Definition: sol.hpp:3727
static int push(lua_State *L, cl_t cl)
Definition: sol.hpp:14839
static bool check(lua_State *, int, Handler &&, record &tracking)
Definition: sol.hpp:8366
protected_function_result safe_function_result
Definition: sol.hpp:332
bool operator!=(const std::basic_string< Char, Traits > &r) const
Definition: sol.hpp:1142
userdata_value(void *data)
Definition: sol.hpp:4863
auto unwrap(T &&item) -> decltype(std::forward< T >(item))
Definition: sol.hpp:1832
const int magic_index
Definition: sol.hpp:18383
basic_object & operator=(base_type &&b)
Definition: sol.hpp:16213
std::enable_if_t< all< Args... >::value, enable_t > enable
Definition: sol.hpp:1320
Definition: sol.hpp:1355
basic_protected_function(stack_reference &&r, handler_t eh)
Definition: sol.hpp:15273
static int real_call(lua_State *L) noexcept(false)
Definition: sol.hpp:14068
const char * unique_tag
Definition: sol.hpp:7163
static T * get_no_lua_nil_from(lua_State *L, void *udata, int index, record &)
Definition: sol.hpp:9933
~ref_clean()
Definition: sol.hpp:20003
basic_protected_function(const stack_reference &r, handler_t eh)
Definition: sol.hpp:15270
Definition: sol.hpp:13837
table create_table(int narr=0, int nrec=0)
Definition: sol.hpp:21657
std::size_t len
Definition: sol.hpp:4572
bases base_classes_tag
Definition: sol.hpp:6201
nested< meta::unqualified_t< T > > as_nested(T &&container)
Definition: sol.hpp:5043
Definition: sol.hpp:379
state_view & new_enum(const string_view &name, Args &&... args)
Definition: sol.hpp:21602
int operator()(lua_State *L, int index, type expected, type actual, const std::string &message) const noexcept(false)
Definition: sol.hpp:6375
int overload_match(Match &&matchfx, lua_State *L, int start, Args &&... args)
Definition: sol.hpp:13200
T * user_allocate(lua_State *L)
Definition: sol.hpp:7502
returns_self_with returns_self
Definition: sol.hpp:4567
int construct_trampolined(lua_State *L)
Definition: sol.hpp:13212
basic_protected_function(stack_reference &&r)
Definition: sol.hpp:15267
Definition: sol.hpp:6445
static Reference get_default_handler(lua_State *L)
Definition: sol.hpp:15101
decltype(auto) call(types< R >, types< Args... > ta, std::index_sequence< I... > tai, lua_State *L, int start, Fx &&fx, FxArgs &&... args)
Definition: sol.hpp:11783
Definition: sol.hpp:5373
L * value
Definition: sol.hpp:4873
int typed_static_trampoline_raw(std::true_type, lua_State *L)
Definition: sol.hpp:5983
int(* lua_CFunction_noexcept)(lua_State *L)
Definition: sol.hpp:4652
~push_popper()
Definition: sol.hpp:6641
Definition: sol.hpp:3568
stack_proxy * pointer
Definition: sol.hpp:15977
static int push(lua_State *L, T &&t)
Definition: sol.hpp:11278
Definition: sol.hpp:410
static int real_ipairs_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17814
static int get_size_hint(const std::forward_list< V, Al > &)
Definition: sol.hpp:7690
void type
Definition: sol.hpp:5649
static int push(lua_State *L, const std::reference_wrapper< T > &t)
Definition: sol.hpp:10482
static int convertible_call(std::false_type, lua_State *L, Fx &&f, Args &&... args)
Definition: sol.hpp:13249
void abandon() noexcept
Definition: sol.hpp:12520
std::forward_list< T, Al > C
Definition: sol.hpp:9411
probe probe_raw_get_field(lua_State *L, Key &&key, int tableindex)
Definition: sol.hpp:8104
call_status status() const noexcept
Definition: sol.hpp:12503
Definition: sol.hpp:3384
Write write
Definition: sol.hpp:12932
void add(lua_State *L, N &&n, constructor_list< Lists... > c)
Definition: sol.hpp:19444
state_view(lua_State *Ls)
Definition: sol.hpp:21118
Definition: sol.hpp:3512
Definition: sol.hpp:18525
static int ipairs_call(lua_State *L)
Definition: sol.hpp:17950
int adl_default_to_string(std::false_type, lua_State *L)
Definition: sol.hpp:18156
const char * metakey
Definition: sol.hpp:18435
bool is_stack(std::false_type) const
Definition: sol.hpp:15786
static int at_call(lua_State *L)
Definition: sol.hpp:17958
const_iterator cend() const
Definition: sol.hpp:12480
auto as_function_reference(Args &&... args)
Definition: sol.hpp:4977
static int push(lua_State *L, const as_container_t< T > &as_cont)
Definition: sol.hpp:18048
unsafe_function_result operator()(Args &&... args) const
Definition: sol.hpp:15026
static int push(lua_State *L, no_metatable_t, const user< T > &u)
Definition: sol.hpp:10834
Definition: sol.hpp:1387
const Char * begin() const
Definition: sol.hpp:1090
basic_coroutine(stack_reference &&r, handler_t eh)
Definition: sol.hpp:21986
Definition: sol.hpp:1240
static void select_member_function(std::true_type, lua_State *L, Fx &&fx, T &&obj, Args &&... args)
Definition: sol.hpp:14549
Definition: sol.hpp:18125
constexpr optional() noexcept
Definition: sol.hpp:3689
basic_coroutine(lua_State *L, raw_index index)
Definition: sol.hpp:22041
constexpr nullopt_t nullopt
Definition: sol.hpp:3498
iterator end() const
Definition: sol.hpp:20217
int c_call(lua_State *L)
Definition: sol.hpp:13862
auto readonly(R T::*v)
Definition: sol.hpp:13000
Definition: sol.hpp:5417
map_t< std::string, object > function_map
Definition: sol.hpp:18432
error_code error
Definition: sol.hpp:8925
static void insert_at_end(std::true_type, types< V >, lua_State *L, T &arr, std::size_t)
Definition: sol.hpp:9272
Arg type
Definition: sol.hpp:1364
static int push(lua_State *L, property_wrapper< void, F > &&pw)
Definition: sol.hpp:14766
int operator()(lua_State *L)
Definition: sol.hpp:13993
record()
Definition: sol.hpp:7646
void apply(std::index_sequence< I0, I1, I... >, lua_State *L, Keys &&keys, Value &&value, int tableindex)
Definition: sol.hpp:11613
unique_usertype_traits< T >::type P
Definition: sol.hpp:10437
Definition: sol.hpp:4682
load_result load_buffer(const char *buff, size_t size, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21437
std::index_sequence_for< Filters... > indices
Definition: sol.hpp:4596
void(*)(void *) unique_destructor
Definition: sol.hpp:7159
static int push(lua_State *L, const char32_t *strb, const char32_t *stre)
Definition: sol.hpp:11169
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8654
struct sol::detail::no_safety_tag no_safety
basic_protected_function(T &&r) noexcept
Definition: sol.hpp:15238
push_popper(T x)
Definition: sol.hpp:6637
container_traits< T > traits
Definition: sol.hpp:17707
basic_coroutine(lua_State *L, int index=-1)
Definition: sol.hpp:22021
std::array< char, 2 > two
Definition: sol.hpp:16472
Definition: sol.hpp:5656
constexpr optional(const optional &rhs) noexcept
Definition: sol.hpp:3964
basic_thread create()
Definition: sol.hpp:21836
sol::optional< T & > argument_type
Definition: sol.hpp:4357
void make_to_string_op(Regs &l, int &index)
Definition: sol.hpp:18210
bool operator>=(const stack_iterator &r) const
Definition: sol.hpp:12086
Definition: sol.hpp:7615
std::make_index_sequence< sizeof...(I) *2 > indices
Definition: sol.hpp:18733
void add(lua_State *L, N &&n, F &&f)
Definition: sol.hpp:19415
std::tuple< Functions... > overload_list
Definition: sol.hpp:14253
type get_type() const noexcept
Definition: sol.hpp:6980
user(U &&x)
Definition: sol.hpp:4902
int construct(lua_State *L)
Definition: sol.hpp:13232
auto make_user(T &&u)
Definition: sol.hpp:4917
const new_table create
Definition: sol.hpp:20012
int call_into_lua(types< void > tr, types< Args... > ta, lua_State *L, int start, Fx &&fx, FxArgs &&... fxargs)
Definition: sol.hpp:11846
Definition: sol.hpp:4923
static void construct(T &&obj, Args &&... args)
Definition: sol.hpp:4438
static int push(lua_State *L, const char *strb, const char *stre)
Definition: sol.hpp:10867
void raw_get_field(lua_State *L, Key &&key, int tableindex)
Definition: sol.hpp:8084
lua_State * L
Definition: sol.hpp:18337
int call_wrapped(lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:13729
has_clear< T > has_traits_clear
Definition: sol.hpp:16619
basic_function(const stack_reference &r)
Definition: sol.hpp:14991
int stack_index() const noexcept
Definition: sol.hpp:12365
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount) const
Definition: sol.hpp:14942
Definition: sol.hpp:5764
const_reverse_iterator rbegin() const
Definition: sol.hpp:12490
const target_t & target
Definition: sol.hpp:15062
static bool check(lua_State *, int, type, Handler &&, record &)
Definition: sol.hpp:8196
basic_environment(env_t, const basic_reference< b > &extraction_target)
Definition: sol.hpp:20621
std::decay_t< meta::unwrap_unqualified_t< Func > > function_type
Definition: sol.hpp:14141
Definition: sol.hpp:12620
static int real_meta_new_index_call(lua_State *L)
Definition: sol.hpp:18958
usertype_detail::base_walk newindexbaseclasspropogation
Definition: sol.hpp:18746
constexpr bool operator>(const optional< T > &x, const optional< T > &y)
Definition: sol.hpp:4067
static int real_size_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17834
decltype(&inheritance< void >::type_cast) inheritance_cast_function
Definition: sol.hpp:6300
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776
static int push_fx(lua_State *L, F &&f, T *obj)
Definition: sol.hpp:10391
static int push(lua_State *L, const protected_function_result &pfr)
Definition: sol.hpp:12389
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8204
int call_user(lua_State *L)
Definition: sol.hpp:13734
void * value
Definition: sol.hpp:4852
const char(& default_main_thread_name())[9]
Definition: sol.hpp:6569
static int add_call(lua_State *L)
Definition: sol.hpp:17918
Definition: sol.hpp:7617
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:14000
static int insert(lua_State *L)
Definition: sol.hpp:16728
reverse_iterator rend()
Definition: sol.hpp:12346
object newindex
Definition: sol.hpp:18439
static int push_with(lua_State *L, Key &&name, Args &&... args)
Definition: sol.hpp:10789
static int push(lua_State *L, overload_set< Functions... > &&set)
Definition: sol.hpp:14710
protected_function_result do_file(const std::string &filename, load_mode mode=load_mode::any)
Definition: sol.hpp:21274
constexpr optional(nullopt_t) noexcept
Definition: sol.hpp:3691
void invoke(types< void >, std::index_sequence< I >, std::ptrdiff_t n, detail::protected_handler< b, handler_t > &h) const
Definition: sol.hpp:15163
lua_bind_traits< function_type > traits_type
Definition: sol.hpp:13928
meta_function
Definition: sol.hpp:5277
static int push(lua_State *L, meta_function m)
Definition: sol.hpp:10950
basic_thread(lua_State *L, ref_index index)
Definition: sol.hpp:21782
Ret invoke(types< Ret >, std::index_sequence< I >, std::ptrdiff_t n, detail::protected_handler< b, handler_t > &h) const
Definition: sol.hpp:15157
Definition: sol.hpp:5632
type type_of(lua_State *L, int index)
Definition: sol.hpp:5358
static int call(lua_State *L)
Definition: sol.hpp:13943
void register_main_thread(lua_State *L)
Definition: sol.hpp:20908
static iterator end(lua_State *L, T &)
Definition: sol.hpp:16769
basic_string_view< char > string_view
Definition: sol.hpp:1186
state_view & new_simple_usertype(const std::string &name, constructors< CArgs... > ctor, Args &&... args)
Definition: sol.hpp:21581
int registry_index() const noexcept
Definition: sol.hpp:6451
Definition: sol.hpp:17705
std::array< char, 2 > two
Definition: sol.hpp:16562
Definition: sol.hpp:16304
call_syntax get_call_syntax(lua_State *L, const string_view &key, int index)
Definition: sol.hpp:11877
stack_reference(lua_State *L, lua_nil_t) noexcept
Definition: sol.hpp:6459
lua_CFunction newindexfunc
Definition: sol.hpp:18452
static int call_with(lua_State *L)
Definition: sol.hpp:18986
void operator()(T *p) const
Definition: sol.hpp:4465
int default_traceback_error_handler(lua_State *L)
Definition: sol.hpp:20944
basic_table_core(lua_State *L, const new_table &nt)
Definition: sol.hpp:20177
static void set_default_handler(lua_State *L, const T &ref)
Definition: sol.hpp:15111
int map_hint
Definition: sol.hpp:5089
int sequence_hint
Definition: sol.hpp:5088
Definition: sol.hpp:1332
static void * type_cast(void *voiddata, const std::string &ti)
Definition: sol.hpp:6259
static int push(lua_State *L, nullopt_t)
Definition: sol.hpp:11288
static constexpr char32_t replacement
Definition: sol.hpp:8995
std::array< char, 1 > one
Definition: sol.hpp:16456
void insert_prepare(std::true_type, lua_State *L, N &&, F &&f, Args &&... args)
Definition: sol.hpp:19378
int operator()(lua_State *L)
Definition: sol.hpp:14159
~state()
Definition: sol.hpp:21884
static int erase(lua_State *L)
Definition: sol.hpp:16748
Definition: sol.hpp:6366
object key_type
Definition: sol.hpp:19898
basic_reference(stack_reference &&r) noexcept
Definition: sol.hpp:6802
reverse_iterator rbegin()
Definition: sol.hpp:16035
basic_string_view< char16_t > u16string_view
Definition: sol.hpp:1188
static int call_const(std::false_type, lua_State *L, Args &&... args)
Definition: sol.hpp:13293
lua_State * L
Definition: sol.hpp:12106
T source
Definition: sol.hpp:16253
lua_State * L
Definition: sol.hpp:7117
Definition: sol.hpp:9976
void set_field(lua_State *L, Key &&key, Value &&value, int tableindex)
Definition: sol.hpp:8114
proxy< global_table &, T > operator[](T &&key)
Definition: sol.hpp:21619
lua_State * L
Definition: sol.hpp:12408
constexpr bool operator>=(const optional< T > &x, const optional< T > &y)
Definition: sol.hpp:4077
int popcount
Definition: sol.hpp:20787
meta::function_return_t< function_type > return_type
Definition: sol.hpp:14173
virtual const char * what() const noexcept override
Definition: sol.hpp:438
Definition: sol.hpp:7613
static constexpr int sequence_length(unsigned char b)
Definition: sol.hpp:8972
table_core< true > global_table
Definition: sol.hpp:292
static int real_next_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17826
const Char * p
Definition: sol.hpp:1067
int push_environment_of(lua_State *L, int index=-1)
Definition: sol.hpp:10337
map_t< std::string, std::unique_ptr< variable_wrapper > > variable_map
Definition: sol.hpp:18431
constexpr optional(in_place_t, T &v) noexcept
Definition: sol.hpp:3968
decltype(auto) unchecked_get(lua_State *L, int index, record &tracking)
Definition: sol.hpp:7704
lua_State * operator->() const noexcept
Definition: sol.hpp:21705
static int push(lua_State *L, no_construction c, function_detail::call_indicator)
Definition: sol.hpp:14818
Definition: sol.hpp:5392
Definition: sol.hpp:4534
Definition: sol.hpp:18449
static void select_member_function(std::true_type, lua_State *L, Fx &&fx, function_detail::class_indicator< C >)
Definition: sol.hpp:14555
typename container_decay< meta::unqualified_t< T >>::type container_decay_t
Definition: sol.hpp:16650
luaL_Reg make_reg(N &&n, lua_CFunction f)
Definition: sol.hpp:18520
Definition: sol.hpp:13106
decltype(auto) get(Keys &&... keys) const
Definition: sol.hpp:21508
static int push(lua_State *L, T &&obj)
Definition: sol.hpp:10414
meta::boolean< meta_detail::has_push_back_test< T >::value > has_push_back
Definition: sol.hpp:1713
function_type fx
Definition: sol.hpp:14142
static int real_add_call(lua_State *L)
Definition: sol.hpp:17854
static int real_empty_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17882
basic_coroutine(lua_State *L, T &&r)
Definition: sol.hpp:22004
void get_field(lua_State *L, Key &&key, int tableindex)
Definition: sol.hpp:8074
Definition: sol.hpp:5813
member_variable(function_type v, Args &&... args)
Definition: sol.hpp:14209
int t
Definition: sol.hpp:6617
meta::boolean< has_traits_add_test< T >::value > has_traits_add
Definition: sol.hpp:16613
load_mode
Definition: sol.hpp:5138
usertype_detail::base_walk newindexbaseclasspropogation
Definition: sol.hpp:19350
basic_coroutine(basic_function< base_t > &&b)
Definition: sol.hpp:21968
void luajit_exception_handler(lua_State *L, int(*handler)(lua_State *, lua_CFunction)=detail::c_trampoline)
Definition: sol.hpp:11903
static void select_function(std::true_type, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14581
raw_index(int i)
Definition: sol.hpp:4812
constexpr auto resolve_f(std::true_type, F &&f) -> decltype(resolve_i(types< meta::function_signature_t< decltype(&U::operator())>>(), std::forward< F >(f)))
Definition: sol.hpp:14297
void remove(lua_State *L, int rawindex, int count)
Definition: sol.hpp:6576
constexpr in_place_tag in_place_index(detail::in_place_of_i< I >)
Definition: sol.hpp:3243
stack_guard(lua_State *L)
Definition: sol.hpp:7121
Definition: sol.hpp:4463
bool operator==(const stack_iterator &r) const
Definition: sol.hpp:12060
static int push(lua_State *L, metatable_t)
Definition: sol.hpp:10692
Definition: sol.hpp:5788
constexpr T && constexpr_forward(typename ::std::remove_reference< T >::type &t) noexcept
Definition: sol.hpp:3432
int user_alloc_destruct(lua_State *L)
Definition: sol.hpp:7560
iterator begin() const
Definition: sol.hpp:21453
Definition: sol.hpp:342
Definition: sol.hpp:414
simple_usertype_metatable(lua_State *L, constructors< CArgs... > constructorlist, Args &&... args)
Definition: sol.hpp:19527
result_type operator()(const std::basic_string< Ch, Tr, Al > &r) const
Definition: sol.hpp:1153
types< Args... > type
Definition: sol.hpp:478
meta::bind_traits< function_type > traits_type
Definition: sol.hpp:13902
Definition: sol.hpp:13740
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:14066
unsafe_function_result unsafe_script_file(const std::string &filename, const basic_environment< E > &env, load_mode mode=load_mode::any)
Definition: sol.hpp:21363
lua_State * L
Definition: sol.hpp:15970
basic_coroutine(const stack_reference &r, handler_t eh)
Definition: sol.hpp:21983
Definition: sol.hpp:15767
void operator()(T &&obj, Args &&... args) const
Definition: sol.hpp:4445
stack_proxy operator[](difference_type index_offset) const
Definition: sol.hpp:12461
constexpr T & operator*() const
Definition: sol.hpp:4022
Definition: sol.hpp:273
unsafe_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n) const
Definition: sol.hpp:14963
int construct_match(Match &&matchfx, lua_State *L, int fxarity, int start, Args &&... args)
Definition: sol.hpp:13206
T * operator->()
Definition: sol.hpp:3871
std::tuple< Upvalues... > upvalues
Definition: sol.hpp:4940
std::conditional_t< is_matched_lookup::value, std::pair< value_type, value_type >, std::conditional_t< is_associative::value||is_lookup::value, value_type, std::pair< std::ptrdiff_t, value_type > > > KV
Definition: sol.hpp:16793
base_walk indexbaseclasspropogation
Definition: sol.hpp:18440
std::array< char, 2 > two
Definition: sol.hpp:16442
bool operator<=(const stack_iterator &r) const
Definition: sol.hpp:12082
state_view & new_usertype(const std::string &name, constructors< CArgs... > ctor, Args &&... args)
Definition: sol.hpp:21563
meta::boolean< has_traits_get_test< T >::value > has_traits_get
Definition: sol.hpp:16589
static int push(lua_State *L, Args &&... args)
Definition: sol.hpp:10422
Definition: sol.hpp:4851
int push(lua_State *L, const as_returns_t< T > &e)
Definition: sol.hpp:22124
basic_table_core & set_usertype(Key &&key, usertype< T > &user)
Definition: sol.hpp:20327
Definition: sol.hpp:5754
const auto default_constructor
Definition: sol.hpp:4497
int call_wrapper_entry(lua_State *L) noexcept(meta::bind_traits< F >::is_noexcept)
Definition: sol.hpp:13832
stack_iterator & operator+=(difference_type idx)
Definition: sol.hpp:12036
typename unwrap_unqualified< T >::type unwrap_unqualified_t
Definition: sol.hpp:1243
light(L *x)
Definition: sol.hpp:4878
void pop(lua_State *Ls, int n=1) const noexcept
Definition: sol.hpp:6512
pointer operator->() const
Definition: sol.hpp:12009
static int push(lua_State *L, char16_t c)
Definition: sol.hpp:11225
bool operator==(const std::basic_string< Char, Traits > &r) const
Definition: sol.hpp:1130
void set_resolved_function(Key &&key, Args &&... args)
Definition: sol.hpp:20492
Definition: sol.hpp:4656
static void push_back_at_end(std::true_type, types< V >, lua_State *L, T &arr, std::size_t)
Definition: sol.hpp:9262
~basic_reference() noexcept
Definition: sol.hpp:6876
int copy() const noexcept
Definition: sol.hpp:6721
decltype(auto) traverse_get(Keys &&... keys) const
Definition: sol.hpp:20256
meta::boolean< meta_detail::has_insert_after_test< T >::value > has_insert_after
Definition: sol.hpp:1722
yielding_t(Arg &&arg)
Definition: sol.hpp:4718
constexpr result_type operator()(argument_type const &arg) const
Definition: sol.hpp:4359
Definition: sol.hpp:383
constexpr Sig C::* resolve_v(std::false_type, Sig C::*mem_func_ptr)
Definition: sol.hpp:14319
protected_function_result safe_script(const string_view &code, const basic_environment< E > &env, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21302
state_view & set_usertype(usertype< T > &user)
Definition: sol.hpp:21540
int count
Definition: sol.hpp:4844
static int push(lua_State *L, light< T > l)
Definition: sol.hpp:10780
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: sol.hpp:15983
std::integral_constant< bool, !std::is_void< R >::value > can_read
Definition: sol.hpp:12927
static int real_new_index_call(lua_State *L)
Definition: sol.hpp:17794
state_view & set_function(Key &&key, Args &&... args)
Definition: sol.hpp:21629
int runtime_new_index(lua_State *L, void *, usertype_metatable_core &, int runtimetarget)
Definition: sol.hpp:18673
basic_table_core & raw_set(Args &&... args)
Definition: sol.hpp:20316
int target
Definition: sol.hpp:4570
constexpr constexpr_optional_base(in_place_t, Args &&... args)
Definition: sol.hpp:3586
basic_reference(lua_State *L, int index=-1) noexcept
Definition: sol.hpp:6861
Definition: sol.hpp:7155
unsafe_function_result unsafe_script(const string_view &code, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21354
simple_usertype_metatable(detail::verified_tag, std::index_sequence< I... >, lua_State *L, Tuple &&args)
Definition: sol.hpp:19493
decltype(auto) tagged_unqualified_get(types< T >, lua_State *L, int index, record &tracking)
Definition: sol.hpp:7959
object newindexfunc
Definition: sol.hpp:19346
constexpr auto resolve(R fun_ptr(Args...)) -> R(*)(Args...)
Definition: sol.hpp:14330
proxy & set_function(Args &&... args)
Definition: sol.hpp:15544
static int push(lua_State *L, Arg &&arg)
Definition: sol.hpp:10441
std::array< char, 2 > two
Definition: sol.hpp:16337
static int real_size_traits(std::false_type, lua_State *L)
Definition: sol.hpp:17838
Definition: sol.hpp:15752
std::size_t aligned_space_for(void *alignment=nullptr)
Definition: sol.hpp:7189
main_table_core< false > main_table
Definition: sol.hpp:293
void pop() const noexcept
Definition: sol.hpp:6953
typename void_tuple_element< I, T >::type void_tuple_element_t
Definition: sol.hpp:555
member_search new_index
Definition: sol.hpp:18394
static table create_table_with(lua_State *L, Args &&... args)
Definition: sol.hpp:21681
protected_function_result script_pass_on_error(lua_State *, protected_function_result result)
Definition: sol.hpp:20980
static int push(lua_State *L, const factory_wrapper< Functions... > &set, function_detail::call_indicator)
Definition: sol.hpp:14798
int call(lua_State *L)
Definition: sol.hpp:14183
constexpr const auto enabler
Definition: sol.hpp:1314
lua_State * L
Definition: sol.hpp:21693
basic_string_view(const std::string &r)
Definition: sol.hpp:1069
meta::boolean< has_erase_test< T >::value > has_erase
Definition: sol.hpp:16583
lua_CFunction c_function
Definition: sol.hpp:4939
lua_CFunction make_func() const
Definition: sol.hpp:18753
this_environment(environment e)
Definition: sol.hpp:20708
const std::string & short_demangle()
Definition: sol.hpp:6152
#define OPTIONAL_MUTABLE_CONSTEXPR
Definition: sol.hpp:3347
std::array< const char *, 4 > args
Definition: sol.hpp:16675
const int filler_index
Definition: sol.hpp:18382
type get_type(difference_type index_offset=0) const noexcept
Definition: sol.hpp:12316
static int push(lua_State *L, const P &p)
Definition: sol.hpp:14917
static int push(lua_State *L, const char32_t(&str)[N], std::size_t sz)
Definition: sol.hpp:11210
void for_each(std::true_type, Fx &&fx) const
Definition: sol.hpp:20024
Definition: sol.hpp:7153
static bool type_unique_cast_bases(void *source_data, void *target_data, const string_view &ti)
Definition: sol.hpp:6270
T type
Definition: sol.hpp:4736
static void select_function(std::false_type, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14576
Definition: sol.hpp:282
static int call_const(std::true_type, lua_State *L, Args &&...)
Definition: sol.hpp:13299
Definition: sol.hpp:5629
static int push(lua_State *L, wchar_t c)
Definition: sol.hpp:11217
std::array< char, 1 > one
Definition: sol.hpp:16471
const Char * cend() const
Definition: sol.hpp:1102
proxy_t value_type
Definition: sol.hpp:11978
Definition: sol.hpp:4569
static int push(lua_State *L, const wchar_t(&str)[N])
Definition: sol.hpp:11184
static void walk_single_base(lua_State *L, bool &found, int &ret, string_view &)
Definition: sol.hpp:18681
protected_function_result safe_script_file(const std::string &filename, const basic_environment< E > &env, Fx &&on_error, load_mode mode=load_mode::any)
Definition: sol.hpp:21320
push_popper(T)
Definition: sol.hpp:6647
void open_libraries(Args &&... args)
Definition: sol.hpp:21131
Definition: sol.hpp:1227
basic_thread(T &&r)
Definition: sol.hpp:21752
void pop(lua_State *Ls, int n=1) const noexcept
Definition: sol.hpp:6957
proxy & force()
Definition: sol.hpp:15652
static void select_member_variable(std::false_type, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14491
basic_thread(const stack_reference &r)
Definition: sol.hpp:21760
static bool check(lua_State *, int, Handler &&, record &tracking)
Definition: sol.hpp:8348
typename pop_front_type< Arg >::type pop_front_type_t
Definition: sol.hpp:494
static int push(lua_State *L, const wchar_t *wstr, std::size_t sz)
Definition: sol.hpp:10987
int push(lua_State *L)
Definition: sol.hpp:19853
void add_function(lua_State *L, N &&n, F &&f)
Definition: sol.hpp:19400
Real * usertype_unique_allocate(lua_State *L, T **&pref, unique_destructor *&dx, unique_tag *&id)
Definition: sol.hpp:7413
lua_State * L
Definition: sol.hpp:11981
int runtime_target
Definition: sol.hpp:18395
~basic_table_iterator()
Definition: sol.hpp:19971
basic_protected_function(basic_function< base_t > &&b)
Definition: sol.hpp:15255
int stacktop
Definition: sol.hpp:11983
const metatable_t metatable_key
Definition: sol.hpp:4700
int call(types< Fx >, index_value< I >, types< R... >, types< Args... >, lua_State *L, int, int)
Definition: sol.hpp:14266
bool is() const
Definition: sol.hpp:15813
thread_status
Definition: sol.hpp:5155
const Char * data() const
Definition: sol.hpp:1106
const_iterator begin() const
Definition: sol.hpp:12330
basic_table_core(lua_nil_t r) noexcept
Definition: sol.hpp:20209
int SOL_INTERNAL_UNSPECIALIZED_MARKER_
Definition: sol.hpp:5638
const_reference operator*() const
Definition: sol.hpp:19959
Definition: sol.hpp:275
std::pair< object, object > kvp
Definition: sol.hpp:19908
basic_protected_function(lua_State *L, ref_index index, handler_t eh)
Definition: sol.hpp:15341
static int push(lua_State *L, const factory_wrapper< Functions... > &fw)
Definition: sol.hpp:14786
call_status status() const noexcept
Definition: sol.hpp:12303
int index
Definition: sol.hpp:4811
Definition: sol.hpp:1384
int push_environment_of(const T &target)
Definition: sol.hpp:10353
lua_State * lua_state() const noexcept
Definition: sol.hpp:20887
unsafe_function_result unsafe_script(const string_view &code, const basic_environment< E > &env, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
Definition: sol.hpp:21338
lua_nil_t value_type
Definition: sol.hpp:16702
std::array< char, 1 > one
Definition: sol.hpp:16411
void pop() const noexcept
Definition: sol.hpp:6508
int index
Definition: sol.hpp:12409
bool success
Definition: sol.hpp:7630
basic_table_iterator operator++(int)
Definition: sol.hpp:19949
is_stack_based< handler_t > is_stack_handler
Definition: sol.hpp:15133
reference operator[](difference_type idx) const
Definition: sol.hpp:12056
meta::boolean< has_traits_find_test< T >::value > has_traits_find
Definition: sol.hpp:16625
iterator end() const
Definition: sol.hpp:21457
static constexpr std::size_t size()
Definition: sol.hpp:468
basic_function< stack_reference, true > stack_aligned_unsafe_function
Definition: sol.hpp:312
std::array< char, 1 > one
Definition: sol.hpp:16531
static R apply(std::index_sequence< I, Ix... >, lua_State *L, int index, record &tracking, Args &&... args)
Definition: sol.hpp:10030
int operator()(lua_State *L, int index, type expected, type actual, const char *message) const noexcept(false)
Definition: sol.hpp:6356
void traverse_set_deep(Key &&key, Value &&value) const
Definition: sol.hpp:20118
Definition: sol.hpp:4502
void modify_unique_usertype_as(const stack_reference &obj, F &&f)
Definition: sol.hpp:8129
overload_list overloads
Definition: sol.hpp:14255
std::unique_ptr< T, Dx > make_unique_deleter(Args &&... args)
Definition: sol.hpp:4477
Definition: sol.hpp:4832
static int real_call(lua_State *L)
Definition: sol.hpp:18963
protected_function_result & operator=(protected_function_result &&o) noexcept
Definition: sol.hpp:12285
std::array< char, 1 > one
Definition: sol.hpp:16441
Definition: sol.hpp:5812
static int push_lvalue(std::false_type, lua_State *L, const C &cont)
Definition: sol.hpp:18034
static int real_ipairs_traits(std::true_type, lua_State *L)
Definition: sol.hpp:17810
void make_reg_op(Regs &l, int &index, const char *name)
Definition: sol.hpp:18198
basic_table_core & set_usertype(usertype< T > &user)
Definition: sol.hpp:20322
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8540
table create_table(Name &&name, int narr=0, int nrec=0)
Definition: sol.hpp:21641
push_popper< top_level, T > push_pop(T &&x)
Definition: sol.hpp:6661
fx_t::args_list args_lists
Definition: sol.hpp:15457
enable_t
Definition: sol.hpp:1310
Definition: sol.hpp:5811
int c_call_raw(std::false_type, lua_State *L)
Definition: sol.hpp:13851
object require_core(const std::string &key, Fx &&action, bool create_global=true)
Definition: sol.hpp:21102
lua_nil_t iterator
Definition: sol.hpp:16701
const char * make_chunk_name(const string_view &code, const std::string &chunkname, char(&basechunkname)[N])
Definition: sol.hpp:11716
static int clear_call(lua_State *L)
Definition: sol.hpp:17930
constexpr optional(T &&v)
Definition: sol.hpp:3722
It next
Definition: sol.hpp:8927
Definition: sol.hpp:16334
static int push(lua_State *L, const void *userdata)
Definition: sol.hpp:10764
static const std::string & user_gc_metatable()
Definition: sol.hpp:6181
Definition: sol.hpp:263
std::array< char, 2 > two
Definition: sol.hpp:16427
int last
Definition: sol.hpp:7643
static void push_back_at_end(std::false_type, types< V > t, lua_State *L, T &arr, std::size_t idx)
Definition: sol.hpp:9267
int stack_clear()
Definition: sol.hpp:21485
constexpr const T * dataptr() const
Definition: sol.hpp:3633
const std::string & demangle()
Definition: sol.hpp:6146
const int index_function_index
Definition: sol.hpp:18386
basic_function(lua_nil_t n)
Definition: sol.hpp:14997
std::vector< object > runtime
Definition: sol.hpp:18453
basic_object & operator=(const base_type &b)
Definition: sol.hpp:16209
basic_protected_function(const proxy_base< Super > &p)
Definition: sol.hpp:15278
type get_type() const noexcept
Definition: sol.hpp:6525
auto protect(T &&value)
Definition: sol.hpp:12911
Definition: sol.hpp:491
stack_table_core< false > stack_table
Definition: sol.hpp:295
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8398
int fail_on_newindex(lua_State *L)
Definition: sol.hpp:20007
static int erase_call(lua_State *L)
Definition: sol.hpp:17922
std::remove_pointer_t< meta::unqualified_t< X > > T
Definition: sol.hpp:17706
void emplace(::std::initializer_list< U > il, Args &&... args)
Definition: sol.hpp:3786
int operator()(lua_State *L, int index, type expected, type actual, const std::string &message) const noexcept(false)
Definition: sol.hpp:6359
Definition: sol.hpp:303
static int real_get_call(lua_State *L)
Definition: sol.hpp:17770
std::make_index_sequence< sizeof...(Functions)> indices
Definition: sol.hpp:14254
size_t size() const
Definition: sol.hpp:20430
protect_t(Arg &&arg, Args &&... args)
Definition: sol.hpp:12900
usertype_detail::base_walk indexbaseclasspropogation
Definition: sol.hpp:18745
static int real_call(lua_State *L) noexcept(traits_type::is_noexcept)
Definition: sol.hpp:14003
static int push(lua_State *L, const destructor_wrapper< Fx > &c)
Definition: sol.hpp:14904
basic_userdata(lua_State *L, T &&r)
Definition: sol.hpp:15853
static int call(lua_State *L, Fx &&f, Args &&... args)
Definition: sol.hpp:13257
table create_table_with(Args &&... args)
Definition: sol.hpp:21667
Definition: sol.hpp:20782
error(const std::string &str)
Definition: sol.hpp:420
std::remove_pointer_t< std::decay_t< Function > > function_type
Definition: sol.hpp:14172
push_popper_at(lua_State *luastate, int index=-1, int count=1)
Definition: sol.hpp:6606
static int next(lua_State *L)
Definition: sol.hpp:16752
static bool check(lua_State *L, int index, Handler &&handler, record &tracking)
Definition: sol.hpp:8222
static bool type_check_bases(types< Base, Args... >, const std::string &ti)
Definition: sol.hpp:6241
Definition: sol.hpp:5718
std::ptrdiff_t idx
Definition: sol.hpp:19912
static void set_default_handler(const T &ref)
Definition: sol.hpp:15140
static void select_convertible(types<>, lua_State *L, Fx &&fx, Args &&... args)
Definition: sol.hpp:14464
std::array< bool, 32 > properties
Definition: sol.hpp:19355
yielding_t(Arg0 &&arg0, Arg1 &&arg1, Args &&... args)
Definition: sol.hpp:4722
decltype(auto) check_get(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:7907
lua_bind_traits< std::remove_pointer_t< meta::unqualified_t< F > > > traits_type
Definition: sol.hpp:12630
bool runnable() const noexcept
Definition: sol.hpp:22072
static int new_index_call(lua_State *L)
Definition: sol.hpp:18994
int levels
Definition: sol.hpp:7631
Definition: sol.hpp:7607
stack_dependencies(int stack_target, Args &&... args)
Definition: sol.hpp:4575
optional< error > tagged_get(types< optional< error >>, int index_offset) const
Definition: sol.hpp:12242
unsafe_function function
Definition: sol.hpp:323
auto as_container(T &&value)
Definition: sol.hpp:16282
new_table(int sequence_hint, int map_hint=0)
Definition: sol.hpp:5097
lua_CFunction callconstructfunc
Definition: sol.hpp:18742
basic_userdata(const stack_reference &r)
Definition: sol.hpp:15846
std::tuple< Filters... > filters
Definition: sol.hpp:4599
basic_thread(lua_State *L, T &&r)
Definition: sol.hpp:21767
bool unqualified_check(lua_State *L, int index=-lua_size< meta::unqualified_t< T >>::value)
Definition: sol.hpp:7850