luaclass: add handling of {new,}index of missing properties (FS#584)
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a9880a6c89
commit
4d0a025f51
1
button.c
1
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_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);
|
button_methods, button_meta);
|
||||||
luaA_class_add_property(&button_class, A_TK_BUTTON,
|
luaA_class_add_property(&button_class, A_TK_BUTTON,
|
||||||
(lua_class_propfunc_t) luaA_button_set_button,
|
(lua_class_propfunc_t) luaA_button_set_button,
|
||||||
|
|
1
client.c
1
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_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);
|
client_methods, client_meta);
|
||||||
luaA_class_add_property(&client_class, A_TK_NAME,
|
luaA_class_add_property(&client_class, A_TK_NAME,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
@ -155,6 +155,8 @@ void
|
||||||
luaA_class_setup(lua_State *L, lua_class_t *class,
|
luaA_class_setup(lua_State *L, lua_class_t *class,
|
||||||
const char *name,
|
const char *name,
|
||||||
lua_class_allocator_t allocator,
|
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 methods[],
|
||||||
const struct luaL_reg meta[])
|
const struct luaL_reg meta[])
|
||||||
{
|
{
|
||||||
|
@ -177,6 +179,8 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
|
||||||
|
|
||||||
class->allocator = allocator;
|
class->allocator = allocator;
|
||||||
class->name = name;
|
class->name = name;
|
||||||
|
class->index_miss_property = index_miss_property;
|
||||||
|
class->newindex_miss_property = newindex_miss_property;
|
||||||
|
|
||||||
lua_class_array_append(&luaA_classes, class);
|
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);
|
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 */
|
||||||
if(prop && prop->index)
|
if(prop)
|
||||||
return prop->index(L, luaA_checkudata(L, 1, class));
|
{
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -297,8 +309,16 @@ luaA_class_newindex(lua_State *L)
|
||||||
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 a newindex callback */
|
/* Property does exist and has a newindex callback */
|
||||||
if(prop && prop->newindex)
|
if(prop)
|
||||||
return prop->newindex(L, luaA_checkudata(L, 1, class));
|
{
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,19 +42,24 @@ typedef struct
|
||||||
|
|
||||||
typedef lua_object_t *(*lua_class_allocator_t)(lua_State *);
|
typedef lua_object_t *(*lua_class_allocator_t)(lua_State *);
|
||||||
|
|
||||||
|
typedef int (*lua_class_propfunc_t)(lua_State *, lua_object_t *);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/** Class name */
|
/** Class name */
|
||||||
const char *name;
|
const char *name;
|
||||||
|
/** Class signals */
|
||||||
signal_array_t signals;
|
signal_array_t signals;
|
||||||
/** Allocator for creating new objects of that class */
|
/** Allocator for creating new objects of that class */
|
||||||
lua_class_allocator_t allocator;
|
lua_class_allocator_t allocator;
|
||||||
/** Class properties */
|
/** Class properties */
|
||||||
lua_class_property_array_t 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;
|
} lua_class_t;
|
||||||
|
|
||||||
typedef int (*lua_class_propfunc_t)(lua_State *, lua_object_t *);
|
|
||||||
|
|
||||||
const char * luaA_typename(lua_State *, int);
|
const char * luaA_typename(lua_State *, int);
|
||||||
lua_class_t * luaA_class_get(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_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,
|
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[]);
|
const struct luaL_reg[], const struct luaL_reg[]);
|
||||||
|
|
||||||
void luaA_class_add_property(lua_class_t *, awesome_token_t,
|
void luaA_class_add_property(lua_class_t *, awesome_token_t,
|
||||||
|
|
1
image.c
1
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_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);
|
image_methods, image_meta);
|
||||||
luaA_class_add_property(&image_class, A_TK_WIDTH,
|
luaA_class_add_property(&image_class, A_TK_WIDTH,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
1
key.c
1
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_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);
|
key_methods, key_meta);
|
||||||
luaA_class_add_property(&key_class, A_TK_KEY,
|
luaA_class_add_property(&key_class, A_TK_KEY,
|
||||||
(lua_class_propfunc_t) luaA_key_set_key,
|
(lua_class_propfunc_t) luaA_key_set_key,
|
||||||
|
|
14
luaa.c
14
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);
|
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
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
3
luaa.h
3
luaa.h
|
@ -243,5 +243,8 @@ bool luaA_isloop(lua_State *, int);
|
||||||
/** Global signals */
|
/** Global signals */
|
||||||
signal_array_t 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
|
#endif
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
1
tag.c
1
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_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);
|
tag_methods, tag_meta);
|
||||||
luaA_class_add_property(&tag_class, A_TK_NAME,
|
luaA_class_add_property(&tag_class, A_TK_NAME,
|
||||||
(lua_class_propfunc_t) luaA_tag_set_name,
|
(lua_class_propfunc_t) luaA_tag_set_name,
|
||||||
|
|
1
timer.c
1
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_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);
|
timer_methods, timer_meta);
|
||||||
luaA_class_add_property(&timer_class, A_TK_TIMEOUT,
|
luaA_class_add_property(&timer_class, A_TK_TIMEOUT,
|
||||||
(lua_class_propfunc_t) luaA_timer_set_timeout,
|
(lua_class_propfunc_t) luaA_timer_set_timeout,
|
||||||
|
|
1
wibox.c
1
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_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);
|
wibox_methods, wibox_meta);
|
||||||
luaA_class_add_property(&wibox_class, A_TK_WIDGETS,
|
luaA_class_add_property(&wibox_class, A_TK_WIDGETS,
|
||||||
(lua_class_propfunc_t) luaA_wibox_set_widgets,
|
(lua_class_propfunc_t) luaA_wibox_set_widgets,
|
||||||
|
|
1
widget.c
1
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,
|
luaA_class_setup(L, &widget_class, "widget", (lua_class_allocator_t) widget_new,
|
||||||
|
NULL, NULL,
|
||||||
widget_methods, widget_meta);
|
widget_methods, widget_meta);
|
||||||
luaA_class_add_property(&widget_class, A_TK_VISIBLE,
|
luaA_class_add_property(&widget_class, A_TK_VISIBLE,
|
||||||
(lua_class_propfunc_t) luaA_widget_set_visible,
|
(lua_class_propfunc_t) luaA_widget_set_visible,
|
||||||
|
|
Loading…
Reference in New Issue