示例#1
0
文件: tag.c 项目: kanru/awesome
/** Get or set the clients attached to this tag.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lparam None or a table of clients to set.
 * \lreturn A table with the clients attached to this tags.
 */
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)
    {
        client_t **c;

        luaA_checktable(L, 2);
        for(i = 0; i < (*tag)->clients.len; i++)
            untag_client((*tag)->clients.tab[i], *tag);
        lua_pushnil(L);
        while(lua_next(L, 2))
        {
            c = luaA_checkudata(L, -1, "client");
            tag_client(*c, *tag);
            lua_pop(L, 1);
        }
    }

    luaA_otable_new(L);
    for(i = 0; i < clients->len; i++)
    {
        luaA_client_userdata_new(L, clients->tab[i]);
        lua_rawseti(L, -2, i + 1);
    }

    return 1;
}
示例#2
0
文件: tag.c 项目: azuwis/awesome
/** Get or set the clients attached to this tag.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lparam None or a table of clients to set.
 * \lreturn A table with the clients attached to this tags.
 */
static int
luaA_tag_clients(lua_State *L)
{
    tag_t *tag = luaL_checkudata(L, 1, "tag");
    client_array_t *clients = &tag->clients;
    int i;

    if(lua_gettop(L) == 2)
    {
        luaA_checktable(L, 2);
        foreach(c, tag->clients)
            untag_client(*c, tag);
        lua_pushnil(L);
        while(lua_next(L, 2))
        {
            client_t *c = luaA_client_checkudata(L, -1);
            /* push tag on top of the stack */
            lua_pushvalue(L, 1);
            tag_client(c);
            lua_pop(L, 1);
        }
    }

    lua_createtable(L, clients->len, 0);
    for(i = 0; i < clients->len; i++)
    {
        client_push(L, clients->tab[i]);
        lua_rawseti(L, -2, i + 1);
    }

    return 1;
}