diff options
author | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-04-03 16:23:52 +0200 |
---|---|---|
committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-04-03 16:23:52 +0200 |
commit | d8cfb248939a9b6e1cbc9bb4c05b216daf9a0e3a (patch) | |
tree | 980974d5ab0e9b3b10dbc588d3a8954ecadccc07 | |
parent | aa9bfcf2dd49f55f11b27e7c21d5b75d81ccfc7e (diff) | |
download | lanes-d8cfb248939a9b6e1cbc9bb4c05b216daf9a0e3a.tar.gz lanes-d8cfb248939a9b6e1cbc9bb4c05b216daf9a0e3a.tar.bz2 lanes-d8cfb248939a9b6e1cbc9bb4c05b216daf9a0e3a.zip |
moved compatibility code in a separate file
-rw-r--r-- | lanes-3.9.4-1.rockspec | 2 | ||||
-rw-r--r-- | src/compat.c | 44 | ||||
-rw-r--r-- | src/compat.h | 29 | ||||
-rw-r--r-- | src/lanes.c | 1 | ||||
-rw-r--r-- | src/tools.c | 43 | ||||
-rw-r--r-- | src/tools.h | 25 |
6 files changed, 75 insertions, 69 deletions
diff --git a/lanes-3.9.4-1.rockspec b/lanes-3.9.4-1.rockspec index fcee525..f5f7e83 100644 --- a/lanes-3.9.4-1.rockspec +++ b/lanes-3.9.4-1.rockspec | |||
@@ -58,7 +58,7 @@ build = { | |||
58 | { | 58 | { |
59 | ["lanes.core"] = | 59 | ["lanes.core"] = |
60 | { | 60 | { |
61 | sources = { "src/lanes.c", "src/keeper.c", "src/tools.c", "src/threading.c"}, | 61 | sources = { "src/compat.c", "src/lanes.c", "src/keeper.c", "src/tools.c", "src/threading.c"}, |
62 | incdirs = { "src"}, | 62 | incdirs = { "src"}, |
63 | }, | 63 | }, |
64 | lanes = "src/lanes.lua" | 64 | lanes = "src/lanes.lua" |
diff --git a/src/compat.c b/src/compat.c new file mode 100644 index 0000000..1a66f38 --- /dev/null +++ b/src/compat.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
2 | * ############################################################################################### | ||
3 | * ######################################### Lua 5.1/5.2 ######################################### | ||
4 | * ############################################################################################### | ||
5 | */ | ||
6 | #include "compat.h" | ||
7 | |||
8 | /* | ||
9 | ** Copied from Lua 5.2 loadlib.c | ||
10 | */ | ||
11 | #if LUA_VERSION_NUM == 501 | ||
12 | static int luaL_getsubtable (lua_State *L, int idx, const char *fname) | ||
13 | { | ||
14 | lua_getfield(L, idx, fname); | ||
15 | if (lua_istable(L, -1)) | ||
16 | return 1; /* table already there */ | ||
17 | else | ||
18 | { | ||
19 | lua_pop(L, 1); /* remove previous result */ | ||
20 | idx = lua_absindex(L, idx); | ||
21 | lua_newtable(L); | ||
22 | lua_pushvalue(L, -1); /* copy to be left at top */ | ||
23 | lua_setfield(L, idx, fname); /* assign new table to field */ | ||
24 | return 0; /* false, because did not find table there */ | ||
25 | } | ||
26 | } | ||
27 | |||
28 | void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) | ||
29 | { | ||
30 | lua_pushcfunction(L, openf); | ||
31 | lua_pushstring(L, modname); /* argument to open function */ | ||
32 | lua_call(L, 1, 1); /* open module */ | ||
33 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); | ||
34 | lua_pushvalue(L, -2); /* make copy of module (call result) */ | ||
35 | lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ | ||
36 | lua_pop(L, 1); /* remove _LOADED table */ | ||
37 | if (glb) | ||
38 | { | ||
39 | lua_pushvalue(L, -1); /* copy of 'mod' */ | ||
40 | lua_setglobal(L, modname); /* _G[modname] = module */ | ||
41 | } | ||
42 | } | ||
43 | #endif // LUA_VERSION_NUM | ||
44 | |||
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 | ||
15 | void 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__ | ||
diff --git a/src/lanes.c b/src/lanes.c index 9e79f64..5f2f492 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -90,6 +90,7 @@ THE SOFTWARE. | |||
90 | #include "lauxlib.h" | 90 | #include "lauxlib.h" |
91 | 91 | ||
92 | #include "threading.h" | 92 | #include "threading.h" |
93 | #include "compat.h" | ||
93 | #include "tools.h" | 94 | #include "tools.h" |
94 | #include "keeper.h" | 95 | #include "keeper.h" |
95 | #include "lanes.h" | 96 | #include "lanes.h" |
diff --git a/src/tools.c b/src/tools.c index ea7662b..d2b316b 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -64,49 +64,6 @@ void ASSERT_IMPL( lua_State* L, bool_t cond_, char const* file_, int const line_ | |||
64 | char const* const CONFIG_REGKEY = "ee932492-a654-4506-9da8-f16540bdb5d4"; | 64 | char const* const CONFIG_REGKEY = "ee932492-a654-4506-9da8-f16540bdb5d4"; |
65 | char const* const LOOKUP_REGKEY = "ddea37aa-50c7-4d3f-8e0b-fb7a9d62bac5"; | 65 | char const* const LOOKUP_REGKEY = "ddea37aa-50c7-4d3f-8e0b-fb7a9d62bac5"; |
66 | 66 | ||
67 | /* | ||
68 | * ############################################################################################### | ||
69 | * ######################################### Lua 5.1/5.2 ######################################### | ||
70 | * ############################################################################################### | ||
71 | */ | ||
72 | |||
73 | /* | ||
74 | ** Copied from Lua 5.2 loadlib.c | ||
75 | */ | ||
76 | #if LUA_VERSION_NUM == 501 | ||
77 | static int luaL_getsubtable (lua_State *L, int idx, const char *fname) | ||
78 | { | ||
79 | lua_getfield(L, idx, fname); | ||
80 | if (lua_istable(L, -1)) | ||
81 | return 1; /* table already there */ | ||
82 | else | ||
83 | { | ||
84 | lua_pop(L, 1); /* remove previous result */ | ||
85 | idx = lua_absindex(L, idx); | ||
86 | lua_newtable(L); | ||
87 | lua_pushvalue(L, -1); /* copy to be left at top */ | ||
88 | lua_setfield(L, idx, fname); /* assign new table to field */ | ||
89 | return 0; /* false, because did not find table there */ | ||
90 | } | ||
91 | } | ||
92 | |||
93 | void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) | ||
94 | { | ||
95 | lua_pushcfunction(L, openf); | ||
96 | lua_pushstring(L, modname); /* argument to open function */ | ||
97 | lua_call(L, 1, 1); /* open module */ | ||
98 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); | ||
99 | lua_pushvalue(L, -2); /* make copy of module (call result) */ | ||
100 | lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ | ||
101 | lua_pop(L, 1); /* remove _LOADED table */ | ||
102 | if (glb) | ||
103 | { | ||
104 | lua_pushvalue(L, -1); /* copy of 'mod' */ | ||
105 | lua_setglobal(L, modname); /* _G[modname] = module */ | ||
106 | } | ||
107 | } | ||
108 | #endif // LUA_VERSION_NUM | ||
109 | |||
110 | DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); | 67 | DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); |
111 | 68 | ||
112 | 69 | ||
diff --git a/src/tools.h b/src/tools.h index 708421c..8e8bb7d 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -16,31 +16,6 @@ | |||
16 | #define inline __inline | 16 | #define inline __inline |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | // code is now using Lua 5.2 API | ||
20 | // add Lua 5.2 API when building for Lua 5.1 | ||
21 | #if LUA_VERSION_NUM == 501 | ||
22 | #define lua_absindex( L, idx) (((idx) >= 0 || (idx) <= LUA_REGISTRYINDEX) ? (idx) : lua_gettop(L) + (idx) +1) | ||
23 | #define lua_pushglobaltable(L) lua_pushvalue( L, LUA_GLOBALSINDEX) | ||
24 | #define lua_setuservalue lua_setfenv | ||
25 | #define lua_getuservalue lua_getfenv | ||
26 | #define lua_rawlen lua_objlen | ||
27 | #define luaG_registerlibfuncs( L, _funcs) luaL_register( L, NULL, _funcs) | ||
28 | #define LUA_OK 0 | ||
29 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value | ||
30 | void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources | ||
31 | #endif // LUA_VERSION_NUM == 501 | ||
32 | |||
33 | // wrap Lua 5.2 calls under Lua 5.1 API when it is simpler that way | ||
34 | #if LUA_VERSION_NUM == 502 | ||
35 | #ifndef lua_equal // already defined when compatibility is active in luaconf.h | ||
36 | #define lua_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | ||
37 | #endif // lua_equal | ||
38 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h | ||
39 | #define lua_lessthan( L, a, b) lua_compare( L, a, b, LUA_OPLT) | ||
40 | #endif // lua_lessthan | ||
41 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | ||
42 | #endif // LUA_VERSION_NUM == 502 | ||
43 | |||
44 | // For some reason, LuaJIT 64bits doesn't support lua_newstate() | 19 | // For some reason, LuaJIT 64bits doesn't support lua_newstate() |
45 | // If you build specifically for this situation, change value to 0 | 20 | // If you build specifically for this situation, change value to 0 |
46 | #define PROPAGATE_ALLOCF 1 | 21 | #define PROPAGATE_ALLOCF 1 |