civetweb_lua.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (c) 2015-2021 the Civetweb developers
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. /* This header is intended to support Lua 5.1, Lua 5.2 and Lua 5.3 in the same
  22. * C source code.
  23. */
  24. #ifndef CIVETWEB_LUA_H
  25. #define CIVETWEB_LUA_H
  26. #define LUA_LIB
  27. #define LUA_COMPAT_LOG10
  28. #define LUA_COMPAT_APIINTCASTS
  29. #if defined(__cplusplus)
  30. extern "C" {
  31. #endif
  32. #include "lauxlib.h"
  33. #include "lua.h"
  34. #include "lualib.h"
  35. #if defined(__cplusplus)
  36. } /* extern "C" */
  37. #endif
  38. #ifndef LUA_VERSION_NUM
  39. #error "Unknown Lua version"
  40. #elif LUA_VERSION_NUM == 501
  41. /* Lua 5.1 detected */
  42. #define LUA_OK 0
  43. #define LUA_ERRGCMM 999 /* not supported */
  44. #define mg_lua_load(a, b, c, d, e) lua_load(a, b, c, d)
  45. #define lua_rawlen lua_objlen
  46. #define lua_newstate(a, b) \
  47. luaL_newstate() /* Must use luaL_newstate() for 64 bit target */
  48. #define lua_pushinteger lua_pushnumber
  49. #define luaL_newlib(L, t) \
  50. { \
  51. luaL_Reg const *r = t; \
  52. while (r->name) { \
  53. lua_register(L, r->name, r->func); \
  54. r++; \
  55. } \
  56. }
  57. #define luaL_setfuncs(L, r, u) lua_register(L, r->name, r->func)
  58. #elif LUA_VERSION_NUM == 502
  59. /* Lua 5.2 detected */
  60. #define mg_lua_load lua_load
  61. #elif LUA_VERSION_NUM == 503
  62. /* Lua 5.3 detected */
  63. #define mg_lua_load lua_load
  64. #elif LUA_VERSION_NUM == 504
  65. /* Lua 5.4 detected */
  66. #define mg_lua_load lua_load
  67. #else
  68. #error "Lua version not supported (yet?)"
  69. #endif
  70. #if defined(LUA_VERSION_MAKEFILE)
  71. #if LUA_VERSION_MAKEFILE != LUA_VERSION_NUM
  72. #error \
  73. "Mismatch between Lua version specified in Makefile and Lua version in lua.h"
  74. #endif
  75. #endif
  76. #endif /* #ifndef CIVETWEB_LUA_H */