diff options
author | Thibault Charbonnier <thibaultcha@me.com> | 2018-01-02 17:11:35 -0800 |
---|---|---|
committer | Yichun Zhang (agentzh) <agentzh@gmail.com> | 2018-01-02 17:35:22 -0800 |
commit | 638ac2741a7f274979ac3fe2e1ea5fd6487702fe (patch) | |
tree | 1745c8e988f8104c633b39d7f93957dc2db684b4 | |
parent | bcbbb53bf2066c64614127f361e158970a14cab2 (diff) | |
download | lua-cjson-638ac2741a7f274979ac3fe2e1ea5fd6487702fe.tar.gz lua-cjson-638ac2741a7f274979ac3fe2e1ea5fd6487702fe.tar.bz2 lua-cjson-638ac2741a7f274979ac3fe2e1ea5fd6487702fe.zip |
optimize: improved forward-compatibility with older versions of Lua/LuaJIT.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
-rw-r--r-- | lua_cjson.c | 15 |
1 files 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) | |||
1380 | 1380 | ||
1381 | /* ===== INITIALISATION ===== */ | 1381 | /* ===== INITIALISATION ===== */ |
1382 | 1382 | ||
1383 | #if !defined(luaL_newlibtable) \ | 1383 | #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 |
1384 | && (!defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502) | ||
1385 | /* Compatibility for Lua 5.1 and older LuaJIT. | 1384 | /* Compatibility for Lua 5.1 and older LuaJIT. |
1386 | * | 1385 | * |
1387 | * luaL_setfuncs() is used to create a module table where the functions have | 1386 | * compat_luaL_setfuncs() is used to create a module table where the functions |
1388 | * json_config_t as their first upvalue. Code borrowed from Lua 5.2 source. */ | 1387 | * have json_config_t as their first upvalue. Code borrowed from Lua 5.2 |
1389 | static void luaL_setfuncs (lua_State *l, const luaL_Reg *reg, int nup) | 1388 | * source's luaL_setfuncs(). |
1389 | */ | ||
1390 | static void compat_luaL_setfuncs(lua_State *l, const luaL_Reg *reg, int nup) | ||
1390 | { | 1391 | { |
1391 | int i; | 1392 | int i; |
1392 | 1393 | ||
@@ -1399,6 +1400,8 @@ static void luaL_setfuncs (lua_State *l, const luaL_Reg *reg, int nup) | |||
1399 | } | 1400 | } |
1400 | lua_pop(l, nup); /* remove upvalues */ | 1401 | lua_pop(l, nup); /* remove upvalues */ |
1401 | } | 1402 | } |
1403 | #else | ||
1404 | #define compat_luaL_setfuncs(L, reg, nup) luaL_setfuncs(L, reg, nup) | ||
1402 | #endif | 1405 | #endif |
1403 | 1406 | ||
1404 | /* Call target function in protected mode with all supplied args. | 1407 | /* Call target function in protected mode with all supplied args. |
@@ -1479,7 +1482,7 @@ static int lua_cjson_new(lua_State *l) | |||
1479 | 1482 | ||
1480 | /* Register functions with config data as upvalue */ | 1483 | /* Register functions with config data as upvalue */ |
1481 | json_create_config(l); | 1484 | json_create_config(l); |
1482 | luaL_setfuncs(l, reg, 1); | 1485 | compat_luaL_setfuncs(l, reg, 1); |
1483 | 1486 | ||
1484 | /* Set cjson.null */ | 1487 | /* Set cjson.null */ |
1485 | lua_pushlightuserdata(l, NULL); | 1488 | lua_pushlightuserdata(l, NULL); |