diff --git a/button.c b/button.c index 8ee117f77..54e7d0dad 100644 --- a/button.c +++ b/button.c @@ -91,7 +91,7 @@ luaA_button_array_set(lua_State *L, int oidx, int idx, button_array_t *buttons) lua_pushnil(L); while(lua_next(L, idx)) - if(luaA_toudata(L, -1, "button")) + if(luaA_toudata(L, -1, &button_class)) button_array_append(buttons, luaA_object_ref_item(L, oidx, -1)); else lua_pop(L, 1); diff --git a/button.h b/button.h index 246def300..72730c2b5 100644 --- a/button.h +++ b/button.h @@ -35,7 +35,7 @@ struct button_t }; lua_class_t button_class; -LUA_OBJECT_FUNCS(button_class, button_t, button, "button") +LUA_OBJECT_FUNCS(button_class, button_t, button) ARRAY_FUNCS(button_t *, button, DO_NOTHING) int luaA_button_array_get(lua_State *, int, button_array_t *); diff --git a/client.c b/client.c index e19a1c989..f44225993 100644 --- a/client.c +++ b/client.c @@ -35,7 +35,7 @@ client_t * luaA_client_checkudata(lua_State *L, int ud) { - client_t *c = luaL_checkudata(L, ud, "client"); + client_t *c = luaA_checkudata(L, ud, &client_class); if(c->invalid) luaL_error(L, "client is invalid\n"); return c; @@ -48,7 +48,7 @@ luaA_client_checkudata(lua_State *L, int ud) static int luaA_client_gc(lua_State *L) { - client_t *c = luaL_checkudata(L, 1, "client"); + client_t *c = luaA_checkudata(L, 1, &client_class); button_array_wipe(&c->buttons); key_array_wipe(&c->keys); xcb_get_wm_protocols_reply_wipe(&c->protocols); diff --git a/client.h b/client.h index cc85a2971..cfa8d134a 100644 --- a/client.h +++ b/client.h @@ -167,7 +167,7 @@ ARRAY_FUNCS(client_t *, client, DO_NOTHING) /** Client class */ lua_class_t client_class; -LUA_OBJECT_FUNCS(client_class, client_t, client, "client") +LUA_OBJECT_FUNCS(client_class, client_t, client) #define client_need_reban(c) \ do { \ diff --git a/common/luaclass.c b/common/luaclass.c index e2f4bf321..654f85a7c 100644 --- a/common/luaclass.c +++ b/common/luaclass.c @@ -34,34 +34,61 @@ struct lua_class_property lua_class_propfunc_t newindex; }; -typedef struct +DO_ARRAY(lua_class_t *, lua_class, DO_NOTHING) + +static lua_class_array_t luaA_classes; + +/** Convert a object to a udata if possible. + * \param L The Lua VM state. + * \param ud The index. + * \param class The wanted class. + * \return A pointer to the object, NULL otherwise. + */ +void * +luaA_toudata(lua_State *L, int ud, lua_class_t *class) { - int id; - lua_class_t *class; -} lua_class_id_t; + void *p = lua_touserdata(L, ud); + if(p) /* value is a userdata? */ + if(lua_getmetatable(L, ud)) /* does it have a metatable? */ + { + lua_pushlightuserdata(L, class); + lua_rawget(L, LUA_REGISTRYINDEX); + if(!lua_rawequal(L, -1, -2)) /* does it have the correct mt? */ + p = NULL; + lua_pop(L, 2); /* remove both metatables */ + } + return p; +} -DO_ARRAY(lua_class_id_t, lua_class_id, DO_NOTHING) +/** Check for a udata class. + * \param L The Lua VM state. + * \param ud The object index on the stack. + * \param class The wanted class. + */ +void * +luaA_checkudata(lua_State *L, int ud, lua_class_t *class) +{ + void *p = luaA_toudata(L, ud, class); + if(!p) + luaL_typerror(L, ud, class->name); + return p; +} -static lua_class_id_array_t luaA_classes; - -/* This has to be initialized to the highest natural type of Lua */ -#define LUA_HIGHEST_TYPE LUA_TTHREAD - -/** Enhanced version of lua_type that recognizes setup Lua classes. +/** Get an object lua_class. * \param L The Lua VM state. * \param idx The index of the object on the stack. */ -int -luaA_type(lua_State *L, int idx) +lua_class_t * +luaA_class_get(lua_State *L, int idx) { int type = lua_type(L, idx); if(type == LUA_TUSERDATA) foreach(class, luaA_classes) - if(luaA_toudata(L, idx, class->class->name)) - return class->id; + if(luaA_toudata(L, idx, *class)) + return *class; - return type; + return NULL; } /** Enhanced version of lua_typename that recognizes setup Lua classes. @@ -71,12 +98,14 @@ luaA_type(lua_State *L, int idx) const char * luaA_typename(lua_State *L, int idx) { - int type = luaA_type(L, idx); + int type = lua_type(L, idx); - if(type > LUA_HIGHEST_TYPE) - foreach(class, luaA_classes) - if(class->id == type) - return class->class->name; + if(type == LUA_TUSERDATA) + { + lua_class_t *lua_class = luaA_class_get(L, idx); + if(lua_class) + return lua_class->name; + } return lua_typename(L, type); } @@ -129,18 +158,27 @@ luaA_class_setup(lua_State *L, lua_class_t *class, const struct luaL_reg methods[], const struct luaL_reg meta[]) { - static int class_type_counter = LUA_HIGHEST_TYPE; + /* Create the metatable */ + lua_newtable(L); + /* Register it with class pointer as key in the registry */ + lua_pushlightuserdata(L, class); + /* Duplicate the metatable */ + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); - luaA_openlib(L, name, methods, meta); + lua_pushvalue(L, -1); /* dup metatable 2 */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable 1 */ + + luaL_register(L, NULL, meta); /* 1 */ + luaL_register(L, name, methods); /* 2 */ + lua_pushvalue(L, -1); /* dup self as metatable 3 */ + lua_setmetatable(L, -2); /* set self as metatable 2 */ + lua_pop(L, 2); class->allocator = allocator; class->name = name; - lua_class_id_array_append(&luaA_classes, (lua_class_id_t) - { - .id = ++class_type_counter, - .class = class, - }); + lua_class_array_append(&luaA_classes, class); } void @@ -214,29 +252,6 @@ lua_class_property_array_getbyid(lua_class_property_array_t *arr, return lua_class_property_array_lookup(arr, &lookup_prop); } -/** Get the class of an object. - * \param L The Lua VM state. - * \param idx The index of the object on the stack. - * \return The class if found, NULL otherwise. - */ -static lua_class_t * -luaA_class_get(lua_State *L, int idx) -{ - int type = luaA_type(L, 1); - - /* Find the class. */ - lua_class_t *class = NULL; - - foreach(classid, luaA_classes) - if(classid->id == type) - { - class = classid->class; - break; - } - - return class; -} - /** Get a property of a object. * \param L The Lua VM state. * \param lua_class The Lua class. @@ -271,7 +286,7 @@ luaA_class_index(lua_State *L) /* Property does exist and has an index callback */ if(prop && prop->index) - return prop->index(L, luaL_checkudata(L, 1, class->name)); + return prop->index(L, luaA_checkudata(L, 1, class)); return 0; } @@ -293,7 +308,7 @@ luaA_class_newindex(lua_State *L) /* Property does exist and has a newindex callback */ if(prop && prop->newindex) - return prop->newindex(L, luaL_checkudata(L, 1, class->name)); + return prop->newindex(L, luaA_checkudata(L, 1, class)); return 0; } diff --git a/common/luaclass.h b/common/luaclass.h index 2d0325ab8..0d17fabaf 100644 --- a/common/luaclass.h +++ b/common/luaclass.h @@ -55,8 +55,8 @@ typedef struct typedef int (*lua_class_propfunc_t)(lua_State *, lua_object_t *); -int luaA_type(lua_State *, int); const char * luaA_typename(lua_State *, int); +lua_class_t * luaA_class_get(lua_State *, int); void luaA_class_add_signal(lua_State *, lua_class_t *, const char *, int); void luaA_class_remove_signal(lua_State *, lua_class_t *, const char *, int); @@ -74,6 +74,9 @@ int luaA_class_index(lua_State *); int luaA_class_newindex(lua_State *); int luaA_class_new(lua_State *, lua_class_t *); +void * luaA_checkudata(lua_State *, int, lua_class_t *); +void * luaA_toudata(lua_State *L, int ud, lua_class_t *); + #define LUA_CLASS_FUNCS(prefix, lua_class) \ static inline int \ luaA_##prefix##_class_add_signal(lua_State *L) \ diff --git a/common/lualib.h b/common/lualib.h index c611b90cd..dce2d5d39 100644 --- a/common/lualib.h +++ b/common/lualib.h @@ -120,27 +120,6 @@ luaA_dofunction(lua_State *L, int nargs, int nret) return true; } -/** Convert a object to a udata if possible. - * \param L The Lua VM state. - * \param ud The index. - * \param tname The type name. - * \return A pointer to the object, NULL otherwise. - */ -static inline void * -luaA_toudata(lua_State *L, int ud, const char *tname) -{ - void *p = lua_touserdata(L, ud); - if(p) /* value is a userdata? */ - if(lua_getmetatable(L, ud)) /* does it have a metatable? */ - { - lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - if(!lua_rawequal(L, -1, -2)) /* does it have the correct mt? */ - p = NULL; - lua_pop(L, 2); /* remove both metatables */ - } - return p; -} - #define luaA_checktable(L, n) \ do { \ if(!lua_istable(L, n)) \ diff --git a/common/luaobject.c b/common/luaobject.c index 03c6f1eb8..72fe303ff 100644 --- a/common/luaobject.c +++ b/common/luaobject.c @@ -139,6 +139,15 @@ luaA_object_decref(lua_State *L, int tud, void *pointer) } } +int +luaA_settype(lua_State *L, lua_class_t *lua_class) +{ + lua_pushlightuserdata(L, lua_class); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_setmetatable(L, -2); + return 1; +} + /** Add a signal to an object. * \param L The Lua VM state. * \param oud The object index on the stack. @@ -219,4 +228,24 @@ luaA_object_emit_signal_simple(lua_State *L) return 0; } +int +luaA_object_tostring(lua_State *L) +{ + lua_class_t *lua_class = luaA_class_get(L, 1); + lua_pushfstring(L, "%s: %p", lua_class->name, luaA_checkudata(L, 1, lua_class)); + return 1; +} + +/** Garbage collect a Lua object. + * \param L The Lua VM state. + * \return The number of elements pushed on stack. + */ +int +luaA_object_gc(lua_State *L) +{ + lua_object_t *item = lua_touserdata(L, 1); + signal_array_wipe(&item->signals); + return 0; +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/luaobject.h b/common/luaobject.h index af75d1af9..e338fdad9 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -24,16 +24,9 @@ #include "common/luaclass.h" -static inline int -luaA_settype(lua_State *L, const char *type) -{ - luaL_getmetatable(L, type); - lua_setmetatable(L, -2); - return 1; -} - #define LUAA_OBJECT_REGISTRY_KEY "awesome.object.registry" +int luaA_settype(lua_State *, lua_class_t *); void luaA_object_setup(lua_State *); void * luaA_object_incref(lua_State *, int, int); void luaA_object_decref(lua_State *, int, void *); @@ -149,14 +142,14 @@ int luaA_object_add_signal_simple(lua_State *); int luaA_object_remove_signal_simple(lua_State *); int luaA_object_emit_signal_simple(lua_State *); -#define LUA_OBJECT_FUNCS(lua_class, type, prefix, lua_type) \ +#define LUA_OBJECT_FUNCS(lua_class, type, prefix) \ LUA_CLASS_FUNCS(prefix, lua_class) \ static inline type * \ prefix##_new(lua_State *L) \ { \ type *p = lua_newuserdata(L, sizeof(type)); \ p_clear(p, 1); \ - luaA_settype(L, lua_type); \ + luaA_settype(L, &(lua_class)); \ lua_newtable(L); \ lua_newtable(L); \ lua_setmetatable(L, -2); \ @@ -164,13 +157,6 @@ int luaA_object_emit_signal_simple(lua_State *); lua_pushvalue(L, -1); \ luaA_class_emit_signal(L, &(lua_class), "new", 1); \ return p; \ - } \ - \ - static inline int \ - luaA_##prefix##_tostring(lua_State *L) \ - { \ - lua_pushfstring(L, lua_type ": %p", luaL_checkudata(L, 1, lua_type)); \ - return 1; \ } #define LUA_OBJECT_EXPORT_PROPERTY(pfx, type, field, pusher) \ @@ -181,20 +167,11 @@ int luaA_object_emit_signal_simple(lua_State *); return 1; \ } -/** Garbage collect a Lua object. - * \param L The Lua VM state. - * \return The number of elements pushed on stack. - */ -static inline int -luaA_object_gc(lua_State *L) -{ - lua_object_t *item = lua_touserdata(L, 1); - signal_array_wipe(&item->signals); - return 0; -} +int luaA_object_tostring(lua_State *); +int luaA_object_gc(lua_State *); #define LUA_OBJECT_META(prefix) \ - { "__tostring", luaA_##prefix##_tostring }, \ + { "__tostring", luaA_object_tostring }, \ { "add_signal", luaA_object_add_signal_simple }, \ { "remove_signal", luaA_object_remove_signal_simple }, \ { "emit_signal", luaA_object_emit_signal_simple }, diff --git a/image.c b/image.c index 9e31ad297..3da494a8a 100644 --- a/image.c +++ b/image.c @@ -27,7 +27,7 @@ static int luaA_image_gc(lua_State *L) { - image_t *p = luaL_checkudata(L, 1, "image"); + image_t *p = luaA_checkudata(L, 1, &image_class); imlib_context_set_image(p->image); imlib_free_image(); p_delete(&p->data); @@ -312,7 +312,7 @@ luaA_image_argb32_new(lua_State *L) static int luaA_image_orientate(lua_State *L) { - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); int orientation = luaL_checknumber(L, 2); imlib_context_set_image(image->image); @@ -334,7 +334,7 @@ luaA_image_orientate(lua_State *L) static int luaA_image_rotate(lua_State *L) { - image_t *image = luaL_checkudata(L, 1, "image"), *new; + image_t *image = luaA_checkudata(L, 1, &image_class), *new; double angle = luaL_checknumber(L, 2); new = image_new(L); @@ -358,7 +358,7 @@ luaA_image_rotate(lua_State *L) static int luaA_image_crop(lua_State *L) { - image_t *image = luaL_checkudata(L, 1, "image"), *new; + image_t *image = luaA_checkudata(L, 1, &image_class), *new; int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); int w = luaL_checkint(L, 4); @@ -388,7 +388,7 @@ luaA_image_crop(lua_State *L) static int luaA_image_crop_and_scale(lua_State *L) { - image_t *image = luaL_checkudata(L, 1, "image"), *new; + image_t *image = luaA_checkudata(L, 1, &image_class), *new; int source_x = luaL_checkint(L, 2); int source_y = luaL_checkint(L, 3); int w = luaL_checkint(L, 4); @@ -421,7 +421,7 @@ luaA_image_draw_pixel(lua_State *L) size_t len; color_t color; color_init_cookie_t cookie; - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); const char *buf = luaL_checklstring(L, 4, &len); @@ -455,7 +455,7 @@ luaA_image_draw_line(lua_State *L) size_t len; color_t color; color_init_cookie_t cookie; - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); int x1 = luaL_checkint(L, 2); int y1 = luaL_checkint(L, 3); int x2 = luaL_checkint(L, 4); @@ -492,7 +492,7 @@ luaA_image_draw_rectangle(lua_State *L) size_t len; color_t color; color_init_cookie_t cookie; - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); int width = luaL_checkint(L, 4); @@ -584,7 +584,7 @@ luaA_table_to_color_range(lua_State *L, int ud) static int luaA_image_draw_rectangle_gradient(lua_State *L) { - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); int width = luaL_checkint(L, 4); @@ -627,7 +627,7 @@ luaA_image_draw_circle(lua_State *L) size_t len; color_t color; color_init_cookie_t cookie; - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); int ah = luaL_checkint(L, 4); @@ -664,7 +664,7 @@ luaA_image_draw_circle(lua_State *L) static int luaA_image_save(lua_State *L) { - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); const char *path = luaL_checkstring(L, 2); Imlib_Load_Error err; @@ -697,8 +697,8 @@ luaA_image_save(lua_State *L) static int luaA_image_insert(lua_State *L) { - image_t *image_target = luaL_checkudata(L, 1, "image"); - image_t *image_source = luaL_checkudata(L, 2, "image"); + image_t *image_target = luaA_checkudata(L, 1, &image_class); + image_t *image_source = luaA_checkudata(L, 2, &image_class); int xoff = luaL_optnumber(L, 3, 0); int yoff = luaL_optnumber(L, 4, 0); @@ -743,7 +743,7 @@ luaA_image_index(lua_State *L) if(luaA_usemetatable(L, 1, 2)) return 1; - image_t *image = luaL_checkudata(L, 1, "image"); + image_t *image = luaA_checkudata(L, 1, &image_class); size_t len; const char *attr = luaL_checklstring(L, 2, &len); diff --git a/image.h b/image.h index 82b69e007..08c0164cd 100644 --- a/image.h +++ b/image.h @@ -41,7 +41,7 @@ typedef struct } image_t; lua_class_t image_class; -LUA_OBJECT_FUNCS(image_class, image_t, image, "image") +LUA_OBJECT_FUNCS(image_class, image_t, image) int image_new_from_argb32(int, int, uint32_t *); uint8_t * image_getdata(image_t *); diff --git a/key.c b/key.c index d0c5f3e72..45f9b9e40 100644 --- a/key.c +++ b/key.c @@ -968,7 +968,7 @@ key_getkeysym(xcb_keycode_t detail, uint16_t state) static void luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len) { - keyb_t *key = luaL_checkudata(L, ud, "key"); + keyb_t *key = luaA_checkudata(L, ud, &key_class); if(len) { if(*str != '#') @@ -1063,7 +1063,7 @@ luaA_key_array_set(lua_State *L, int oidx, int idx, key_array_t *keys) lua_pushnil(L); while(lua_next(L, idx)) - if(luaA_toudata(L, -1, "key")) + if(luaA_toudata(L, -1, &key_class)) key_array_append(keys, luaA_object_ref_item(L, oidx, -1)); else lua_pop(L, 1); diff --git a/key.h b/key.h index 7d8ede975..ef973c2c1 100644 --- a/key.h +++ b/key.h @@ -19,8 +19,8 @@ * */ -#ifndef AWESOME_KEYBINDING_H -#define AWESOME_KEYBINDING_H +#ifndef AWESOME_KEY_H +#define AWESOME_KEY_H #include "luaa.h" @@ -36,7 +36,7 @@ typedef struct keyb_t } keyb_t; lua_class_t key_class; -LUA_OBJECT_FUNCS(key_class, keyb_t, key, "key") +LUA_OBJECT_FUNCS(key_class, keyb_t, key) DO_ARRAY(keyb_t *, key, DO_NOTHING) void key_class_setup(lua_State *); diff --git a/luaa.c b/luaa.c index a77902462..a5bef8f7e 100644 --- a/luaa.c +++ b/luaa.c @@ -345,7 +345,7 @@ luaA_wtable_newindex(lua_State *L) /* get current key value in content table */ lua_rawget(L, lua_upvalueindex(1)); /* if value is a widget, notify change */ - if(lua_istable(L, -1) || luaA_toudata(L, -1, "widget")) + if(lua_istable(L, -1) || luaA_toudata(L, -1, &widget_class)) invalid = true; lua_pop(L, 1); /* remove value */ @@ -356,7 +356,7 @@ luaA_wtable_newindex(lua_State *L) luaA_table2wtable(L); invalid = true; } - else if(!invalid && luaA_toudata(L, 3, "widget")) + else if(!invalid && luaA_toudata(L, 3, &widget_class)) invalid = true; /* upvalue 1 is content table */ diff --git a/tag.c b/tag.c index bd9d6712e..a3dc4d4c7 100644 --- a/tag.c +++ b/tag.c @@ -26,7 +26,7 @@ #include "widget.h" static lua_class_t tag_class; -LUA_OBJECT_FUNCS(tag_class, tag_t, tag, "tag") +LUA_OBJECT_FUNCS(tag_class, tag_t, tag) void tag_unref_simplified(tag_t **tag) @@ -41,7 +41,7 @@ tag_unref_simplified(tag_t **tag) static int luaA_tag_gc(lua_State *L) { - tag_t *tag = luaL_checkudata(L, 1, "tag"); + tag_t *tag = luaA_checkudata(L, 1, &tag_class); client_array_wipe(&tag->clients); p_delete(&tag->name); return luaA_object_gc(L); @@ -55,7 +55,7 @@ luaA_tag_gc(lua_State *L) static void tag_view(lua_State *L, int udx, bool view) { - tag_t *tag = luaL_checkudata(L, udx, "tag"); + tag_t *tag = luaA_checkudata(L, udx, &tag_class); if(tag->selected != view) { tag->selected = view; @@ -92,7 +92,7 @@ tag_view(lua_State *L, int udx, bool view) void tag_append_to_screen(lua_State *L, int udx, screen_t *s) { - tag_t *tag = luaL_checkudata(globalconf.L, udx, "tag"); + tag_t *tag = luaA_checkudata(globalconf.L, udx, &tag_class); /* can't attach a tag twice */ if(tag->screen) @@ -306,7 +306,7 @@ luaA_tag_new(lua_State *L) static int luaA_tag_clients(lua_State *L) { - tag_t *tag = luaL_checkudata(L, 1, "tag"); + tag_t *tag = luaA_checkudata(L, 1, &tag_class); client_array_t *clients = &tag->clients; int i; diff --git a/timer.c b/timer.c index 9ca41dfe5..f3acc28dd 100644 --- a/timer.c +++ b/timer.c @@ -33,7 +33,7 @@ typedef struct } atimer_t; static lua_class_t timer_class; -LUA_OBJECT_FUNCS(timer_class, atimer_t, timer, "timer") +LUA_OBJECT_FUNCS(timer_class, atimer_t, timer) static void ev_timer_emit_signal(struct ev_loop *loop, struct ev_timer *w, int revents) @@ -47,7 +47,7 @@ static int luaA_timer_new(lua_State *L) { luaA_class_new(L, &timer_class); - atimer_t *timer = luaL_checkudata(L, -1, "timer"); + atimer_t *timer = luaA_checkudata(L, -1, &timer_class); timer->timer.data = timer; ev_set_cb(&timer->timer, ev_timer_emit_signal); return 1; @@ -72,7 +72,7 @@ luaA_timer_get_timeout(lua_State *L, atimer_t *timer) static int luaA_timer_start(lua_State *L) { - atimer_t *timer = luaL_checkudata(L, 1, "timer"); + atimer_t *timer = luaA_checkudata(L, 1, &timer_class); if(timer->started) luaA_warn(L, "timer already started"); else @@ -87,7 +87,7 @@ luaA_timer_start(lua_State *L) static int luaA_timer_stop(lua_State *L) { - atimer_t *timer = luaL_checkudata(L, 1, "timer"); + atimer_t *timer = luaA_checkudata(L, 1, &timer_class); if(timer->started) { ev_timer_stop(globalconf.loop, &timer->timer); diff --git a/wibox.c b/wibox.c index 56379b728..905cbd849 100644 --- a/wibox.c +++ b/wibox.c @@ -37,7 +37,7 @@ static int luaA_wibox_gc(lua_State *L) { - wibox_t *wibox = luaL_checkudata(L, 1, "wibox"); + wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class); p_delete(&wibox->cursor); wibox_wipe(wibox); button_array_wipe(&wibox->buttons); @@ -839,7 +839,7 @@ static int luaA_wibox_index(lua_State *L) { size_t len; - wibox_t *wibox = luaL_checkudata(L, 1, "wibox"); + wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class); const char *attr = luaL_checklstring(L, 2, &len); if(luaA_usemetatable(L, 1, 2)) @@ -924,7 +924,7 @@ luaA_wibox_index(lua_State *L) static int luaA_wibox_geometry(lua_State *L) { - wibox_t *wibox = luaL_checkudata(L, 1, "wibox"); + wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class); if(lua_gettop(L) == 2) { @@ -961,7 +961,7 @@ static int luaA_wibox_newindex(lua_State *L) { size_t len; - wibox_t *wibox = luaL_checkudata(L, 1, "wibox"); + wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class); const char *buf, *attr = luaL_checklstring(L, 2, &len); awesome_token_t tok; @@ -1153,7 +1153,7 @@ luaA_wibox_newindex(lua_State *L) static int luaA_wibox_buttons(lua_State *L) { - wibox_t *wibox = luaL_checkudata(L, 1, "wibox"); + wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class); if(lua_gettop(L) == 2) { diff --git a/wibox.h b/wibox.h index ce7b109a9..6c17e402b 100644 --- a/wibox.h +++ b/wibox.h @@ -117,7 +117,7 @@ void wibox_border_color_set(wibox_t *, const xcolor_t *); void wibox_orientation_set(wibox_t *, orientation_t); lua_class_t wibox_class; -LUA_OBJECT_FUNCS(wibox_class, wibox_t, wibox, "wibox") +LUA_OBJECT_FUNCS(wibox_class, wibox_t, wibox) #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/widget.c b/widget.c index 31a6e5fd5..25b8f2c75 100644 --- a/widget.c +++ b/widget.c @@ -32,8 +32,7 @@ #include "common/atoms.h" #include "common/xutil.h" -static lua_class_t widget_class; -LUA_OBJECT_FUNCS(widget_class, widget_t, widget, "widget"); +LUA_OBJECT_FUNCS(widget_class, widget_t, widget); /** Collect a widget structure. * \param L The Lua VM state. @@ -42,7 +41,7 @@ LUA_OBJECT_FUNCS(widget_class, widget_t, widget, "widget"); static int luaA_widget_gc(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); if(widget->destructor) widget->destructor(widget); button_array_wipe(&widget->buttons); @@ -115,7 +114,7 @@ luaA_table2widgets(lua_State *L, widget_node_array_t *widgets) } else { - widget_t *widget = luaA_toudata(L, -1, "widget"); + widget_t *widget = luaA_toudata(L, -1, &widget_class); if(widget) { widget_node_t w; @@ -405,7 +404,7 @@ luaA_widget_new(lua_State *L) { luaA_class_new(L, &widget_class); - widget_t *w = luaL_checkudata(L, -1, "widget"); + widget_t *w = luaA_checkudata(L, -1, &widget_class); /* Set visible by default. */ w->isvisible = true; @@ -423,7 +422,7 @@ luaA_widget_new(lua_State *L) static int luaA_widget_buttons(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); if(lua_gettop(L) == 2) { @@ -455,7 +454,7 @@ luaA_widget_index(lua_State *L) return 1; /* Then call special widget index */ - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); return widget->index ? widget->index(L, token) : 0; } @@ -474,14 +473,14 @@ luaA_widget_newindex(lua_State *L) luaA_class_newindex(L); /* Then call special widget newindex */ - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); return widget->newindex ? widget->newindex(L, token) : 0; } static int luaA_widget_extents(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); area_t g = { .x = 0, .y = 0, diff --git a/widget.h b/widget.h index c4b8d3a5f..2d6aec5d2 100644 --- a/widget.h +++ b/widget.h @@ -69,6 +69,7 @@ bool widget_geometries(wibox_t *); void widget_invalidate_bywidget(widget_t *); void widget_invalidate_bytype(widget_constructor_t *); +lua_class_t widget_class; void widget_class_setup(lua_State *); widget_constructor_t widget_textbox; diff --git a/widgets/graph.c b/widgets/graph.c index 878a1ac7c..771508a1e 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -305,7 +305,7 @@ graph_draw(widget_t *widget, draw_context_t *ctx, static int luaA_graph_plot_properties_set(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); graph_data_t *d = widget->data; float max_value; const char *title, *buf; @@ -370,7 +370,7 @@ luaA_graph_plot_properties_set(lua_State *L) static int luaA_graph_plot_data_add(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); graph_data_t *d = widget->data; plot_t *plot = NULL; const char *title = luaL_checkstring(L, 2); @@ -448,7 +448,7 @@ luaA_graph_plot_data_add(lua_State *L) static int luaA_graph_index(lua_State *L, awesome_token_t token) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); graph_data_t *d = widget->data; switch(token) @@ -500,7 +500,7 @@ static int luaA_graph_newindex(lua_State *L, awesome_token_t token) { size_t len; - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); graph_data_t *d = widget->data; const char *buf; int width; diff --git a/widgets/imagebox.c b/widgets/imagebox.c index 16306549d..e5aedf773 100644 --- a/widgets/imagebox.c +++ b/widgets/imagebox.c @@ -102,7 +102,7 @@ imagebox_destructor(widget_t *w) static int luaA_imagebox_index(lua_State *L, awesome_token_t token) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); imagebox_data_t *d = widget->data; switch(token) @@ -131,7 +131,7 @@ luaA_imagebox_index(lua_State *L, awesome_token_t token) static int luaA_imagebox_newindex(lua_State *L, awesome_token_t token) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); imagebox_data_t *d = widget->data; switch(token) diff --git a/widgets/progressbar.c b/widgets/progressbar.c index afb48fa09..11cfef8fe 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -443,7 +443,7 @@ static int luaA_progressbar_bar_properties_set(lua_State *L) { size_t len; - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); const char *buf, *title = luaL_checkstring(L, 2); bar_t *bar; progressbar_data_t *d = widget->data; @@ -508,7 +508,7 @@ luaA_progressbar_bar_properties_set(lua_State *L) static int luaA_progressbar_bar_data_add(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); const char *title = luaL_checkstring(L, 2); progressbar_data_t *d = widget->data; bar_t *bar; @@ -543,7 +543,7 @@ luaA_progressbar_bar_data_add(lua_State *L) static int luaA_progressbar_index(lua_State *L, awesome_token_t token) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); progressbar_data_t *d = widget->data; switch(token) @@ -593,7 +593,7 @@ luaA_progressbar_index(lua_State *L, awesome_token_t token) static int luaA_progressbar_newindex(lua_State *L, awesome_token_t token) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); progressbar_data_t *d = widget->data; switch(token) diff --git a/widgets/textbox.c b/widgets/textbox.c index 72d69cc04..175616f35 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -145,7 +145,7 @@ textbox_destructor(widget_t *w) static int luaA_textbox_margin(lua_State *L) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); textbox_data_t *d = widget->data; if(lua_gettop(L) == 2) @@ -178,7 +178,7 @@ luaA_textbox_margin(lua_State *L) static int luaA_textbox_index(lua_State *L, awesome_token_t token) { - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); textbox_data_t *d = widget->data; switch(token) @@ -257,7 +257,7 @@ static int luaA_textbox_newindex(lua_State *L, awesome_token_t token) { size_t len = 0; - widget_t *widget = luaL_checkudata(L, 1, "widget"); + widget_t *widget = luaA_checkudata(L, 1, &widget_class); const char *buf = NULL; textbox_data_t *d = widget->data;