diff --git a/common/luaobject.h b/common/luaobject.h index 19aca17f..056368bd 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -106,6 +106,20 @@ luaA_object_ref(lua_State *L, int oud) return p; } +/** Reference an object and return a pointer to it checking its type. + * That only works with userdata. + * \param L The Lua VM state. + * \param oud The object index on the stack. + * \param class The class of object expected + * \return The object reference, or NULL if not referenceable. + */ +static inline void * +luaA_object_ref_class(lua_State *L, int oud, lua_class_t *class) +{ + luaA_checkudata(L, oud, class); + return luaA_object_ref(L, oud); +} + /** Unreference an object and return a pointer to it. * That only works with userdata, table, thread or function. * \param L The Lua VM state. diff --git a/root.c b/root.c index b91067a2..f9540ef5 100644 --- a/root.c +++ b/root.c @@ -126,7 +126,7 @@ luaA_root_keys(lua_State *L) lua_pushnil(L); while(lua_next(L, 1)) - key_array_append(&globalconf.keys, luaA_object_ref(L, -1)); + key_array_append(&globalconf.keys, luaA_object_ref_class(L, -1, &key_class)); int nscreen = xcb_setup_roots_length(xcb_get_setup(globalconf.connection)); diff --git a/tag.c b/tag.c index dfb5365e..31357f90 100644 --- a/tag.c +++ b/tag.c @@ -127,7 +127,7 @@ tag_append_to_screen(lua_State *L, int udx, screen_t *s) int phys_screen = screen_virttophys(screen_index); tag->screen = s; - tag_array_append(&s->tags, luaA_object_ref(globalconf.L, udx)); + tag_array_append(&s->tags, luaA_object_ref_class(globalconf.L, udx, &tag_class)); ewmh_update_net_numbers_of_desktop(phys_screen); ewmh_update_net_desktop_names(phys_screen); ewmh_update_workarea(phys_screen); @@ -210,7 +210,7 @@ tag_client_emit_signal(lua_State *L, tag_t *t, client_t *c, const char *signame) void tag_client(client_t *c) { - tag_t *t = luaA_object_ref(globalconf.L, -1); + tag_t *t = luaA_object_ref_class(globalconf.L, -1, &tag_class); /* don't tag twice */ if(is_client_tagged(c, t)) diff --git a/titlebar.c b/titlebar.c index 2a363308..9d73efe3 100644 --- a/titlebar.c +++ b/titlebar.c @@ -224,7 +224,7 @@ void titlebar_client_attach(client_t *c) { /* check if we can register the object */ - wibox_t *t = luaA_object_ref(globalconf.L, -1); + wibox_t *t = luaA_object_ref_class(globalconf.L, -1, &wibox_class); titlebar_client_detach(c); diff --git a/wibox.c b/wibox.c index 3c51f664..feb8403d 100644 --- a/wibox.c +++ b/wibox.c @@ -738,7 +738,7 @@ wibox_attach(lua_State *L, int udx, screen_t *s) /* duplicate wibox */ lua_pushvalue(L, udx); /* ref it */ - wibox_t *wibox = luaA_object_ref(globalconf.L, -1); + wibox_t *wibox = luaA_object_ref_class(globalconf.L, -1, &wibox_class); wibox_detach(L, udx);