From 270baeb1537f133ee04688bcf0eb2cb345bd2037 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 4 Jun 2016 00:51:23 +0200 Subject: [PATCH] "Fix" client properties which can be absent (#932) A client c could have no c.machine or no c.pid because the corresponding properties are not set on its window. Previously, the C code would return an empty string or 0 for these values. This commit makes the C code give Lua no value instead (not even a nil). Signed-off-by: Uli Schlachter --- common/luaobject.h | 10 ++++++++++ objects/client.c | 14 +++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/luaobject.h b/common/luaobject.h index c26af6fc..c3e1f056 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -195,6 +195,16 @@ int luaA_object_emit_signal_simple(lua_State *); return 1; \ } +#define LUA_OBJECT_EXPORT_OPTIONAL_PROPERTY(pfx, type, field, pusher, empty_value) \ + static int \ + luaA_##pfx##_get_##field(lua_State *L, type *object) \ + { \ + if (object->field == empty_value) \ + return 0; \ + pusher(L, object->field); \ + return 1; \ + } + int luaA_object_tostring(lua_State *); #define LUA_OBJECT_META(prefix) \ diff --git a/objects/client.c b/objects/client.c index 45ba0830..69f5be80 100644 --- a/objects/client.c +++ b/objects/client.c @@ -2770,15 +2770,16 @@ luaA_client_get_icon_name(lua_State *L, client_t *c) return 1; } +LUA_OBJECT_EXPORT_OPTIONAL_PROPERTY(client, client_t, screen, luaA_object_push, NULL) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, class, lua_pushstring) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, instance, lua_pushstring) -LUA_OBJECT_EXPORT_PROPERTY(client, client_t, machine, lua_pushstring) +LUA_OBJECT_EXPORT_OPTIONAL_PROPERTY(client, client_t, machine, lua_pushstring, NULL) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, role, lua_pushstring) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, transient_for, luaA_object_push) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, skip_taskbar, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, leader_window, lua_pushinteger) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, group_window, lua_pushinteger) -LUA_OBJECT_EXPORT_PROPERTY(client, client_t, pid, lua_pushinteger) +LUA_OBJECT_EXPORT_OPTIONAL_PROPERTY(client, client_t, pid, lua_pushinteger, 0) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, hidden, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, minimized, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, fullscreen, lua_pushboolean) @@ -2819,15 +2820,6 @@ luaA_client_get_content(lua_State *L, client_t *c) return 1; } -static int -luaA_client_get_screen(lua_State *L, client_t *c) -{ - if(!c->screen) - return 0; - luaA_object_push(L, c->screen); - return 1; -} - static int luaA_client_get_icon(lua_State *L, client_t *c) {