aboutsummaryrefslogtreecommitdiff
path: root/src/compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat.h')
-rw-r--r--src/compat.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h
new file mode 100644
index 0000000..a5801c4
--- /dev/null
+++ b/src/compat.h
@@ -0,0 +1,29 @@
1#if !defined( __COMPAT_H__)
2#define __COMPAT_H__ 1
3
4// code is now using Lua 5.2 API
5// add Lua 5.2 API when building for Lua 5.1
6#if LUA_VERSION_NUM == 501
7#define lua_absindex( L, idx) (((idx) >= 0 || (idx) <= LUA_REGISTRYINDEX) ? (idx) : lua_gettop(L) + (idx) +1)
8#define lua_pushglobaltable(L) lua_pushvalue( L, LUA_GLOBALSINDEX)
9#define lua_setuservalue lua_setfenv
10#define lua_getuservalue lua_getfenv
11#define lua_rawlen lua_objlen
12#define luaG_registerlibfuncs( L, _funcs) luaL_register( L, NULL, _funcs)
13#define LUA_OK 0
14#define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value
15void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources
16#endif // LUA_VERSION_NUM == 501
17
18// wrap Lua 5.2 calls under Lua 5.1 API when it is simpler that way
19#if LUA_VERSION_NUM == 502
20#ifndef lua_equal // already defined when compatibility is active in luaconf.h
21#define lua_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ)
22#endif // lua_equal
23#ifndef lua_lessthan // already defined when compatibility is active in luaconf.h
24#define lua_lessthan( L, a, b) lua_compare( L, a, b, LUA_OPLT)
25#endif // lua_lessthan
26#define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0)
27#endif // LUA_VERSION_NUM == 502
28
29#endif // __COMPAT_H__