Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Calls the callback function for the GIO channel
- * Returns FALSE if the event should be removed
- *
- * \see luaH_luakit_idle_add_socket
- *
- * \param source The channel that triggered the event
- * \param condition The condition that triggered the event
- * \param func Lua callback function
- */
- static gboolean
- idle_socket_cb(GIOChannel *source, GIOCondition condition, gpointer func)
- {
- lua_State *L = globalconf.L;
- gint top = lua_gettop(L);
- gboolean keep = FALSE;
- /* setup stack for call, first the function to call*/
- luaH_object_push(L, func);
- /* now come the arguments*/
- int fd = g_io_channel_unix_get_fd(source);
- lua_pushnumber(L, fd);
- lua_pushnumber(L, condition);
- /*make the jump to light speed...*/
- if (lua_pcall(L, 2, 1, 0))
- warn("error in socket callback: %s", lua_tostring(L, -1));
- else
- keep = lua_toboolean(L, -1);
- if (!keep)
- luaH_object_unref(L, func);
- lua_settop(L, top);
- return keep;
- }
- /** Adds the GIOChannel into the default main loop context with the default
- * priority.
- *
- * \param L The lua VM state.
- * \return The number of elements pushed on stack
- *
- * \luastack
- * \lparam fd The file descriptor to create a watch for
- * \lparam condition The conditions for the watch to trigger an event
- * \lparam func The callback function
- */
- static gint
- luaH_luakit_idle_add_socket(lua_State *L)
- {
- int fd = luaL_checkint(L, 1);
- GIOCondition condition = luaL_checkint(L, 2);
- luaH_checkfunction(L, 3);
- gpointer func = luaH_object_ref(L, 3);
- GIOChannel *channel = g_io_channel_unix_new(fd);
- g_io_add_watch(channel, condition, idle_socket_cb, func);
- return 0;
- }
Add Comment
Please, Sign In to add comment