From: Rui Guo Date: Wed, 19 Aug 2009 15:10:22 +0000 (+0800) Subject: Make the result of screen.windows easier to use. X-Git-Url: https://repo.or.cz/w/screen-lua.git/commitdiff_plain/8f24941533cc9f66b6e4fe4bc6891c251f5aa37e Make the result of screen.windows easier to use. The resulting table does not have holes in index. --- 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; }