civetweb_lua.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (c) 2015-2020 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. #include "lauxlib.h"
  30. #include "lua.h"
  31. #include "lualib.h"
  32. #ifndef LUA_VERSION_NUM
  33. #error "Unknown Lua version"
  34. #elif LUA_VERSION_NUM == 501
  35. /* Lua 5.1 detected */
  36. #define LUA_OK 0
  37. #define LUA_ERRGCMM 999 /* not supported */
  38. #define mg_lua_load(a, b, c, d, e) lua_load(a, b, c, d)
  39. #define lua_rawlen lua_objlen
  40. #define lua_newstate(a, b) \
  41. luaL_newstate() /* Must use luaL_newstate() for 64 bit target */
  42. #define lua_pushinteger lua_pushnumber
  43. #define luaL_newlib(L, t) \
  44. { \
  45. luaL_Reg const *r = t; \
  46. while (r->name) { \
  47. lua_register(L, r->name, r->func); \
  48. r++; \
  49. } \
  50. }
  51. #define luaL_setfuncs(L, r, u) lua_register(L, r->name, r->func)
  52. #elif LUA_VERSION_NUM == 502
  53. /* Lua 5.2 detected */
  54. #define mg_lua_load lua_load
  55. #elif LUA_VERSION_NUM == 503
  56. /* Lua 5.3 detected */
  57. #define mg_lua_load lua_load
  58. #elif LUA_VERSION_NUM == 504
  59. /* Lua 5.4 detected */
  60. #define mg_lua_load lua_load
  61. #else
  62. #error "Lua version not supported (yet?)"
  63. #endif
  64. #if defined(LUA_VERSION_MAKEFILE)
  65. #if LUA_VERSION_MAKEFILE != LUA_VERSION_NUM
  66. #error \
  67. "Mismatch between Lua version specified in Makefile and Lua version in lua.h"
  68. #endif
  69. #endif
  70. #endif /* #ifndef CIVETWEB_LUA_H */