forward.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // sol2
  2. // The MIT License (MIT)
  3. // Copyright (c) 2013-2022 Rapptz, ThePhD and contributors
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. // this software and associated documentation files (the "Software"), to deal in
  6. // the Software without restriction, including without limitation the rights to
  7. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. // the Software, and to permit persons to whom the Software is furnished to do so,
  9. // subject to the following conditions:
  10. // The above copyright notice and this permission notice shall be included in all
  11. // copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #ifndef SOL_FORWARD_HPP
  19. #define SOL_FORWARD_HPP
  20. #include <sol/version.hpp>
  21. #include <utility>
  22. #include <type_traits>
  23. #include <string_view>
  24. #if SOL_IS_ON(SOL_USING_CXX_LUA) || SOL_IS_ON(SOL_USING_CXX_LUAJIT)
  25. struct lua_State;
  26. #else
  27. extern "C" {
  28. struct lua_State;
  29. }
  30. #endif // C++ Mangling for Lua vs. Not
  31. namespace sol {
  32. enum class type;
  33. class stateless_reference;
  34. template <bool b>
  35. class basic_reference;
  36. using reference = basic_reference<false>;
  37. using main_reference = basic_reference<true>;
  38. class stateless_stack_reference;
  39. class stack_reference;
  40. template <typename A>
  41. class basic_bytecode;
  42. struct lua_value;
  43. struct proxy_base_tag;
  44. template <typename>
  45. struct proxy_base;
  46. template <typename, typename>
  47. struct table_proxy;
  48. template <bool, typename>
  49. class basic_table_core;
  50. template <bool b>
  51. using table_core = basic_table_core<b, reference>;
  52. template <bool b>
  53. using main_table_core = basic_table_core<b, main_reference>;
  54. template <bool b>
  55. using stack_table_core = basic_table_core<b, stack_reference>;
  56. template <typename base_type>
  57. using basic_table = basic_table_core<false, base_type>;
  58. using table = table_core<false>;
  59. using global_table = table_core<true>;
  60. using main_table = main_table_core<false>;
  61. using main_global_table = main_table_core<true>;
  62. using stack_table = stack_table_core<false>;
  63. using stack_global_table = stack_table_core<true>;
  64. template <typename>
  65. struct basic_lua_table;
  66. using lua_table = basic_lua_table<reference>;
  67. using stack_lua_table = basic_lua_table<stack_reference>;
  68. template <typename T, typename base_type>
  69. class basic_usertype;
  70. template <typename T>
  71. using usertype = basic_usertype<T, reference>;
  72. template <typename T>
  73. using stack_usertype = basic_usertype<T, stack_reference>;
  74. template <typename base_type>
  75. class basic_metatable;
  76. using metatable = basic_metatable<reference>;
  77. using stack_metatable = basic_metatable<stack_reference>;
  78. template <typename base_t>
  79. struct basic_environment;
  80. using environment = basic_environment<reference>;
  81. using main_environment = basic_environment<main_reference>;
  82. using stack_environment = basic_environment<stack_reference>;
  83. template <typename T, bool>
  84. class basic_function;
  85. template <typename T, bool, typename H>
  86. class basic_protected_function;
  87. using unsafe_function = basic_function<reference, false>;
  88. using safe_function = basic_protected_function<reference, false, reference>;
  89. using main_unsafe_function = basic_function<main_reference, false>;
  90. using main_safe_function = basic_protected_function<main_reference, false, reference>;
  91. using stack_unsafe_function = basic_function<stack_reference, false>;
  92. using stack_safe_function = basic_protected_function<stack_reference, false, reference>;
  93. using stack_aligned_unsafe_function = basic_function<stack_reference, true>;
  94. using stack_aligned_safe_function = basic_protected_function<stack_reference, true, reference>;
  95. using protected_function = safe_function;
  96. using main_protected_function = main_safe_function;
  97. using stack_protected_function = stack_safe_function;
  98. using stack_aligned_protected_function = stack_aligned_safe_function;
  99. #if SOL_IS_ON(SOL_SAFE_FUNCTION_OBJECTS)
  100. using function = protected_function;
  101. using main_function = main_protected_function;
  102. using stack_function = stack_protected_function;
  103. using stack_aligned_function = stack_aligned_safe_function;
  104. #else
  105. using function = unsafe_function;
  106. using main_function = main_unsafe_function;
  107. using stack_function = stack_unsafe_function;
  108. using stack_aligned_function = stack_aligned_unsafe_function;
  109. #endif
  110. using stack_aligned_stack_handler_function = basic_protected_function<stack_reference, true, stack_reference>;
  111. struct unsafe_function_result;
  112. struct protected_function_result;
  113. using safe_function_result = protected_function_result;
  114. #if SOL_IS_ON(SOL_SAFE_FUNCTION_OBJECTS)
  115. using function_result = safe_function_result;
  116. #else
  117. using function_result = unsafe_function_result;
  118. #endif
  119. template <typename base_t>
  120. class basic_object_base;
  121. template <typename base_t>
  122. class basic_object;
  123. template <typename base_t>
  124. class basic_userdata;
  125. template <typename base_t>
  126. class basic_lightuserdata;
  127. template <typename base_t>
  128. class basic_coroutine;
  129. template <typename base_t>
  130. class basic_packaged_coroutine;
  131. template <typename base_t>
  132. class basic_thread;
  133. using object = basic_object<reference>;
  134. using userdata = basic_userdata<reference>;
  135. using lightuserdata = basic_lightuserdata<reference>;
  136. using thread = basic_thread<reference>;
  137. using coroutine = basic_coroutine<reference>;
  138. using packaged_coroutine = basic_packaged_coroutine<reference>;
  139. using main_object = basic_object<main_reference>;
  140. using main_userdata = basic_userdata<main_reference>;
  141. using main_lightuserdata = basic_lightuserdata<main_reference>;
  142. using main_coroutine = basic_coroutine<main_reference>;
  143. using stack_object = basic_object<stack_reference>;
  144. using stack_userdata = basic_userdata<stack_reference>;
  145. using stack_lightuserdata = basic_lightuserdata<stack_reference>;
  146. using stack_thread = basic_thread<stack_reference>;
  147. using stack_coroutine = basic_coroutine<stack_reference>;
  148. struct stack_proxy_base;
  149. struct stack_proxy;
  150. struct variadic_args;
  151. struct variadic_results;
  152. struct stack_count;
  153. struct this_state;
  154. struct this_main_state;
  155. struct this_environment;
  156. class state_view;
  157. class state;
  158. template <typename T>
  159. struct as_table_t;
  160. template <typename T>
  161. struct as_container_t;
  162. template <typename T>
  163. struct nested;
  164. template <typename T>
  165. struct light;
  166. template <typename T>
  167. struct user;
  168. template <typename T>
  169. struct as_args_t;
  170. template <typename T>
  171. struct protect_t;
  172. template <typename F, typename... Policies>
  173. struct policy_wrapper;
  174. template <typename T>
  175. struct usertype_traits;
  176. template <typename T>
  177. struct unique_usertype_traits;
  178. template <typename... Args>
  179. struct types {
  180. typedef std::make_index_sequence<sizeof...(Args)> indices;
  181. static constexpr std::size_t size() {
  182. return sizeof...(Args);
  183. }
  184. };
  185. template <typename T>
  186. struct derive : std::false_type {
  187. typedef types<> type;
  188. };
  189. template <typename T>
  190. struct base : std::false_type {
  191. typedef types<> type;
  192. };
  193. template <typename T>
  194. struct weak_derive {
  195. static bool value;
  196. };
  197. template <typename T>
  198. bool weak_derive<T>::value = false;
  199. namespace stack {
  200. struct record;
  201. }
  202. #if SOL_IS_OFF(SOL_USE_BOOST)
  203. template <class T>
  204. class optional;
  205. template <class T>
  206. class optional<T&>;
  207. #endif
  208. using check_handler_type = int(lua_State*, int, type, type, const char*);
  209. } // namespace sol
  210. #define SOL_BASE_CLASSES(T, ...) \
  211. namespace sol { \
  212. template <> \
  213. struct base<T> : std::true_type { \
  214. typedef ::sol::types<__VA_ARGS__> type; \
  215. }; \
  216. } \
  217. static_assert(true, "")
  218. #define SOL_DERIVED_CLASSES(T, ...) \
  219. namespace sol { \
  220. template <> \
  221. struct derive<T> : std::true_type { \
  222. typedef ::sol::types<__VA_ARGS__> type; \
  223. }; \
  224. } \
  225. static_assert(true, "")
  226. #endif // SOL_FORWARD_HPP