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.
'table_print',
'__engine',
'_ENV',
- '_SANDBOX',
}
new_globals = {
{ NULL, NULL }
};
- register_lib(L, "cache", lib);
+ luaL_register(L, "cache", lib);
return 1;
}
{ NULL, NULL }
};
- register_lib(L, "event", lib);
+ luaL_register(L, "event", lib);
return 1;
}
int kr_bindings_net (lua_State *L); /* ./net.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)
{
- lualib(L, "modules", kr_bindings_modules);
- lualib(L, "net", kr_bindings_net);
- lualib(L, "cache", kr_bindings_cache);
- lualib(L, "event", kr_bindings_event);
- lualib(L, "worker", kr_bindings_worker);
+ kr_bindings_cache(L);
+ kr_bindings_event(L);
+ kr_bindings_modules(L);
+ kr_bindings_net(L);
+ kr_bindings_worker(L);
}
void lua_error_p(lua_State *L, const char *fmt, ...)
#include <lua.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. */
#define STR(s) STRINGIFY_TOKEN(s)
#define STRINGIFY_TOKEN(s) #s
{ NULL, NULL }
};
- register_lib(L, "modules", lib);
+ luaL_register(L, "modules", lib);
return 1;
}
buf[0] = '\0';
}
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");
/* Hardware address. */
{ "register_endpoint_kind", net_register_endpoint_kind },
{ NULL, NULL }
};
- register_lib(L, "net", lib);
+ luaL_register(L, "net", lib);
return 1;
}
{ "stats", wrk_stats },
{ NULL, NULL }
};
- register_lib(L, "worker", lib);
+ luaL_register(L, "worker", lib);
return 1;
}
#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.
* Default is from Redis and Apache. */
#ifndef TCP_BACKLOG_DEFAULT
if (node->key) {
lua_setfield(L, -2, node->key);
} else {
- lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
+ lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
}
}
}
/** @internal Throw Lua error if expr is false */
#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)
{
lua_pushlstring(L, rbuf, rlen);
}
json_delete(root_node);
- lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
+ lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
continue;
}
/* Didn't respond */
lua_pushboolean(L, false);
- lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
+ lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
}
return 1;
}
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);
}
#include "lib/module.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.
* Each slot ID corresponds to Lua reference in module API. */
enum {
static void l_ffi_resume_cb(uv_idle_t *check)
{
lua_State *L = check->data;
- int status = l_resume(L, 0);
+ int status = lua_resume(L, 0);
if (status != LUA_YIELD) {
uv_idle_stop(check); /* Stop coroutine */
uv_close((uv_handle_t *)check, (uv_close_cb)free);
end
-- Compatibility sandbox
-if setfenv then -- Lua 5.1 and less
- _G = make_sandbox(getfenv(0))
- setfenv(0, _G)
-else -- Lua 5.2+
- _SANDBOX = make_sandbox(_ENV)
-end
+_G = make_sandbox(getfenv(0))
+setfenv(0, _G)
-- Load embedded modules
trust_anchors = require('trust_anchors')
#include "lib/layer.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
#define FREQUENT_COUNT LRU_REP_SIZE /* Size of frequent tables */
#else
#include "lib/layer.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 */
#define VERBOSE_MSG(qry, ...) QRVERBOSE(qry, "stat", __VA_ARGS__)
#define FREQUENT_PSAMPLE 10 /* Sampling rate, 1 in N */