diff --git a/src/GNUmakefile b/src/GNUmakefile index c426b02..1f0dd7d 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -22,7 +22,7 @@ VENDOR_$(d) = $(or $(CQUEUES_VENDOR),$(shell $( 0 || idx <= LUA_REGISTRYINDEX)? idx : lua_gettop(L) + idx + 1; -} /* lua_absindex() */ - - -static void *luaL_testudata(lua_State *L, int arg, const char *tname) { - void *p = lua_touserdata(L, arg); - int eq; - - if (!p || !lua_getmetatable(L, arg)) - return 0; - - luaL_getmetatable(L, tname); - eq = lua_rawequal(L, -2, -1); - lua_pop(L, 2); - - return (eq)? p : 0; -} /* luaL_testudate() */ - - -static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { - int i, t = lua_absindex(L, -1 - nup); - - for (; l->name; l++) { - for (i = 0; i < nup; i++) - lua_pushvalue(L, -nup); - lua_pushcclosure(L, l->func, nup); - lua_setfield(L, t, l->name); - } - - lua_pop(L, nup); -} /* luaL_setfuncs() */ - - -#define luaL_newlibtable(L, l) \ - lua_createtable(L, 0, (sizeof (l) / sizeof *(l)) - 1) - -#define luaL_newlib(L, l) \ - (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0)) - - -static int luaL_getsubtable(lua_State *L, int index, const char *tname) { - lua_getfield(L, index, tname); - - if (lua_istable(L, -1)) - return 1; - - lua_pop(L, 1); - index = lua_absindex(L, index); - lua_newtable(L); - lua_pushvalue(L, -1); - lua_setfield(L, index, tname); - - return 0; -} /* luaL_getsubtable() */ - - -static void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb) { - lua_pushcfunction(L, openf); - lua_pushstring(L, modname); - lua_call(L, 1, 1); - - luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_pushvalue(L, -2); - lua_setfield(L, -2, modname); - lua_pop(L, 1); - - if (glb) { - lua_pushvalue(L, -1); - lua_setglobal(L, modname); - } -} /* luaL_requiref() */ - - -#define lua_resume(L, from, nargs) lua_resume((L), (nargs)) - - -static void lua_rawgetp(lua_State *L, int index, const void *p) { - index = lua_absindex(L, index); - lua_pushlightuserdata(L, (void *)p); - lua_rawget(L, index); -} /* lua_rawgetp() */ - -static void lua_rawsetp(lua_State *L, int index, const void *p) { - index = lua_absindex(L, index); - lua_pushlightuserdata(L, (void *)p); - lua_pushvalue(L, -2); - lua_rawset(L, index); - lua_pop(L, 1); -} /* lua_rawsetp() */ - - -#ifndef LUA_UNSIGNED -#define LUA_UNSIGNED unsigned -#endif - -typedef LUA_UNSIGNED lua_Unsigned; - - -static void lua_pushunsigned(lua_State *L, lua_Unsigned n) { - lua_pushnumber(L, (lua_Number)n); -} /* lua_pushunsigned() */ - -static lua_Unsigned luaL_checkunsigned(lua_State *L, int arg) { - return (lua_Unsigned)luaL_checknumber(L, arg); -} /* luaL_checkunsigned() */ - - -static lua_Unsigned luaL_optunsigned(lua_State *L, int arg, lua_Unsigned def) { - return (lua_Unsigned)luaL_optnumber(L, arg, (lua_Number)def); -} /* luaL_optunsigned() */ - - -#ifndef LUA_FILEHANDLE /* Not defined by earlier LuaJIT releases */ -#define LUA_FILEHANDLE "FILE*" -#endif - -/* - * Lua 5.1 userdata is a simple FILE *, while LuaJIT is a struct with the - * first member a FILE *, similar to Lua 5.2. - */ -typedef struct luaL_Stream { - FILE *f; -} luaL_Stream; - - -#define lua_rawlen(...) lua_objlen(__VA_ARGS__) - - -#endif /* LUA_VERSION_NUM < 502 */ diff --git a/src/cqueues.c b/src/cqueues.c index d452640..6528706 100644 --- a/src/cqueues.c +++ b/src/cqueues.c @@ -810,12 +810,7 @@ static int kpoll_wait(struct kpoll *kp, double timeout) { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #if LUA_VERSION_NUM >= 502 - -#if LUA_VERSION_NUM >= 503 -static int auxlib_tostringk(lua_State *L NOTUSED, int status NOTUSED, lua_KContext ctx NOTUSED) { -#else -static int auxlib_tostringk(lua_State *L NOTUSED) { -#endif +LUA_KFUNCTION(auxlib_tostringk) { if (luaL_getmetafield(L, 1, "__tostring")) { lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); } else { @@ -833,11 +828,7 @@ static int auxlib_tostring(lua_State *L) { lua_settop(L, 2); lua_callk(L, 1, 1, 0, &auxlib_tostringk); -#if LUA_VERSION_NUM >= 503 return auxlib_tostringk(L, LUA_OK, 0); -#else - return auxlib_tostringk(L); -#endif } else { luaL_tolstring(L, 1, NULL); @@ -2199,10 +2190,10 @@ static double cqueue_timeout_(struct cqueue *Q) { } /* cqueue_timeout_() */ -#if LUA_VERSION_NUM <= 502 -static int cqueue_step_cont(lua_State *L) { +#if LUA_VERSION_NUM >= 502 +LUA_KFUNCTION(cqueue_step_cont) { #else -static int cqueue_step_cont(lua_State *L, int status NOTUSED, lua_KContext ctx NOTUSED) { +static int cqueue_step_cont(lua_State *L) { #endif int nargs = lua_gettop(L); struct callinfo I = CALLINFO_INITIALIZER; diff --git a/src/cqueues.h b/src/cqueues.h index d289324..0e3303e 100644 --- a/src/cqueues.h +++ b/src/cqueues.h @@ -40,9 +40,7 @@ #include #include -#if LUA_VERSION_NUM < 502 -#include "compat52.h" -#endif +#include "../vendor/compat53/c-api/compat-5.3.h" /* diff --git a/src/thread.c b/src/thread.c index a46a1bd..65d7fb8 100644 --- a/src/thread.c +++ b/src/thread.c @@ -498,11 +498,7 @@ static int ct_setfarg(lua_State *L, struct cthread *ct, struct cthread_arg *arg, T = lua_newthread(L); luaL_buffinit(T, &B); lua_pushvalue(L, index); -#if LUA_VERSION_NUM >= 503 lua_dump(L, &dump_add, &B, 0); -#else - lua_dump(L, &dump_add, &B); -#endif luaL_pushresult(&B); arg->v.string.iov_base = (char *)luaL_checklstring(T, -1, &arg->v.string.iov_len);