lua: Lua 5.3 support

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
Raito Bezarius 2024-09-08 01:07:25 +02:00
parent 65bb027054
commit ebb1dc92e4

View file

@ -252,7 +252,7 @@ ubus_lua_connect(lua_State *L)
{ {
struct ubus_lua_connection *c; struct ubus_lua_connection *c;
const char *sockpath = luaL_optstring(L, 1, NULL); const char *sockpath = luaL_optstring(L, 1, NULL);
int timeout = luaL_optint(L, 2, 30); int timeout = luaL_optinteger(L, 2, 30);
if ((c = lua_newuserdata(L, sizeof(*c))) != NULL && if ((c = lua_newuserdata(L, sizeof(*c))) != NULL &&
(c->ctx = ubus_connect(sockpath)) != NULL) (c->ctx = ubus_connect(sockpath)) != NULL)
@ -278,7 +278,7 @@ ubus_lua_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
lua_State *L = (lua_State *)p; lua_State *L = (lua_State *)p;
lua_pushstring(L, o->path); lua_pushstring(L, o->path);
lua_rawseti(L, -2, lua_objlen(L, -2) + 1); lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
} }
static int static int
@ -404,7 +404,7 @@ static int ubus_lua_load_methods(lua_State *L, struct ubus_method *m)
/* check if the method table is valid */ /* check if the method table is valid */
if ((lua_type(L, -2) != LUA_TFUNCTION) || if ((lua_type(L, -2) != LUA_TFUNCTION) ||
(lua_type(L, -1) != LUA_TTABLE) || (lua_type(L, -1) != LUA_TTABLE) ||
lua_objlen(L, -1)) { lua_rawlen(L, -1)) {
lua_pop(L, 2); lua_pop(L, 2);
return 1; return 1;
} }
@ -536,7 +536,7 @@ static struct ubus_object* ubus_lua_load_object(lua_State *L)
/* check if it looks like a method */ /* check if it looks like a method */
if ((lua_type(L, -2) != LUA_TSTRING) || if ((lua_type(L, -2) != LUA_TSTRING) ||
(lua_type(L, -1) != LUA_TTABLE) || (lua_type(L, -1) != LUA_TTABLE) ||
!lua_objlen(L, -1)) { !lua_rawlen(L, -1)) {
lua_pop(L, 1); lua_pop(L, 1);
continue; continue;
} }
@ -977,11 +977,12 @@ luaopen_ubus(lua_State *L)
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
/* fill metatable */ /* fill metatable */
luaL_register(L, NULL, ubus); luaL_setfuncs(L, ubus, 0);
lua_pop(L, 1); lua_pop(L, 1);
/* create module */ /* create module */
luaL_register(L, MODNAME, ubus); luaL_newmetatable(L, MODNAME);
luaL_setfuncs(L, ubus, 0);
/* set some enum defines */ /* set some enum defines */
lua_pushinteger(L, BLOBMSG_TYPE_ARRAY); lua_pushinteger(L, BLOBMSG_TYPE_ARRAY);