civetweb_lua.h 2.9 KB

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