diff --git a/button.c b/button.c index 5d9c78cb3..ac3d38cd2 100644 --- a/button.c +++ b/button.c @@ -154,6 +154,7 @@ button_class_setup(lua_State *L) }; luaA_class_setup(L, &button_class, "button", (lua_class_allocator_t) button_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, button_methods, button_meta); luaA_class_add_property(&button_class, A_TK_BUTTON, (lua_class_propfunc_t) luaA_button_set_button, diff --git a/client.c b/client.c index c6070d361..00b496a5c 100644 --- a/client.c +++ b/client.c @@ -2137,6 +2137,7 @@ client_class_setup(lua_State *L) }; luaA_class_setup(L, &client_class, "client", (lua_class_allocator_t) client_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, client_methods, client_meta); luaA_class_add_property(&client_class, A_TK_NAME, NULL, diff --git a/common/luaclass.c b/common/luaclass.c index 8be626d37..85f115aa2 100644 --- a/common/luaclass.c +++ b/common/luaclass.c @@ -155,6 +155,8 @@ void luaA_class_setup(lua_State *L, lua_class_t *class, const char *name, lua_class_allocator_t allocator, + lua_class_propfunc_t index_miss_property, + lua_class_propfunc_t newindex_miss_property, const struct luaL_reg methods[], const struct luaL_reg meta[]) { @@ -177,6 +179,8 @@ luaA_class_setup(lua_State *L, lua_class_t *class, class->allocator = allocator; class->name = name; + class->index_miss_property = index_miss_property; + class->newindex_miss_property = newindex_miss_property; lua_class_array_append(&luaA_classes, class); } @@ -275,8 +279,16 @@ luaA_class_index(lua_State *L) lua_class_property_t *prop = luaA_class_property_get(L, class, 2); /* Property does exist and has an index callback */ - if(prop && prop->index) - return prop->index(L, luaA_checkudata(L, 1, class)); + if(prop) + { + if(prop->index) + return prop->index(L, luaA_checkudata(L, 1, class)); + } + else + { + if(class->index_miss_property) + return class->index_miss_property(L, luaA_checkudata(L, 1, class)); + } return 0; } @@ -297,8 +309,16 @@ luaA_class_newindex(lua_State *L) lua_class_property_t *prop = luaA_class_property_get(L, class, 2); /* Property does exist and has a newindex callback */ - if(prop && prop->newindex) - return prop->newindex(L, luaA_checkudata(L, 1, class)); + if(prop) + { + if(prop->newindex) + return prop->newindex(L, luaA_checkudata(L, 1, class)); + } + else + { + if(class->newindex_miss_property) + return class->newindex_miss_property(L, luaA_checkudata(L, 1, class)); + } return 0; } diff --git a/common/luaclass.h b/common/luaclass.h index 0d17fabaf..f41ec9a19 100644 --- a/common/luaclass.h +++ b/common/luaclass.h @@ -42,19 +42,24 @@ typedef struct typedef lua_object_t *(*lua_class_allocator_t)(lua_State *); +typedef int (*lua_class_propfunc_t)(lua_State *, lua_object_t *); + typedef struct { /** Class name */ const char *name; + /** Class signals */ signal_array_t signals; /** Allocator for creating new objects of that class */ lua_class_allocator_t allocator; /** Class properties */ lua_class_property_array_t properties; + /** Function to call when a indexing an unknown property */ + lua_class_propfunc_t index_miss_property; + /** Function to call when a indexing an unknown property */ + lua_class_propfunc_t newindex_miss_property; } lua_class_t; -typedef int (*lua_class_propfunc_t)(lua_State *, lua_object_t *); - const char * luaA_typename(lua_State *, int); lua_class_t * luaA_class_get(lua_State *, int); @@ -64,6 +69,7 @@ void luaA_class_emit_signal(lua_State *, lua_class_t *, const char *, int); void luaA_openlib(lua_State *, const char *, const struct luaL_reg[], const struct luaL_reg[]); void luaA_class_setup(lua_State *, lua_class_t *, const char *, lua_class_allocator_t, + lua_class_propfunc_t, lua_class_propfunc_t, const struct luaL_reg[], const struct luaL_reg[]); void luaA_class_add_property(lua_class_t *, awesome_token_t, diff --git a/image.c b/image.c index 3b0edf5d5..a31709ca4 100644 --- a/image.c +++ b/image.c @@ -800,6 +800,7 @@ image_class_setup(lua_State *L) }; luaA_class_setup(L, &image_class, "image", (lua_class_allocator_t) image_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, image_methods, image_meta); luaA_class_add_property(&image_class, A_TK_WIDTH, NULL, diff --git a/key.c b/key.c index 77f89b5c7..57724b9e9 100644 --- a/key.c +++ b/key.c @@ -1199,6 +1199,7 @@ key_class_setup(lua_State *L) }; luaA_class_setup(L, &key_class, "key", (lua_class_allocator_t) key_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, key_methods, key_meta); luaA_class_add_property(&key_class, A_TK_KEY, (lua_class_propfunc_t) luaA_key_set_key, diff --git a/luaa.c b/luaa.c index b96ff7a4b..b0232746d 100644 --- a/luaa.c +++ b/luaa.c @@ -869,4 +869,18 @@ luaA_on_timer(EV_P_ ev_timer *w, int revents) luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.timer, 0, 0); } +int +luaA_class_index_miss_property(lua_State *L, lua_object_t *obj) +{ + signal_object_emit(L, &global_signals, "debug::index::miss", 2); + return 0; +} + +int +luaA_class_newindex_miss_property(lua_State *L, lua_object_t *obj) +{ + signal_object_emit(L, &global_signals, "debug::newindex::miss", 3); + return 0; +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/luaa.h b/luaa.h index 62389dbab..bc0a04c59 100644 --- a/luaa.h +++ b/luaa.h @@ -243,5 +243,8 @@ bool luaA_isloop(lua_State *, int); /** Global signals */ signal_array_t global_signals; +int luaA_class_index_miss_property(lua_State *, lua_object_t *); +int luaA_class_newindex_miss_property(lua_State *, lua_object_t *); + #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/tag.c b/tag.c index afa2bca6e..c86bbdb51 100644 --- a/tag.c +++ b/tag.c @@ -470,6 +470,7 @@ tag_class_setup(lua_State *L) }; luaA_class_setup(L, &tag_class, "tag", (lua_class_allocator_t) tag_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, tag_methods, tag_meta); luaA_class_add_property(&tag_class, A_TK_NAME, (lua_class_propfunc_t) luaA_tag_set_name, diff --git a/timer.c b/timer.c index 6f8f7f609..cc448dc00 100644 --- a/timer.c +++ b/timer.c @@ -123,6 +123,7 @@ timer_class_setup(lua_State *L) }; luaA_class_setup(L, &timer_class, "timer", (lua_class_allocator_t) timer_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, timer_methods, timer_meta); luaA_class_add_property(&timer_class, A_TK_TIMEOUT, (lua_class_propfunc_t) luaA_timer_set_timeout, diff --git a/wibox.c b/wibox.c index b2f0f6d53..4c5f14af6 100644 --- a/wibox.c +++ b/wibox.c @@ -1505,6 +1505,7 @@ wibox_class_setup(lua_State *L) }; luaA_class_setup(L, &wibox_class, "wibox", (lua_class_allocator_t) wibox_new, + luaA_class_index_miss_property, luaA_class_newindex_miss_property, wibox_methods, wibox_meta); luaA_class_add_property(&wibox_class, A_TK_WIDGETS, (lua_class_propfunc_t) luaA_wibox_set_widgets, diff --git a/widget.c b/widget.c index 144658aa2..7c6ebb73a 100644 --- a/widget.c +++ b/widget.c @@ -577,6 +577,7 @@ widget_class_setup(lua_State *L) }; luaA_class_setup(L, &widget_class, "widget", (lua_class_allocator_t) widget_new, + NULL, NULL, widget_methods, widget_meta); luaA_class_add_property(&widget_class, A_TK_VISIBLE, (lua_class_propfunc_t) luaA_widget_set_visible,