diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2017-08-07 20:22:18 +0200 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2017-08-07 20:22:18 +0200 |
| commit | f608371c71644f5db60a3c83b2c7a44f1eb30eea (patch) | |
| tree | c98a08855a0006843772e57a68c1b6dd30a8a419 | |
| parent | 8b2d71e601d1b9695aea084bb5bf7aa7dc0ca230 (diff) | |
| download | lua-compat-5.3-f608371c71644f5db60a3c83b2c7a44f1eb30eea.tar.gz lua-compat-5.3-f608371c71644f5db60a3c83b2c7a44f1eb30eea.tar.bz2 lua-compat-5.3-f608371c71644f5db60a3c83b2c7a44f1eb30eea.zip | |
Fix compilation issues with recent LuaJIT 2.1.
Protect macros with `#ifndef`.
Use "compat53" prefix instead of "lua" prefix for the mode where
static versions of the C API functions are created.
Fixes #19.
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | c-api/compat-5.3.c | 2 | ||||
| -rw-r--r-- | c-api/compat-5.3.h | 63 |
3 files changed, 44 insertions, 27 deletions
| @@ -72,7 +72,11 @@ your project: | |||
| 72 | compatibility functions in your code. You have to compile and link | 72 | compatibility functions in your code. You have to compile and link |
| 73 | `compat-5.3.c` to your project yourself. You can change the way the | 73 | `compat-5.3.c` to your project yourself. You can change the way the |
| 74 | functions are exported using the `COMPAT53_API` macro (e.g. if you need | 74 | functions are exported using the `COMPAT53_API` macro (e.g. if you need |
| 75 | some `__declspec` magic). | 75 | some `__declspec` magic). While it is technically possible to use |
| 76 | the "lua" prefix (and it looks better in the debugger), this is | ||
| 77 | discouraged because LuaJIT has started to implement its own Lua 5.2+ | ||
| 78 | C API functions, and with the "lua" prefix you'd violate the | ||
| 79 | one-definition rule with recent LuaJIT versions. | ||
| 76 | 80 | ||
| 77 | ## What's implemented | 81 | ## What's implemented |
| 78 | 82 | ||
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index d7d127f..b913196 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
| @@ -263,7 +263,6 @@ COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | |||
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | 265 | ||
| 266 | #if !defined(COMPAT53_IS_LUAJIT) | ||
| 267 | static int compat53_countlevels (lua_State *L) { | 266 | static int compat53_countlevels (lua_State *L) { |
| 268 | lua_Debug ar; | 267 | lua_Debug ar; |
| 269 | int li = 1, le = 1; | 268 | int li = 1, le = 1; |
| @@ -418,7 +417,6 @@ COMPAT53_API int luaL_execresult (lua_State *L, int stat) { | |||
| 418 | return 3; | 417 | return 3; |
| 419 | } | 418 | } |
| 420 | } | 419 | } |
| 421 | #endif /* not COMPAT53_IS_LUAJIT */ | ||
| 422 | 420 | ||
| 423 | 421 | ||
| 424 | COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B) { | 422 | COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B) { |
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index ba90d81..0083eb4 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h | |||
| @@ -24,10 +24,9 @@ extern "C" { | |||
| 24 | # undef COMPAT53_INCLUDE_SOURCE | 24 | # undef COMPAT53_INCLUDE_SOURCE |
| 25 | #else /* COMPAT53_PREFIX */ | 25 | #else /* COMPAT53_PREFIX */ |
| 26 | /* - make all functions static and include the source. | 26 | /* - make all functions static and include the source. |
| 27 | * - don't mess with the symbol names of functions | ||
| 28 | * - compat-5.3.c doesn't need to be compiled (and linked) separately | 27 | * - compat-5.3.c doesn't need to be compiled (and linked) separately |
| 29 | */ | 28 | */ |
| 30 | # define COMPAT53_PREFIX lua | 29 | # define COMPAT53_PREFIX compat53 |
| 31 | # undef COMPAT53_API | 30 | # undef COMPAT53_API |
| 32 | # if defined(__GNUC__) || defined(__clang__) | 31 | # if defined(__GNUC__) || defined(__clang__) |
| 33 | # define COMPAT53_API __attribute__((__unused__)) static | 32 | # define COMPAT53_API __attribute__((__unused__)) static |
| @@ -55,25 +54,39 @@ extern "C" { | |||
| 55 | * luaL_loadfilex | 54 | * luaL_loadfilex |
| 56 | */ | 55 | */ |
| 57 | 56 | ||
| 58 | /* PUC-Rio Lua uses lconfig_h as include guard for luaconf.h, | 57 | #ifndef LUA_OK |
| 59 | * LuaJIT uses luaconf_h. If you use PUC-Rio's include files | 58 | # define LUA_OK 0 |
| 60 | * but LuaJIT's library, you will need to define the macro | 59 | #endif |
| 61 | * COMPAT53_IS_LUAJIT yourself! */ | 60 | #ifndef LUA_OPADD |
| 62 | #if !defined(COMPAT53_IS_LUAJIT) && defined(luaconf_h) | 61 | # define LUA_OPADD 0 |
| 63 | # define COMPAT53_IS_LUAJIT | 62 | #endif |
| 63 | #ifndef LUA_OPSUB | ||
| 64 | # define LUA_OPSUB 1 | ||
| 65 | #endif | ||
| 66 | #ifndef LUA_OPMUL | ||
| 67 | # define LUA_OPMUL 2 | ||
| 68 | #endif | ||
| 69 | #ifndef LUA_OPDIV | ||
| 70 | # define LUA_OPDIV 3 | ||
| 71 | #endif | ||
| 72 | #ifndef LUA_OPMOD | ||
| 73 | # define LUA_OPMOD 4 | ||
| 74 | #endif | ||
| 75 | #ifndef LUA_OPPOW | ||
| 76 | # define LUA_OPPOW 5 | ||
| 77 | #endif | ||
| 78 | #ifndef LUA_OPUNM | ||
| 79 | # define LUA_OPUNM 6 | ||
| 80 | #endif | ||
| 81 | #ifndef LUA_OPEQ | ||
| 82 | # define LUA_OPEQ 0 | ||
| 83 | #endif | ||
| 84 | #ifndef LUA_OPLT | ||
| 85 | # define LUA_OPLT 1 | ||
| 86 | #endif | ||
| 87 | #ifndef LUA_OPLE | ||
| 88 | # define LUA_OPLE 2 | ||
| 64 | #endif | 89 | #endif |
| 65 | |||
| 66 | #define LUA_OK 0 | ||
| 67 | #define LUA_OPADD 0 | ||
| 68 | #define LUA_OPSUB 1 | ||
| 69 | #define LUA_OPMUL 2 | ||
| 70 | #define LUA_OPDIV 3 | ||
| 71 | #define LUA_OPMOD 4 | ||
| 72 | #define LUA_OPPOW 5 | ||
| 73 | #define LUA_OPUNM 6 | ||
| 74 | #define LUA_OPEQ 0 | ||
| 75 | #define LUA_OPLT 1 | ||
| 76 | #define LUA_OPLE 2 | ||
| 77 | 90 | ||
| 78 | typedef size_t lua_Unsigned; | 91 | typedef size_t lua_Unsigned; |
| 79 | 92 | ||
| @@ -106,10 +119,14 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to); | |||
| 106 | #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) | 119 | #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) |
| 107 | COMPAT53_API void lua_len (lua_State *L, int i); | 120 | COMPAT53_API void lua_len (lua_State *L, int i); |
| 108 | 121 | ||
| 109 | #define luaL_newlibtable(L, l) \ | 122 | #ifndef luaL_newlibtable |
| 123 | # define luaL_newlibtable(L, l) \ | ||
| 110 | (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) | 124 | (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) |
| 111 | #define luaL_newlib(L, l) \ | 125 | #endif |
| 126 | #ifndef luaL_newlib | ||
| 127 | # define luaL_newlib(L, l) \ | ||
| 112 | (luaL_newlibtable(L, l), luaL_register(L, NULL, l)) | 128 | (luaL_newlibtable(L, l), luaL_register(L, NULL, l)) |
| 129 | #endif | ||
| 113 | 130 | ||
| 114 | #define lua_pushglobaltable(L) \ | 131 | #define lua_pushglobaltable(L) \ |
| 115 | lua_pushvalue(L, LUA_GLOBALSINDEX) | 132 | lua_pushvalue(L, LUA_GLOBALSINDEX) |
| @@ -152,7 +169,6 @@ COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname); | |||
| 152 | #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) | 169 | #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) |
| 153 | COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); | 170 | COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); |
| 154 | 171 | ||
| 155 | #if !defined(COMPAT53_IS_LUAJIT) | ||
| 156 | #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) | 172 | #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) |
| 157 | COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); | 173 | COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); |
| 158 | 174 | ||
| @@ -161,7 +177,6 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname); | |||
| 161 | 177 | ||
| 162 | #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) | 178 | #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) |
| 163 | COMPAT53_API int luaL_execresult (lua_State *L, int stat); | 179 | COMPAT53_API int luaL_execresult (lua_State *L, int stat); |
| 164 | #endif /* COMPAT53_IS_LUAJIT */ | ||
| 165 | 180 | ||
| 166 | #define lua_callk(L, na, nr, ctx, cont) \ | 181 | #define lua_callk(L, na, nr, ctx, cont) \ |
| 167 | ((void)(ctx), (void)(cont), lua_call(L, na, nr)) | 182 | ((void)(ctx), (void)(cont), lua_call(L, na, nr)) |
