treewide: drop support for other lua versions

We're very much depending on LuaJIT, for years already.
The removed stuff seems very unlikely to be useful in any LuaJIT
in forseeable future.  The Lua language is effectively forked.
parent c495717e
...@@ -41,7 +41,6 @@ new_read_globals = { ...@@ -41,7 +41,6 @@ new_read_globals = {
'table_print', 'table_print',
'__engine', '__engine',
'_ENV', '_ENV',
'_SANDBOX',
} }
new_globals = { new_globals = {
......
...@@ -466,7 +466,7 @@ int kr_bindings_cache(lua_State *L) ...@@ -466,7 +466,7 @@ int kr_bindings_cache(lua_State *L)
{ NULL, NULL } { NULL, NULL }
}; };
register_lib(L, "cache", lib); luaL_register(L, "cache", lib);
return 1; return 1;
} }
...@@ -218,7 +218,7 @@ int kr_bindings_event(lua_State *L) ...@@ -218,7 +218,7 @@ int kr_bindings_event(lua_State *L)
{ NULL, NULL } { NULL, NULL }
}; };
register_lib(L, "event", lib); luaL_register(L, "event", lib);
return 1; return 1;
} }
...@@ -49,24 +49,13 @@ int kr_bindings_modules (lua_State *L); /* ./modules.c */ ...@@ -49,24 +49,13 @@ int kr_bindings_modules (lua_State *L); /* ./modules.c */
int kr_bindings_net (lua_State *L); /* ./net.c */ int kr_bindings_net (lua_State *L); /* ./net.c */
int kr_bindings_worker (lua_State *L); /* ./worker.c */ int kr_bindings_worker (lua_State *L); /* ./worker.c */
static void lualib(lua_State *L, const char *name, lua_CFunction lib_cb)
{
#if LUA_VERSION_NUM >= 502
luaL_requiref(L, name, lib_cb, 1);
lua_pop(L, 1);
#else
lib_cb(L);
#endif
}
void kr_bindings_register(lua_State *L) void kr_bindings_register(lua_State *L)
{ {
lualib(L, "modules", kr_bindings_modules); kr_bindings_cache(L);
lualib(L, "net", kr_bindings_net); kr_bindings_event(L);
lualib(L, "cache", kr_bindings_cache); kr_bindings_modules(L);
lualib(L, "event", kr_bindings_event); kr_bindings_net(L);
lualib(L, "worker", kr_bindings_worker); kr_bindings_worker(L);
} }
void lua_error_p(lua_State *L, const char *fmt, ...) void lua_error_p(lua_State *L, const char *fmt, ...)
......
...@@ -21,20 +21,6 @@ ...@@ -21,20 +21,6 @@
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
/** @internal Compatibility wrapper for Lua 5.0 - 5.2
https://www.lua.org/manual/5.2/manual.html#luaL_newlib
*/
#if LUA_VERSION_NUM >= 502
#define register_lib(L, name, lib) \
luaL_newlib((L), (lib))
#else
#define lua_rawlen(L, obj) \
lua_objlen((L), (obj))
#define register_lib(L, name, lib) \
luaL_openlib((L), (name), (lib), 0)
#endif
/** Useful to stringify #defines into error strings. */ /** Useful to stringify #defines into error strings. */
#define STR(s) STRINGIFY_TOKEN(s) #define STR(s) STRINGIFY_TOKEN(s)
#define STRINGIFY_TOKEN(s) #s #define STRINGIFY_TOKEN(s) #s
......
...@@ -85,7 +85,7 @@ int kr_bindings_modules(lua_State *L) ...@@ -85,7 +85,7 @@ int kr_bindings_modules(lua_State *L)
{ NULL, NULL } { NULL, NULL }
}; };
register_lib(L, "modules", lib); luaL_register(L, "modules", lib);
return 1; return 1;
} }
...@@ -279,7 +279,7 @@ static int net_interfaces(lua_State *L) ...@@ -279,7 +279,7 @@ static int net_interfaces(lua_State *L)
buf[0] = '\0'; buf[0] = '\0';
} }
lua_pushstring(L, buf); lua_pushstring(L, buf);
lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
lua_setfield(L, -2, "addr"); lua_setfield(L, -2, "addr");
/* Hardware address. */ /* Hardware address. */
...@@ -1030,7 +1030,7 @@ int kr_bindings_net(lua_State *L) ...@@ -1030,7 +1030,7 @@ int kr_bindings_net(lua_State *L)
{ "register_endpoint_kind", net_register_endpoint_kind }, { "register_endpoint_kind", net_register_endpoint_kind },
{ NULL, NULL } { NULL, NULL }
}; };
register_lib(L, "net", lib); luaL_register(L, "net", lib);
return 1; return 1;
} }
...@@ -177,7 +177,7 @@ int kr_bindings_worker(lua_State *L) ...@@ -177,7 +177,7 @@ int kr_bindings_worker(lua_State *L)
{ "stats", wrk_stats }, { "stats", wrk_stats },
{ NULL, NULL } { NULL, NULL }
}; };
register_lib(L, "worker", lib); luaL_register(L, "worker", lib);
return 1; return 1;
} }
...@@ -53,11 +53,6 @@ ...@@ -53,11 +53,6 @@
#endif #endif
#endif #endif
/** @internal Compatibility wrapper for Lua < 5.2 */
#if LUA_VERSION_NUM < 502
#define lua_rawlen(L, obj) lua_objlen((L), (obj))
#endif
/**@internal Maximum number of incomplete TCP connections in queue. /**@internal Maximum number of incomplete TCP connections in queue.
* Default is from Redis and Apache. */ * Default is from Redis and Apache. */
#ifndef TCP_BACKLOG_DEFAULT #ifndef TCP_BACKLOG_DEFAULT
...@@ -306,7 +301,7 @@ static void l_unpack_json(lua_State *L, JsonNode *table) ...@@ -306,7 +301,7 @@ static void l_unpack_json(lua_State *L, JsonNode *table)
if (node->key) { if (node->key) {
lua_setfield(L, -2, node->key); lua_setfield(L, -2, node->key);
} else { } else {
lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
} }
} }
} }
...@@ -390,7 +385,7 @@ static int l_fromjson(lua_State *L) ...@@ -390,7 +385,7 @@ static int l_fromjson(lua_State *L)
/** @internal Throw Lua error if expr is false */ /** @internal Throw Lua error if expr is false */
#define expr_checked(expr) \ #define expr_checked(expr) \
if (!(expr)) { lua_pushboolean(L, false); lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); continue; } if (!(expr)) { lua_pushboolean(L, false); lua_rawseti(L, -2, lua_objlen(L, -2) + 1); continue; }
static int l_map(lua_State *L) static int l_map(lua_State *L)
{ {
...@@ -429,12 +424,12 @@ static int l_map(lua_State *L) ...@@ -429,12 +424,12 @@ static int l_map(lua_State *L)
lua_pushlstring(L, rbuf, rlen); lua_pushlstring(L, rbuf, rlen);
} }
json_delete(root_node); json_delete(root_node);
lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
continue; continue;
} }
/* Didn't respond */ /* Didn't respond */
lua_pushboolean(L, false); lua_pushboolean(L, false);
lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
} }
return 1; return 1;
} }
...@@ -666,10 +661,6 @@ void engine_deinit(struct engine *engine) ...@@ -666,10 +661,6 @@ void engine_deinit(struct engine *engine)
int engine_pcall(lua_State *L, int argc) int engine_pcall(lua_State *L, int argc)
{ {
#if LUA_VERSION_NUM >= 502
lua_getglobal(L, "_SANDBOX");
lua_setupvalue(L, -(2 + argc), 1);
#endif
return lua_pcall(L, argc, LUA_MULTRET, 0); return lua_pcall(L, argc, LUA_MULTRET, 0);
} }
......
...@@ -25,12 +25,6 @@ ...@@ -25,12 +25,6 @@
#include "lib/module.h" #include "lib/module.h"
#include "lib/layer.h" #include "lib/layer.h"
#if LUA_VERSION_NUM >= 502
#define l_resume(L, argc) lua_resume((L), NULL, (argc))
#else
#define l_resume(L, argc) lua_resume((L), (argc))
#endif
/** @internal Slots for layer callbacks. /** @internal Slots for layer callbacks.
* Each slot ID corresponds to Lua reference in module API. */ * Each slot ID corresponds to Lua reference in module API. */
enum { enum {
...@@ -65,7 +59,7 @@ static inline lua_State *l_ffi_preface(struct kr_module *module, const char *cal ...@@ -65,7 +59,7 @@ static inline lua_State *l_ffi_preface(struct kr_module *module, const char *cal
static void l_ffi_resume_cb(uv_idle_t *check) static void l_ffi_resume_cb(uv_idle_t *check)
{ {
lua_State *L = check->data; lua_State *L = check->data;
int status = l_resume(L, 0); int status = lua_resume(L, 0);
if (status != LUA_YIELD) { if (status != LUA_YIELD) {
uv_idle_stop(check); /* Stop coroutine */ uv_idle_stop(check); /* Stop coroutine */
uv_close((uv_handle_t *)check, (uv_close_cb)free); uv_close((uv_handle_t *)check, (uv_close_cb)free);
......
...@@ -404,12 +404,8 @@ local function make_sandbox(defined) ...@@ -404,12 +404,8 @@ local function make_sandbox(defined)
end end
-- Compatibility sandbox -- Compatibility sandbox
if setfenv then -- Lua 5.1 and less _G = make_sandbox(getfenv(0))
_G = make_sandbox(getfenv(0)) setfenv(0, _G)
setfenv(0, _G)
else -- Lua 5.2+
_SANDBOX = make_sandbox(_ENV)
end
-- Load embedded modules -- Load embedded modules
trust_anchors = require('trust_anchors') trust_anchors = require('trust_anchors')
......
...@@ -12,11 +12,6 @@ ...@@ -12,11 +12,6 @@
#include "lib/layer.h" #include "lib/layer.h"
#include "lib/generic/lru.h" #include "lib/generic/lru.h"
/** @internal Compatibility wrapper for Lua < 5.2 */
#if LUA_VERSION_NUM < 502
#define lua_rawlen(L, obj) lua_objlen((L), (obj))
#endif
#ifdef LRU_REP_SIZE #ifdef LRU_REP_SIZE
#define FREQUENT_COUNT LRU_REP_SIZE /* Size of frequent tables */ #define FREQUENT_COUNT LRU_REP_SIZE /* Size of frequent tables */
#else #else
......
...@@ -36,11 +36,6 @@ ...@@ -36,11 +36,6 @@
#include "lib/layer.h" #include "lib/layer.h"
#include "lib/resolve.h" #include "lib/resolve.h"
/** @internal Compatibility wrapper for Lua < 5.2 */
#if LUA_VERSION_NUM < 502
#define lua_rawlen(L, obj) lua_objlen((L), (obj))
#endif
/* Defaults */ /* Defaults */
#define VERBOSE_MSG(qry, ...) QRVERBOSE(qry, "stat", __VA_ARGS__) #define VERBOSE_MSG(qry, ...) QRVERBOSE(qry, "stat", __VA_ARGS__)
#define FREQUENT_PSAMPLE 10 /* Sampling rate, 1 in N */ #define FREQUENT_PSAMPLE 10 /* Sampling rate, 1 in N */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment