From 0bdaed2704c3b6315366f6c1f3d098cf707febe6 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 4 Oct 2013 15:24:09 +0200 Subject: [PATCH] screen: Fix screen equality comparison (FS#1151) We did some black magic which broke and was replaced with more black magic. This now broke using screen objects as table indexes: $ echo 'local l, s = {}, screen[1] ; l[s] = 42 ; return l[s]' | awesome-client double 42 $ echo 'local l, s = {}, screen[1] ; l[s] = 42 ; return l[screen[1]]' | awesome-client Fix this by using just a single lua userdata for representing a screen object. It would be even better if screens were allocated with lua, but that doesn't really provide any benefits right now and would be more complicated... Signed-off-by: Uli Schlachter --- screen.c | 32 ++++++++++---------------------- screen.h | 2 ++ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/screen.c b/screen.c index c30ec393..e04e310b 100644 --- a/screen.c +++ b/screen.c @@ -71,8 +71,17 @@ screen_add(screen_t new_screen) MAX(new_screen.geometry.height, screen_to_test->geometry.height); return; } + signal_add(&new_screen.signals, "property::workarea"); screen_array_append(&globalconf.screens, new_screen); + + /* Allocate the lua userdata object representing this screen */ + screen_t *s = &globalconf.screens.tab[globalconf.screens.len-1]; + screen_t **ps = lua_newuserdata(globalconf.L, sizeof(*ps)); + *ps = s; + luaL_getmetatable(globalconf.L, "screen"); + lua_setmetatable(globalconf.L, -2); + s->userdata = luaA_object_ref(globalconf.L, -1); } static bool @@ -398,10 +407,7 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize) static int luaA_pushscreen(lua_State *L, screen_t *s) { - screen_t **ps = lua_newuserdata(L, sizeof(*ps)); - *ps = s; - luaL_getmetatable(L, "screen"); - lua_setmetatable(L, -2); + luaA_object_push(L, s->userdata); return 1; } @@ -499,23 +505,6 @@ luaA_screen_index(lua_State *L) return 0; } -/** A screen. - * \param L The Lua VM state. - * \return The number of elements pushed on stack. - */ -static int -luaA_screen_equal(lua_State *L) -{ - screen_t **ps1; - screen_t **ps2; - - ps1 = luaL_checkudata(L, 1, "screen"); - ps2 = luaL_checkudata(L, 2, "screen"); - lua_pushboolean(L, *ps1 == *ps2); - - return 1; -} - /** Add a signal to a screen. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -631,7 +620,6 @@ const struct luaL_Reg awesome_screen_meta[] = { "disconnect_signal", luaA_screen_disconnect_signal }, { "emit_signal", luaA_screen_emit_signal }, { "__index", luaA_screen_index }, - { "__eq", luaA_screen_equal }, { NULL, NULL } }; diff --git a/screen.h b/screen.h index 08c0881f..c812baaa 100644 --- a/screen.h +++ b/screen.h @@ -36,6 +36,8 @@ struct a_screen signal_array_t signals; /** The screen outputs informations */ screen_output_array_t outputs; + /** The lua userdata representing this screen */ + void *userdata; }; ARRAY_FUNCS(screen_t, screen, DO_NOTHING)