From 8f24941533cc9f66b6e4fe4bc6891c251f5aa37e Mon Sep 17 00:00:00 2001 From: Rui Guo Date: Wed, 19 Aug 2009 23:10:22 +0800 Subject: [PATCH] Make the result of screen.windows easier to use. The resulting table does not have holes in index. --- src/lua.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lua.c b/src/lua.c index 2c73ea8..ac29244 100644 --- a/src/lua.c +++ b/src/lua.c @@ -996,18 +996,27 @@ static const struct Xet_reg display_getters[] = { /** Screen {{{ */ +extern struct win *wtab[]; + static int screen_get_windows(lua_State *L) { - struct win *iter; - int count; + struct win **iter = wtab; + int count, i; 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); - } + i = 1; + for (count = 0; count < MAXWIN; count++) + { + if (!*iter) { + iter++; + continue; + } + lua_pushinteger(L, i++); + push_window(L, iter); + lua_settable(L, -3); + iter++; + } return 1; } -- 2.11.4.GIT