From f608371c71644f5db60a3c83b2c7a44f1eb30eea Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Mon, 7 Aug 2017 20:22:18 +0200 Subject: 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. --- README.md | 6 +++++- c-api/compat-5.3.c | 2 -- c-api/compat-5.3.h | 63 +++++++++++++++++++++++++++++++++--------------------- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8c7b058..25bc911 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,11 @@ your project: compatibility functions in your code. You have to compile and link `compat-5.3.c` to your project yourself. You can change the way the functions are exported using the `COMPAT53_API` macro (e.g. if you need - some `__declspec` magic). + some `__declspec` magic). While it is technically possible to use + the "lua" prefix (and it looks better in the debugger), this is + discouraged because LuaJIT has started to implement its own Lua 5.2+ + C API functions, and with the "lua" prefix you'd violate the + one-definition rule with recent LuaJIT versions. ## What's implemented 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) { } -#if !defined(COMPAT53_IS_LUAJIT) static int compat53_countlevels (lua_State *L) { lua_Debug ar; int li = 1, le = 1; @@ -418,7 +417,6 @@ COMPAT53_API int luaL_execresult (lua_State *L, int stat) { return 3; } } -#endif /* not COMPAT53_IS_LUAJIT */ 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" { # undef COMPAT53_INCLUDE_SOURCE #else /* COMPAT53_PREFIX */ /* - make all functions static and include the source. - * - don't mess with the symbol names of functions * - compat-5.3.c doesn't need to be compiled (and linked) separately */ -# define COMPAT53_PREFIX lua +# define COMPAT53_PREFIX compat53 # undef COMPAT53_API # if defined(__GNUC__) || defined(__clang__) # define COMPAT53_API __attribute__((__unused__)) static @@ -55,25 +54,39 @@ extern "C" { * luaL_loadfilex */ -/* PUC-Rio Lua uses lconfig_h as include guard for luaconf.h, - * LuaJIT uses luaconf_h. If you use PUC-Rio's include files - * but LuaJIT's library, you will need to define the macro - * COMPAT53_IS_LUAJIT yourself! */ -#if !defined(COMPAT53_IS_LUAJIT) && defined(luaconf_h) -# define COMPAT53_IS_LUAJIT +#ifndef LUA_OK +# define LUA_OK 0 +#endif +#ifndef LUA_OPADD +# define LUA_OPADD 0 +#endif +#ifndef LUA_OPSUB +# define LUA_OPSUB 1 +#endif +#ifndef LUA_OPMUL +# define LUA_OPMUL 2 +#endif +#ifndef LUA_OPDIV +# define LUA_OPDIV 3 +#endif +#ifndef LUA_OPMOD +# define LUA_OPMOD 4 +#endif +#ifndef LUA_OPPOW +# define LUA_OPPOW 5 +#endif +#ifndef LUA_OPUNM +# define LUA_OPUNM 6 +#endif +#ifndef LUA_OPEQ +# define LUA_OPEQ 0 +#endif +#ifndef LUA_OPLT +# define LUA_OPLT 1 +#endif +#ifndef LUA_OPLE +# define LUA_OPLE 2 #endif - -#define LUA_OK 0 -#define LUA_OPADD 0 -#define LUA_OPSUB 1 -#define LUA_OPMUL 2 -#define LUA_OPDIV 3 -#define LUA_OPMOD 4 -#define LUA_OPPOW 5 -#define LUA_OPUNM 6 -#define LUA_OPEQ 0 -#define LUA_OPLT 1 -#define LUA_OPLE 2 typedef size_t lua_Unsigned; @@ -106,10 +119,14 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to); #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) COMPAT53_API void lua_len (lua_State *L, int i); -#define luaL_newlibtable(L, l) \ +#ifndef luaL_newlibtable +# define luaL_newlibtable(L, l) \ (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) -#define luaL_newlib(L, l) \ +#endif +#ifndef luaL_newlib +# define luaL_newlib(L, l) \ (luaL_newlibtable(L, l), luaL_register(L, NULL, l)) +#endif #define lua_pushglobaltable(L) \ lua_pushvalue(L, LUA_GLOBALSINDEX) @@ -152,7 +169,6 @@ COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname); #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); -#if !defined(COMPAT53_IS_LUAJIT) #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); @@ -161,7 +177,6 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname); #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) COMPAT53_API int luaL_execresult (lua_State *L, int stat); -#endif /* COMPAT53_IS_LUAJIT */ #define lua_callk(L, na, nr, ctx, cont) \ ((void)(ctx), (void)(cont), lua_call(L, na, nr)) -- cgit v1.2.3-55-g6feb