diff --git a/client.c b/client.c index d8fd37b3b..831e1c02f 100644 --- a/client.c +++ b/client.c @@ -998,6 +998,7 @@ luaA_client_tags(lua_State *L) tag_array_t *tags; tag_t **tag; client_t **c = luaA_checkudata(L, 1, "client"); + int j = 0; if(lua_gettop(L) == 2) { @@ -1012,19 +1013,17 @@ luaA_client_tags(lua_State *L) tag_client(*c, *tag); lua_pop(L, 1); } + lua_pop(L, 1); } - else - { - tags = &globalconf.screens[(*c)->screen].tags; - luaA_otable_new(L); - for(int i = 0; i < tags->len; i++) - if(is_client_tagged(*c, tags->tab[i])) - { - luaA_tag_userdata_new(L, tags->tab[i]); - luaA_tag_userdata_new(L, tags->tab[i]); - lua_rawset(L, -3); - } - } + + tags = &globalconf.screens[(*c)->screen].tags; + luaA_otable_new(L); + for(int i = 0; i < tags->len; i++) + if(is_client_tagged(*c, tags->tab[i])) + { + luaA_tag_userdata_new(L, tags->tab[i]); + lua_rawseti(L, -2, ++j); + } return 1; } diff --git a/lua.c b/lua.c index b03750dbd..c4532e87e 100644 --- a/lua.c +++ b/lua.c @@ -410,9 +410,19 @@ luaA_otable_index(lua_State *L) lua_pushnil(L); while(lua_next(L, 1)) { + /* check the key against the key if the key is a userdata, + * otherwise check it again the value. */ if((v = lua_touserdata(L, -2)) - && *v == *obj) + && *v == *obj) + /* return value */ return 1; + else if((v = lua_touserdata(L, -1)) + && *v == *obj) + { + /* return key */ + lua_pop(L, 1); + return 1; + } /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); } diff --git a/tag.c b/tag.c index baf2bc17b..417257e10 100644 --- a/tag.c +++ b/tag.c @@ -290,6 +290,7 @@ static int luaA_tag_clients(lua_State *L) { tag_t **tag = luaA_checkudata(L, 1, "tag"); + client_array_t *clients = &(*tag)->clients; int i; if(lua_gettop(L) == 2) @@ -307,15 +308,12 @@ luaA_tag_clients(lua_State *L) lua_pop(L, 1); } } - else + + luaA_otable_new(L); + for(i = 0; i < clients->len; i++) { - client_array_t *clients = &(*tag)->clients; - lua_newtable(L); - for(i = 0; i < clients->len; i++) - { - luaA_client_userdata_new(L, clients->tab[i]); - lua_rawseti(L, -2, i + 1); - } + luaA_client_userdata_new(L, clients->tab[i]); + lua_rawseti(L, -2, i + 1); } return 1;