luaa: split dofunction()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-05-19 17:37:35 +02:00
parent 90bc90fde4
commit e4acb74a5a
8 changed files with 44 additions and 32 deletions

View file

@ -64,7 +64,7 @@ awesome_atexit(void)
int screen_nbr, nscreens;
if(globalconf.hooks.exit != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.exit, 0, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.exit, 0, 0);
a_dbus_cleanup();

View file

@ -177,7 +177,7 @@ client_unfocus_update(client_t *c)
if(globalconf.hooks.unfocus != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.unfocus, 1, 0);
}
}
@ -259,7 +259,7 @@ client_focus_update(client_t *c)
if(globalconf.hooks.focus != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.focus, 1, 0);
}
}
@ -546,14 +546,14 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
/* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.clients, 0, 0);
/* call hook */
if(globalconf.hooks.manage != LUA_REFNIL)
{
client_push(globalconf.L, c);
lua_pushboolean(globalconf.L, startup);
luaA_dofunction(globalconf.L, globalconf.hooks.manage, 2, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.manage, 2, 0);
}
}
@ -1019,12 +1019,12 @@ client_unmanage(client_t *c)
if(globalconf.hooks.unmanage != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.unmanage, 1, 0);
}
/* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.clients, 0, 0);
/* The server grab construct avoids race conditions. */
xcb_grab_server(globalconf.connection);
@ -1204,7 +1204,7 @@ luaA_client_swap(lua_State *L)
/* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
luaA_dofunction_from_registry(L, globalconf.hooks.clients, 0, 0);
}
return 0;

4
dbus.c
View file

@ -300,11 +300,11 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
nargs += a_dbus_message_iter(&iter);
if(dbus_message_get_no_reply(msg))
luaA_dofunction(globalconf.L, globalconf.hooks.dbus, nargs, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.dbus, nargs, 0);
else
{
int n = lua_gettop(globalconf.L) - nargs;
luaA_dofunction(globalconf.L, globalconf.hooks.dbus, nargs, LUA_MULTRET);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.dbus, nargs, LUA_MULTRET);
n -= lua_gettop(globalconf.L);
DBusMessage *reply = dbus_message_new_method_return(msg);

18
event.c
View file

@ -58,7 +58,7 @@
{ \
for(int i = 0; i < nargs; i++) \
lua_pushvalue(globalconf.L, - nargs); \
luaA_dofunction(globalconf.L, (*item)->press, nargs, 0); \
luaA_dofunction_from_registry(globalconf.L, (*item)->press, nargs, 0); \
} \
break; \
case xcbeventprefix##_RELEASE: \
@ -66,7 +66,7 @@
{ \
for(int i = 0; i < nargs; i++) \
lua_pushvalue(globalconf.L, - nargs); \
luaA_dofunction(globalconf.L, (*item)->release, nargs, 0); \
luaA_dofunction_from_registry(globalconf.L, (*item)->release, nargs, 0); \
} \
break; \
} \
@ -347,7 +347,7 @@ event_handle_widget_motionnotify(void *object,
{
/* call mouse leave function on old widget */
widget_push(globalconf.L, *mouse_over);
luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
luaA_dofunction_from_registry(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
}
}
if(widget)
@ -357,7 +357,7 @@ event_handle_widget_motionnotify(void *object,
if(widget->mouse_enter != LUA_REFNIL)
{
widget_push(globalconf.L, widget);
luaA_dofunction(globalconf.L, widget->mouse_enter, 1, 0);
luaA_dofunction_from_registry(globalconf.L, widget->mouse_enter, 1, 0);
}
}
}
@ -411,7 +411,7 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
if(globalconf.hooks.mouse_leave != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.mouse_leave, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.mouse_leave, 1, 0);
}
if((wibox = wibox_getbywin(ev->event)))
@ -422,13 +422,13 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
{
/* call mouse leave function on widget the mouse was over */
wibox_push(globalconf.L, wibox);
luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
luaA_dofunction_from_registry(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
}
wibox->mouse_over = NULL;
}
if(wibox->mouse_leave != LUA_REFNIL)
luaA_dofunction(globalconf.L, wibox->mouse_leave, 0, 0);
luaA_dofunction_from_registry(globalconf.L, wibox->mouse_leave, 0, 0);
}
return 0;
@ -460,7 +460,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
if(wibox->mouse_enter != LUA_REFNIL)
luaA_dofunction(globalconf.L, wibox->mouse_enter, 0, 0);
luaA_dofunction_from_registry(globalconf.L, wibox->mouse_enter, 0, 0);
}
if((c = client_getbytitlebarwin(ev->event))
@ -468,7 +468,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
if(globalconf.hooks.mouse_enter != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
}
return 0;

2
luaa.c
View file

@ -861,7 +861,7 @@ void
luaA_on_timer(EV_P_ ev_timer *w, int revents)
{
if(globalconf.hooks.timer != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.timer, 0, 0);
awesome_refresh();
}

22
luaa.h
View file

@ -238,17 +238,15 @@ luaA_registerfct(lua_State *L, int idx, luaA_ref *fct)
return luaA_register(L, idx, fct);
}
/** Execute an Lua function.
/** Execute an Lua function on top of the stack.
* \param L The Lua stack.
* \param f The Lua function to execute.
* \param nargs The number of arguments for the Lua function.
* \param nret The number of returned value from the Lua function.
* \return True on no error, false otherwise.
*/
static inline bool
luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret)
luaA_dofunction(lua_State *L, int nargs, int nret)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, f);
if(nargs)
lua_insert(L, - (nargs + 1));
if(lua_pcall(L, nargs, nret, 0))
@ -261,6 +259,20 @@ luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret)
return true;
}
/** Grab a function from the registry and execute it.
* \param L The Lua stack.
* \param ref The function reference.
* \param nargs The number of arguments for the Lua function.
* \param nret The number of returned value from the Lua function.
* \return True on no error, false otherwise.
*/
static inline bool
luaA_dofunction_from_registry(lua_State *L, luaA_ref ref, int nargs, int nret)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
return luaA_dofunction(L, nargs, nret);
}
/** Print a warning about some Lua code.
* This is less mean than luaL_error() which setjmp via lua_error() and kills
* everything. This only warn, it's up to you to then do what's should be done.
@ -337,7 +349,7 @@ bool luaA_isloop(lua_State *, int);
{ \
type##_push(globalconf.L, obj); \
lua_pushliteral(globalconf.L, prop); \
luaA_dofunction(globalconf.L, globalconf.hooks.property, 2, 0); \
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.property, 2, 0); \
} \
} while(0);

View file

@ -77,7 +77,7 @@ spawn_monitor_timeout(struct ev_loop *loop, ev_timer *w, int revents)
lua_setfield(globalconf.L, -2, "id");
lua_pushliteral(globalconf.L, "timedout");
lua_setfield(globalconf.L, -2, "type");
luaA_dofunction(globalconf.L, globalconf.hooks.startup_notification, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.startup_notification, 1, 0);
}
sn_startup_sequence_unref(w->data);
p_delete(&w);
@ -175,7 +175,7 @@ spawn_monitor_event(SnMonitorEvent *event, void *data)
break;
}
luaA_dofunction(globalconf.L, globalconf.hooks.startup_notification, 1, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.startup_notification, 1, 0);
}
/** Tell the spawn module that an app has been started.

10
tag.c
View file

@ -70,7 +70,7 @@ tag_view(tag_t *tag, bool view)
lua_pushliteral(globalconf.L, "select");
else
lua_pushliteral(globalconf.L, "unselect");
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 3, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.tags, 3, 0);
}
}
}
@ -102,7 +102,7 @@ tag_append_to_screen(screen_t *s)
lua_pushnumber(globalconf.L, screen_index + 1);
tag_push(globalconf.L, tag);
lua_pushliteral(globalconf.L, "add");
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 3, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.tags, 3, 0);
}
}
@ -132,7 +132,7 @@ tag_remove_from_screen(tag_t *tag)
lua_pushnumber(globalconf.L, screen_index + 1);
tag_push(globalconf.L, tag);
lua_pushliteral(globalconf.L, "remove");
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 3, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.tags, 3, 0);
}
tag->screen = NULL;
@ -161,7 +161,7 @@ tag_client(client_t *c)
{
client_push(globalconf.L, c);
tag_push(globalconf.L, t);
luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.tagged, 2, 0);
}
}
@ -184,7 +184,7 @@ untag_client(client_t *c, tag_t *t)
{
client_push(globalconf.L, c);
tag_push(globalconf.L, t);
luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0);
luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.tagged, 2, 0);
}
tag_unref(globalconf.L, t);
return;