diff options
Diffstat (limited to 'src/compat.h')
-rw-r--r-- | src/compat.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h index eaa9f85..e44f827 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -5,13 +5,29 @@ | |||
5 | #include "lualib.h" | 5 | #include "lualib.h" |
6 | #include "lauxlib.h" | 6 | #include "lauxlib.h" |
7 | 7 | ||
8 | // try to detect if we are building against LuaJIT or MoonJIT | ||
9 | #if defined(LUA_JITLIBNAME) | ||
10 | #include "luajit.h" | ||
11 | #if (defined(__x86_64__) || defined(_M_X64) || defined(__LP64__)) | ||
12 | #define LUAJIT_FLAVOR() 64 | ||
13 | #else // 64 bits | ||
14 | #define LUAJIT_FLAVOR() 32 | ||
15 | #endif // 64 bits | ||
16 | #else // LUA_JITLIBNAME | ||
17 | #define LUAJIT_FLAVOR() 0 | ||
18 | #endif // LUA_JITLIBNAME | ||
19 | |||
20 | |||
8 | // code is now preferring Lua 5.4 API | 21 | // code is now preferring Lua 5.4 API |
9 | 22 | ||
10 | // add some Lua 5.3-style API when building for Lua 5.1 | 23 | // add some Lua 5.3-style API when building for Lua 5.1 |
11 | #if LUA_VERSION_NUM == 501 | 24 | #if LUA_VERSION_NUM == 501 |
25 | |||
12 | #define lua501_equal lua_equal | 26 | #define lua501_equal lua_equal |
13 | #define lua_absindex( L, idx) (((idx) >= 0 || (idx) <= LUA_REGISTRYINDEX) ? (idx) : lua_gettop(L) + (idx) +1) | 27 | #define lua_absindex( L, idx) (((idx) >= 0 || (idx) <= LUA_REGISTRYINDEX) ? (idx) : lua_gettop(L) + (idx) +1) |
28 | #if LUAJIT_VERSION_NUM < 20200 // moonjit is 5.1 plus bits of 5.2 that we don't need to wrap | ||
14 | #define lua_pushglobaltable(L) lua_pushvalue( L, LUA_GLOBALSINDEX) | 29 | #define lua_pushglobaltable(L) lua_pushvalue( L, LUA_GLOBALSINDEX) |
30 | #endif // LUAJIT_VERSION_NUM | ||
15 | #define lua_setuservalue lua_setfenv | 31 | #define lua_setuservalue lua_setfenv |
16 | #define lua_getuservalue lua_getfenv | 32 | #define lua_getuservalue lua_getfenv |
17 | #define lua_rawlen lua_objlen | 33 | #define lua_rawlen lua_objlen |
@@ -21,10 +37,12 @@ | |||
21 | void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources | 37 | void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources |
22 | #define lua504_dump( L, writer, data, strip) lua_dump( L, writer, data) | 38 | #define lua504_dump( L, writer, data, strip) lua_dump( L, writer, data) |
23 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.1 | 39 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.1 |
40 | |||
24 | #endif // LUA_VERSION_NUM == 501 | 41 | #endif // LUA_VERSION_NUM == 501 |
25 | 42 | ||
26 | // wrap Lua 5.2 calls under Lua 5.1 API when it is simpler that way | 43 | // wrap Lua 5.2 calls under Lua 5.1 API when it is simpler that way |
27 | #if LUA_VERSION_NUM == 502 | 44 | #if LUA_VERSION_NUM == 502 |
45 | |||
28 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h | 46 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h |
29 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | 47 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) |
30 | #endif // lua501_equal | 48 | #endif // lua501_equal |
@@ -34,10 +52,12 @@ void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int | |||
34 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | 52 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) |
35 | #define lua504_dump( L, writer, data, strip) lua_dump( L, writer, data) | 53 | #define lua504_dump( L, writer, data, strip) lua_dump( L, writer, data) |
36 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.2 | 54 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.2 |
55 | |||
37 | #endif // LUA_VERSION_NUM == 502 | 56 | #endif // LUA_VERSION_NUM == 502 |
38 | 57 | ||
39 | // wrap Lua 5.3 calls under Lua 5.1 API when it is simpler that way | 58 | // wrap Lua 5.3 calls under Lua 5.1 API when it is simpler that way |
40 | #if LUA_VERSION_NUM == 503 | 59 | #if LUA_VERSION_NUM == 503 |
60 | |||
41 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h | 61 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h |
42 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | 62 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) |
43 | #endif // lua501_equal | 63 | #endif // lua501_equal |
@@ -47,16 +67,20 @@ void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int | |||
47 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | 67 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) |
48 | #define lua504_dump lua_dump | 68 | #define lua504_dump lua_dump |
49 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | 69 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) |
70 | |||
50 | #endif // LUA_VERSION_NUM == 503 | 71 | #endif // LUA_VERSION_NUM == 503 |
51 | 72 | ||
52 | #if LUA_VERSION_NUM < 504 | 73 | #if LUA_VERSION_NUM < 504 |
74 | |||
53 | void *lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue); | 75 | void *lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue); |
54 | int lua_getiuservalue( lua_State* L, int idx, int n); | 76 | int lua_getiuservalue( lua_State* L, int idx, int n); |
55 | int lua_setiuservalue( lua_State* L, int idx, int n); | 77 | int lua_setiuservalue( lua_State* L, int idx, int n); |
78 | |||
56 | #endif // LUA_VERSION_NUM < 504 | 79 | #endif // LUA_VERSION_NUM < 504 |
57 | 80 | ||
58 | // wrap Lua 5.4 calls under Lua 5.1 API when it is simpler that way | 81 | // wrap Lua 5.4 calls under Lua 5.1 API when it is simpler that way |
59 | #if LUA_VERSION_NUM == 504 | 82 | #if LUA_VERSION_NUM == 504 |
83 | |||
60 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h | 84 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h |
61 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | 85 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) |
62 | #endif // lua501_equal | 86 | #endif // lua501_equal |
@@ -66,6 +90,7 @@ int lua_setiuservalue( lua_State* L, int idx, int n); | |||
66 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | 90 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) |
67 | #define lua504_dump lua_dump | 91 | #define lua504_dump lua_dump |
68 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | 92 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) |
93 | |||
69 | #endif // LUA_VERSION_NUM == 504 | 94 | #endif // LUA_VERSION_NUM == 504 |
70 | 95 | ||
71 | #endif // __COMPAT_H__ | 96 | #endif // __COMPAT_H__ |