Message ID | 20171009150241.7fcrcm3kp3n7s3u5@MD1KR9XC.ww002.siemens.net |
---|---|
State | Not Applicable |
Headers | show |
Series | State of Lua version(s) supported/working | expand |
Hi Christian, On 09/10/2017 17:02, Christian Storm wrote: > Hi, > > I did a quick compile test with various versions of Lua: > * Lua 5.3: works. > * Lua 5.2: works. > * Lua 5.1: does not work, with the following errors: > > corelib/lua_interface.c:421:2: warning: implicit declaration of function ‘luaL_newlib’ > corelib/lua_interface.c:485:6: error: ‘LUA_OK’ undeclared > corelib/lua_interface.c:538:3: warning: implicit declaration of function ‘luaL_requiref’ > This is known, see the thread : https://groups.google.com/forum/#!topic/swupdate/WAm8npAOd6o > These are all available from Lua 5.2 onwards. > > As Lua 5.1 was released on 21st Feb 2006 and 5.2 on 16th Dec 2011, I > guess Lua 5.2 does qualify as minimal Lua version requirement? Yes > Travis also uses the 5.2 version by the way. > Right. > Otherwise, we either need to get rid of the 5.2ish functions No. > or > implement some mapping code like the following patch (copied and > assembled from https://github.com/keplerproject/lua-compat-5.2): > > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index 14f9251..c716982 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -29,6 +29,45 @@ > #include "util.h" > #include "handler.h" > > +/* from https://github.com/keplerproject/lua-compat-5.2 */ > +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501 > +void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); > +void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb); > + > +void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { > + luaL_checkstack(L, nup+1, "too many upvalues"); > + for (; l->name != NULL; l++) { /* fill the table with given functions */ > + int i; > + lua_pushstring(L, l->name); > + for (i = 0; i < nup; i++) /* copy upvalues to the top */ > + lua_pushvalue(L, -(nup + 1)); > + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ > + lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ > + } > + lua_pop(L, nup); /* remove upvalues */ > +} > + > +void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb) { > + luaL_checkstack(L, 3, "not enough stack slots"); > + lua_pushcfunction(L, openf); > + lua_pushstring(L, modname); > + lua_call(L, 1, 1); > + lua_getglobal(L, "package"); > + lua_getfield(L, -1, "loaded"); > + lua_replace(L, -2); > + lua_pushvalue(L, -2); > + lua_setfield(L, -2, modname); > + lua_pop(L, 1); > + if (glb) { > + lua_pushvalue(L, -1); > + lua_setglobal(L, modname); > + } > +} > + > +#define LUA_OK 0 > +#define luaL_newlib(L, l) (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) > +#endif > + > #define LUA_PUSH_IMG_STRING(img, attr, field) do { \ > lua_pushstring(L, attr); \ > lua_pushstring(L, img->field); \ > As I wrote in the above thread: "As far as I understand, the main reason to remain with 5.1 is LUAJit because it is not supported after 5.1." Anyway, it is a 11 years old release. And as I stated, I have nothing against patches if they do not break current behaviour. Best regards, Stefano
Hi Stefano, > > I did a quick compile test with various versions of Lua: > > * Lua 5.3: works. > > * Lua 5.2: works. > > * Lua 5.1: does not work, with the following errors: > > > > corelib/lua_interface.c:421:2: warning: implicit declaration of function ‘luaL_newlib’ > > corelib/lua_interface.c:485:6: error: ‘LUA_OK’ undeclared > > corelib/lua_interface.c:538:3: warning: implicit declaration of function ‘luaL_requiref’ > > > > This is known, see the thread : > > https://groups.google.com/forum/#!topic/swupdate/WAm8npAOd6o Ah, I see, sorry for the noise! I should have searched the ML history... > [...] > As I wrote in the above thread: > > "As far as I understand, the main reason to remain with 5.1 is LUAJit > because it is not supported after 5.1." Yes, LuaJIT is mostly 5.1 but has some of 5.2's features. It's latest version 2.0.5 was released on 1st of May 2017. > Anyway, it is a 11 years old release. And as I stated, I have nothing > against patches if they do not break current behaviour. OK, I'd like to see LuaJIT supported, I'll take a look and come back with a patch. Kind regards, Christian
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 14f9251..c716982 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -29,6 +29,45 @@ #include "util.h" #include "handler.h" +/* from https://github.com/keplerproject/lua-compat-5.2 */ +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501 +void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); +void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb); + +void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { + luaL_checkstack(L, nup+1, "too many upvalues"); + for (; l->name != NULL; l++) { /* fill the table with given functions */ + int i; + lua_pushstring(L, l->name); + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -(nup + 1)); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ + } + lua_pop(L, nup); /* remove upvalues */ +} + +void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb) { + luaL_checkstack(L, 3, "not enough stack slots"); + lua_pushcfunction(L, openf); + lua_pushstring(L, modname); + lua_call(L, 1, 1); + lua_getglobal(L, "package"); + lua_getfield(L, -1, "loaded"); + lua_replace(L, -2); + lua_pushvalue(L, -2); + lua_setfield(L, -2, modname); + lua_pop(L, 1); + if (glb) { + lua_pushvalue(L, -1); + lua_setglobal(L, modname); + } +} + +#define LUA_OK 0 +#define luaL_newlib(L, l) (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) +#endif + #define LUA_PUSH_IMG_STRING(img, attr, field) do { \ lua_pushstring(L, attr); \ lua_pushstring(L, img->field); \