From 638ac2741a7f274979ac3fe2e1ea5fd6487702fe Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Tue, 2 Jan 2018 17:11:35 -0800 Subject: optimize: improved forward-compatibility with older versions of Lua/LuaJIT. Signed-off-by: Yichun Zhang (agentzh) --- lua_cjson.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lua_cjson.c b/lua_cjson.c index c0bdce1..cbf8286 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -1380,13 +1380,14 @@ static int json_decode(lua_State *l) /* ===== INITIALISATION ===== */ -#if !defined(luaL_newlibtable) \ - && (!defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502) +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 /* Compatibility for Lua 5.1 and older LuaJIT. * - * luaL_setfuncs() is used to create a module table where the functions have - * json_config_t as their first upvalue. Code borrowed from Lua 5.2 source. */ -static void luaL_setfuncs (lua_State *l, const luaL_Reg *reg, int nup) + * compat_luaL_setfuncs() is used to create a module table where the functions + * have json_config_t as their first upvalue. Code borrowed from Lua 5.2 + * source's luaL_setfuncs(). + */ +static void compat_luaL_setfuncs(lua_State *l, const luaL_Reg *reg, int nup) { int i; @@ -1399,6 +1400,8 @@ static void luaL_setfuncs (lua_State *l, const luaL_Reg *reg, int nup) } lua_pop(l, nup); /* remove upvalues */ } +#else +#define compat_luaL_setfuncs(L, reg, nup) luaL_setfuncs(L, reg, nup) #endif /* Call target function in protected mode with all supplied args. @@ -1479,7 +1482,7 @@ static int lua_cjson_new(lua_State *l) /* Register functions with config data as upvalue */ json_create_config(l); - luaL_setfuncs(l, reg, 1); + compat_luaL_setfuncs(l, reg, 1); /* Set cjson.null */ lua_pushlightuserdata(l, NULL); -- cgit v1.2.3-55-g6feb