lua_version.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_COMPATIBILITY_LUA_VERSION_HPP
  19. #define SOL_COMPATIBILITY_LUA_VERSION_HPP
  20. #include <sol/version.hpp>
  21. // clang-format off
  22. #if SOL_IS_ON(SOL_USING_CXX_LUA)
  23. #include <lua.h>
  24. #include <lualib.h>
  25. #include <lauxlib.h>
  26. #elif SOL_IS_ON(SOL_USE_LUA_HPP)
  27. #include <lua.hpp>
  28. #else
  29. extern "C" {
  30. #include <lua.h>
  31. #include <lauxlib.h>
  32. #include <lualib.h>
  33. }
  34. #endif // C++ Mangling for Lua vs. Not
  35. #if defined(SOL_LUAJIT)
  36. #if (SOL_LUAJIT != 0)
  37. #define SOL_USE_LUAJIT_I_ SOL_ON
  38. #else
  39. #define SOL_USE_LUAJIT_I_ SOL_OFF
  40. #endif
  41. #elif defined(LUAJIT_VERSION)
  42. #define SOL_USE_LUAJIT_I_ SOL_ON
  43. #else
  44. #define SOL_USE_LUAJIT_I_ SOL_DEFAULT_OFF
  45. #endif // luajit
  46. #if SOL_IS_ON(SOL_USING_CXX_LUAJIT)
  47. #include <luajit.h>
  48. #elif SOL_IS_ON(SOL_USE_LUAJIT)
  49. extern "C" {
  50. #include <luajit.h>
  51. }
  52. #endif // C++ LuaJIT ... whatever that means
  53. #if defined(SOL_LUAJIT_VERSION)
  54. #define SOL_LUAJIT_VERSION_I_ SOL_LUAJIT_VERSION
  55. #elif SOL_IS_ON(SOL_USE_LUAJIT)
  56. #define SOL_LUAJIT_VERSION_I_ LUAJIT_VERSION_NUM
  57. #else
  58. #define SOL_LUAJIT_VERSION_I_ 0
  59. #endif
  60. #if defined(SOL_LUAJIT_FFI_DISABLED)
  61. #define SOL_LUAJIT_FFI_DISABLED_I_ SOL_ON
  62. #elif defined(LUAJIT_DISABLE_FFI)
  63. #define SOL_LUAJIT_FFI_DISABLED_I_ SOL_ON
  64. #else
  65. #define SOL_LUAJIT_FFI_DISABLED_I_ SOL_DEFAULT_OFF
  66. #endif
  67. #if defined(MOONJIT_VERSION)
  68. #define SOL_USE_MOONJIT_I_ SOL_ON
  69. #else
  70. #define SOL_USE_MOONJIT_I_ SOL_OFF
  71. #endif
  72. #if !defined(SOL_LUA_VERSION)
  73. #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502
  74. #define SOL_LUA_VERSION LUA_VERSION_NUM
  75. #elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
  76. #define SOL_LUA_VERSION LUA_VERSION_NUM
  77. #elif !defined(LUA_VERSION_NUM) || !(LUA_VERSION_NUM)
  78. // Definitely 5.0
  79. #define SOL_LUA_VERSION 500
  80. #else
  81. // ??? Not sure, assume latest?
  82. #define SOL_LUA_VERSION 504
  83. #endif // Lua Version 503, 502, 501 || luajit, 500
  84. #endif // SOL_LUA_VERSION
  85. #if defined(SOL_LUA_VERSION)
  86. #define SOL_LUA_VERSION_I_ SOL_LUA_VERSION
  87. #else
  88. #define SOL_LUA_VERSION_I_ 504
  89. #endif
  90. // Exception safety / propagation, according to Lua information
  91. // and user defines. Note this can sometimes change based on version information...
  92. #if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE)
  93. #if (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0)
  94. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
  95. #else
  96. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON
  97. #endif
  98. #elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
  99. #if (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0)
  100. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON
  101. #else
  102. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
  103. #endif
  104. #elif SOL_LUAJIT_VERSION_I_ >= 20100
  105. // LuaJIT 2.1.0-beta3 and better have exception support locked in for all platforms (mostly)
  106. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_ON
  107. #elif SOL_LUAJIT_VERSION_I_ >= 20000
  108. // LuaJIT 2.0.x have exception support only on x64 builds
  109. #if SOL_IS_ON(SOL_PLATFORM_X64)
  110. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_ON
  111. #else
  112. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
  113. #endif
  114. #else
  115. // otherwise, there is no exception safety for
  116. // shoving exceptions through Lua and errors should
  117. // always be serialized
  118. #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_OFF
  119. #endif
  120. // Some configurations work with exceptions,
  121. // but cannot catch-all everything...
  122. #if defined(SOL_EXCEPTIONS_CATCH_ALL)
  123. #if (SOL_EXCEPTIONS_CATCH_ALL != 0)
  124. #define SOL_EXCEPTIONS_CATCH_ALL_I_ SOL_ON
  125. #else
  126. #define SOL_EXCEPTIONS_CATCH_ALL_I_ SOL_OFF
  127. #endif
  128. #else
  129. #if SOL_IS_ON(SOL_USE_LUAJIT)
  130. #define SOL_EXCEPTIONS_CATCH_ALL_I_ SOL_DEFAULT_OFF
  131. #elif SOL_IS_ON(SOL_USING_CXX_LUAJIT)
  132. #define SOL_EXCEPTIONS_CATCH_ALL_I_ SOL_DEFAULT_OFF
  133. #elif SOL_IS_ON(SOL_USING_CXX_LUA)
  134. #define SOL_EXCEPTIONS_CATCH_ALL_I_ SOL_DEFAULT_OFF
  135. #else
  136. #define SOL_EXCEPTIONS_CATCH_ALL_I_ SOL_DEFAULT_ON
  137. #endif
  138. #endif
  139. #if defined(SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE)
  140. #if (SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE != 0)
  141. #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON
  142. #else
  143. #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_OFF
  144. #endif
  145. #else
  146. #if SOL_IS_OFF(SOL_PROPAGATE_EXCEPTIONS) && SOL_IS_ON(SOL_USE_LUAJIT)
  147. #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON
  148. #else
  149. #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_DEFAULT_OFF
  150. #endif
  151. #endif
  152. #if defined(SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION)
  153. #if (SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION != 0)
  154. #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON
  155. #else
  156. #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_OFF
  157. #endif
  158. #else
  159. #if SOL_IS_OFF(SOL_USE_LUAJIT) && (SOL_LUA_VERSION > 501)
  160. #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON
  161. #else
  162. #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_DEFAULT_OFF
  163. #endif
  164. #endif
  165. #if defined (SOL_LUA_BIT32_LIB)
  166. #if SOL_LUA_BIT32_LIB != 0
  167. #define SOL_LUA_BIT32_LIB_I_ SOL_ON
  168. #else
  169. #define SOL_LUA_BIT32_LIB_I_ SOL_OFF
  170. #endif
  171. #else
  172. // Lua 5.2 only (deprecated in 5.3 (503)) (Can be turned on with Compat flags)
  173. // Lua 5.2, or other versions of Lua with the compat flag, or Lua that is not 5.2 with the specific define (5.4.1 either removed it entirely or broke it)
  174. #if (SOL_LUA_VERSION_I_ == 502)
  175. #define SOL_LUA_BIT32_LIB_I_ SOL_ON
  176. #elif defined(LUA_COMPAT_BITLIB)
  177. #define SOL_LUA_BIT32_LIB_I_ SOL_ON
  178. #elif (SOL_LUA_VERSION_I_ < 504 && defined(LUA_COMPAT_5_2))
  179. #define SOL_LUA_BIT32_LIB_I_ SOL_ON
  180. #else
  181. #define SOL_LUA_BIT32_LIB_I_ SOL_DEFAULT_OFF
  182. #endif
  183. #endif
  184. #if defined (SOL_LUA_NIL_IN_TABLES)
  185. #if SOL_LUA_NIL_IN_TABLES != 0
  186. #define SOL_LUA_NIL_IN_TABLES_I_ SOL_ON
  187. #else
  188. #define SOL_LUA_NIL_IN_TABLES_I_ SOL_OFF
  189. #endif
  190. #else
  191. #if defined(LUA_NILINTABLE) && (LUA_NILINTABLE != 0)
  192. #define SOL_LUA_NIL_IN_TABLES_I_ SOL_DEFAULT_ON
  193. #else
  194. #define SOL_LUA_NIL_IN_TABLES_I_ SOL_DEFAULT_OFF
  195. #endif
  196. #endif
  197. // clang-format on
  198. #endif // SOL_COMPATIBILITY_LUA_VERSION_HPP