Ejemplo n.º 1
0
Archivo: luah.c Proyecto: pawelz/luakit
/* Add a global signal.
 * Returns the number of elements pushed on stack.
 * \luastack
 * \lparam A string with the event name.
 * \lparam The function to call.
 */
static gint
luaH_luakit_add_signal(lua_State *L)
{
    const gchar *name = luaL_checkstring(L, 1);
    luaH_checkfunction(L, 2);
    signal_add(globalconf.signals, name, luaH_object_ref(L, 2));
    return 0;
}
Ejemplo n.º 2
0
static int
luaH_timer_start(lua_State *L)
{
    ltimer_t *timer = luaH_checktimer(L, 1);
    if (!timer->interval)
        luaL_error(L, "interval not set");

    if (timer->id == TIMER_STOPPED) {
        /* ensure timer isn't collected while running */
        timer->ref = luaH_object_ref(L, 1);
        timer->id = g_timeout_add(timer->interval, timer_handle_timeout, timer);
    } else
        luaH_warn(L, "timer already started");
    return 0;
}
Ejemplo n.º 3
0
static int
luaH_timer_start(lua_State *L)
{
    ltimer_t *timer = luaH_checkudata(L, 1, &timer_class);
    // get interval
    lua_getfield(L, -1, TIMER_INTERVAL_FIELD);
    int millis = luaL_checkinteger(L, -1);
    timer->ref = luaH_object_ref(L, 1); // ensure that timers don't get collected while running
    if (timer->timer_id == TIMER_STOPPED) {
        timer->timer_id = g_timeout_add(millis, timer_handle_timeout, timer);
    } else {
        luaH_warn(L, "timer already started. Cannot start a timer twice");
    }
    return 0;
}
Ejemplo n.º 4
0
static gint
luaH_webview_register_function(lua_State *L)
{
    WebKitWebFrame *frame = NULL;
    widget_t *w = luaH_checkwidget(L, 1);
    WebKitWebView *view = WEBKIT_WEB_VIEW(g_object_get_data(G_OBJECT(w->widget), "webview"));
    const gchar *name = luaL_checkstring(L, 2);
    lua_pushvalue(L, 3);
    gpointer ref = luaH_object_ref(L, -1);

    /* Check if function should be registered on currently focused frame */
    if (lua_gettop(L) >= 4 && luaH_checkboolean(L, 4))
        frame = webkit_web_view_get_focused_frame(view);
    /* Fall back on main frame */
    if (!frame)
        frame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(view));

    /* register function */
    webview_register_function(frame, name, ref);
    return 0;
}
Ejemplo n.º 5
0
/**
 * Starts the download.
 *
 * Will produce a warning if the download is already running.
 * References the download to prevent its garbage collection.
 * Will raise a Lua error if the start failed.
 *
 * \param L The Lua VM state.
 *
 * \luastack
 * \lparam A \c download object to start.
 */
static gint
luaH_download_start(lua_State *L)
{
    download_t *download = luaH_checkdownload(L, 1);
    if (!download_is_started(download)) {
        /* prevent lua garbage collection while downloading */
        lua_pushvalue(L, 1);
        download->ref = luaH_object_ref(L, -1);

        /* check if we can download to destination */
        if (download_check_prerequesites(L, download))
            webkit_download_start(download->webkit_download);

        /* check for webkit/glib errors from download start */
        if (download->error) {
            lua_pushstring(L, download->error);
            lua_error(L);
        }

    } else
        luaH_warn(L, "download already stared");
    return 0;
}