diff --git a/client.h b/client.h index 2efd84a6..40b64e5c 100644 --- a/client.h +++ b/client.h @@ -51,7 +51,6 @@ int luaA_client_newindex(lua_State *); int luaA_client_userdata_new(lua_State *, client_t *); DO_SLIST(client_t, client, client_unref) -DO_LUA_EXPORT_ARRAY(client, "client_array", client_t, client_array_t, luaA_client_userdata_new) #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/lua.h b/lua.h index ac5cdfb5..0fa0fb9e 100644 --- a/lua.h +++ b/lua.h @@ -259,100 +259,5 @@ luaA_generic_pairs(lua_State *L) return 3; } -#define DO_LUA_EXPORT_ARRAY(pfx, typename, type, atype, ctor) \ - static inline int \ - luaA_##pfx##_array_index(lua_State *L) \ - { \ - atype *value = lua_touserdata(L, 1); \ - type **obj; \ - int idx; \ - \ - if ((obj = lua_touserdata(L, 2))) \ - { \ - for (idx = 0; idx < value->len; idx++) \ - if (value->tab[idx] == *obj) \ - return ctor(L, value->tab[idx]); \ - return 0; \ - } \ - \ - idx = luaL_checknumber(L, 2) - 1; \ - if (idx < 0 || idx >= value->len) \ - return 0; \ - \ - return ctor(L, value->tab[idx]); \ - } \ - static inline int \ - luaA_##pfx##_array_newindex(lua_State *L) \ - { \ - atype *value = lua_touserdata(L, 1); \ - int idx = luaL_checknumber(L, 2); \ - type **elem = luaL_checkudata(L, 3, #pfx); \ - pfx##_array_splice(value, idx - 1, 1, elem, 1); \ - return 0; \ - } \ - static inline int \ - luaA_##pfx##_array_len(lua_State *L) \ - { \ - atype *value = lua_touserdata(L, 1); \ - lua_pushnumber(L, value->len); \ - return 1; \ - } \ - static inline int \ - luaA_##pfx##_array_tostring(lua_State *L) \ - { \ - atype *value = lua_touserdata(L, 1); \ - lua_pushfstring(L, "["typename" udata(%p)]", value); \ - return 1; \ - } \ - static inline int \ - luaA_##pfx##_array_next(lua_State *L) \ - { \ - atype *value = lua_touserdata(L, 1); \ - if(value) \ - { \ - lua_settop(L, 2); \ - if(lua_isnumber(L, 2)) \ - { \ - int idx = lua_tonumber(L, 2); \ - if(idx >= 0 && idx < value->len) \ - { \ - lua_pushnumber(L, idx + 1); \ - ctor(L, value->tab[idx]); \ - return 2; \ - } \ - } \ - else if(lua_isnil(L, 2)) \ - { \ - if(value->len) \ - { \ - lua_pushnumber(L, 1); \ - ctor(L, value->tab[0]); \ - return 2; \ - } \ - } \ - } \ - return 0; \ - } \ - static inline void \ - luaA_##pfx##_array_export(lua_State *L, atype *arr) \ - { \ - lua_pushlightuserdata(L, arr); \ - lua_newtable(L); \ - lua_pushcfunction(L, luaA_##pfx##_array_index); \ - lua_setfield(L, -2, "__index"); \ - lua_pushcfunction(L, luaA_##pfx##_array_tostring); \ - lua_setfield(L, -2, "__tostring"); \ - lua_pushcfunction(L, luaA_##pfx##_array_next); \ - lua_setfield(L, -2, "__next"); \ - lua_pushcfunction(L, luaA_##pfx##_array_next); \ - lua_pushcclosure(L, luaA_generic_pairs, 1); \ - lua_setfield(L, -2, "__pairs"); \ - lua_pushcfunction(L, luaA_##pfx##_array_newindex); \ - lua_setfield(L, -2, "__newindex"); \ - lua_pushcfunction(L, luaA_##pfx##_array_len); \ - lua_setfield(L, -2, "__len"); \ - lua_setmetatable(L, -2); \ - } - #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/tag.c b/tag.c index 55adefa4..23167eb6 100644 --- a/tag.c +++ b/tag.c @@ -349,6 +349,8 @@ luaA_tag_index(lua_State *L) size_t len; tag_t **tag = luaA_checkudata(L, 1, "tag"); const char *attr; + client_array_t *clients; + int i; if(luaA_usemetatable(L, 1, 2)) return 1; @@ -381,7 +383,14 @@ luaA_tag_index(lua_State *L) lua_pushnumber(L, (*tag)->ncol); break; case A_TK_CLIENTS: - luaA_client_array_export(L, &(*tag)->clients); + clients = &(*tag)->clients; + luaA_otable_new(L); + for(i = 0; i < clients->len; i++) + { + luaA_client_userdata_new(L, clients->tab[i]); + luaA_client_userdata_new(L, clients->tab[i]); + lua_rawset(L, -3); + } break; default: return 0;