m-lua-scripting/api: allow EventDispatcher.push_event() to accept event objects

This commit is contained in:
George Kiagiadakis
2022-12-23 21:11:58 +02:00
committed by Julian Bouzas
parent d46d54f261
commit 73b6b90a35

View File

@@ -1837,9 +1837,9 @@ event_dispatcher_push_event (lua_State *L)
WpProperties *properties = NULL;
GObject *source = NULL;
GObject *subject = NULL;
WpEvent *event = NULL;
luaL_checktype (L, 1, LUA_TTABLE);
if (lua_type (L, 1) == LUA_TTABLE) {
lua_pushliteral (L, "type");
if (lua_gettable (L, 1) != LUA_TSTRING)
luaL_error (L, "EventDispatcher.push_event: expected 'type' as string");
@@ -1869,9 +1869,13 @@ event_dispatcher_push_event (lua_State *L)
subject = wplua_checkobject (L, -1, G_TYPE_OBJECT);
lua_pop (L, 1);
event = wp_event_new (type, priority, properties, source, subject);
} else {
event = wp_event_ref (wplua_checkboxed (L, 1, WP_TYPE_EVENT));
}
g_autoptr (WpEventDispatcher) dispatcher =
wp_event_dispatcher_get_instance (get_wp_core (L));
WpEvent *event = wp_event_new (type, priority, properties, source, subject);
wp_event_dispatcher_push_event (dispatcher, wp_event_ref (event));
wplua_pushboxed (L, WP_TYPE_EVENT, event);
return 1;