From 8ed8da2d85c62283d1453627e697b29e34e9ec81 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Sun, 22 Feb 2009 00:19:24 -0500 Subject: [PATCH] Return proper tables For the list of windows, displays and canvases, return proper lua tables. For the list of windows, use the window-number as the key for the returned table. --- src/lua.c | 24 ++++++++++++++++++------ src/scripts/findwindow.lua | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/lua.c b/src/lua.c index 7b51085..26aafe2 100644 --- a/src/lua.c +++ b/src/lua.c @@ -427,10 +427,14 @@ display_get_canvases(lua_State *L) int count; d = check_display(L, 1); - for (iter = d->d_cvlist, count = 0; iter; iter = iter->c_next, count++) + lua_newtable(L); + for (iter = d->d_cvlist, count = 0; iter; iter = iter->c_next, count++) { + lua_pushinteger(L, count); push_canvas(L, &iter); + lua_settable(L, -3); + } - return count; + return 1; } static const luaL_reg display_methods[] = { @@ -478,10 +482,14 @@ screen_get_windows(lua_State *L) struct win *iter; int count; - for (iter = windows, count = 0; iter; iter = iter->w_next, count++) + lua_newtable(L); + for (iter = windows, count = 0; iter; iter = iter->w_next, count++) { + lua_pushinteger(L, iter->w_number); push_window(L, &iter); + lua_settable(L, -3); + } - return count; + return 1; } static int @@ -490,10 +498,14 @@ screen_get_displays(lua_State *L) struct display *iter; int count; - for (iter = displays, count = 0; iter; iter = iter->d_next, count++) + lua_newtable(L); + for (iter = displays, count = 0; iter; iter = iter->d_next, count++) { + lua_pushinteger(L, count); push_display(L, &iter); + lua_settable(L, -3); + } - return count; + return 1; } static int diff --git a/src/scripts/findwindow.lua b/src/scripts/findwindow.lua index d1dbccc..ff393df 100644 --- a/src/scripts/findwindow.lua +++ b/src/scripts/findwindow.lua @@ -1,6 +1,6 @@ function find_window(name) display = screen.display() - canvases = {display:get_canvases()} + canvases = display:get_canvases() for i, c in pairs(canvases) do w = c.window if w ~= nil and (w.title == name or tostring(w.number) == name) then c:select() return end -- 2.11.4.GIT