objects: Add .valid property (Fixes #110)

This property is especially useful for client objects which are unusable after
unmanage. "Unusuable" here means that pretty much everything you do with the
client object results in a lua error.

Syntax is c.valid.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2015-02-15 12:16:03 +01:00
parent 62346a75a9
commit f5610fa920
2 changed files with 14 additions and 0 deletions

View File

@ -369,6 +369,19 @@ luaA_class_index(lua_State *L)
lua_class_t *class = luaA_class_get(L, 1); lua_class_t *class = luaA_class_get(L, 1);
/* Is this the special 'valid' property? This is the only property
* accessible for invalid objects and thus needs special handling. */
const char *attr = luaL_checkstring(L, 2);
if (A_STREQ(attr, "valid"))
{
void *p = luaA_toudata(L, 1, class);
if (class->checker)
lua_pushboolean(L, p != NULL && class->checker(p));
else
lua_pushboolean(L, p != NULL);
return 1;
}
lua_class_property_t *prop = luaA_class_property_get(L, class, 2); lua_class_property_t *prop = luaA_class_property_get(L, class, 2);
/* Property does exist and has an index callback */ /* Property does exist and has an index callback */

View File

@ -47,6 +47,7 @@ module("client")
-- @field shape_client_bounding The client's bounding shape as set by the program as a (native) cairo surface. -- @field shape_client_bounding The client's bounding shape as set by the program as a (native) cairo surface.
-- @field shape_client_clip The client's clip shape as set by the program as a (native) cairo surface. -- @field shape_client_clip The client's clip shape as set by the program as a (native) cairo surface.
-- @field startup_id The FreeDesktop StartId. -- @field startup_id The FreeDesktop StartId.
-- @field valid If the client that this object refers to is still managed by awesome.
-- @class table -- @class table
-- @name client -- @name client