lua: add optional path filter to objects() method
[project/ubus.git] / lua / ubus.c
index fb50418d27b0e3c3ace535050a4f107b984c6d64..07b816d40f851aaaebb25f73d34e86d94db10b13 100644 (file)
@@ -196,7 +196,10 @@ ubus_lua_format_blob(lua_State *L, struct blob_buf *b, bool table)
        case LUA_TINT:
 #endif
        case LUA_TNUMBER:
-               blobmsg_add_u32(b, key, (uint32_t)lua_tointeger(L, -1));
+               if ((uint64_t)lua_tonumber(L, -1) > INT_MAX)
+                       blobmsg_add_u64(b, key, (uint64_t)lua_tonumber(L, -1));
+               else
+                       blobmsg_add_u32(b, key, (uint32_t)lua_tointeger(L, -1));
                break;
 
        case LUA_TSTRING:
@@ -283,9 +286,10 @@ ubus_lua_objects(lua_State *L)
 {
        int rv;
        struct ubus_lua_connection *c = luaL_checkudata(L, 1, METANAME);
+       const char *path = (lua_gettop(L) >= 2) ? luaL_checkstring(L, 2) : NULL;
 
        lua_newtable(L);
-       rv = ubus_lookup(c->ctx, NULL, ubus_lua_objects_cb, L);
+       rv = ubus_lookup(c->ctx, path, ubus_lua_objects_cb, L);
 
        if (rv != UBUS_STATUS_OK)
        {
@@ -840,8 +844,8 @@ ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* targe
 
        if( idxremove ){
                lua_getglobal(L, "__ubus_cb_subscribe");
-               lua_pushvalue(L, idxnotify);
-               sub->rnotify = luaL_ref(L, -2);
+               lua_pushvalue(L, idxremove);
+               sub->rremove = luaL_ref(L, -2);
                lua_pop(L, 1);
                sub->s.remove_cb = ubus_sub_remove_handler;
        }