Module gtk_internal.channel

Functions

local _get_channel (L, index) Check that the given Lua value is a object for a GIOChannel.
local _get_int_or_enum (L, index) A numeric argument might be given as an ENUM.
local _handle_channel_status (L, status, error, bytes_transferred) Build a response for the Lua caller about the result of a Channel IO operation.
local _watch_destroy_notify (data) Clean up the data of a watch.
local _watch_handler (gio, cond, data) This is the handler for channel related events.
local g_io_add_watch (GIOChannel, conditions, callback, thread) Add a new watch on a GIOChannel to the main loop.
local g_io_channel_flush (channel) Flush the IO Channel.
local g_io_channel_read_chars (channel, maxbytes) Read data from the channel up to a given maximum length.
local g_io_channel_read_line (channel) Read the next line from the channel.
local g_io_channel_write_chars (channel, buf) Write a buffer to the given IO Channel.


Functions

local _get_channel (L, index)
Check that the given Lua value is a object for a GIOChannel.

Parameters

  • L:
  • index:

Return value:

the object; raises a Lua error otherwise. In file: src/glib/channel.c line 29
local _get_int_or_enum (L, index)
A numeric argument might be given as an ENUM. If this is so, extract the value.

Parameters

  • L:
  • index:
In file: src/glib/channel.c line 47
local _handle_channel_status (L, status, error, bytes_transferred)
Build a response for the Lua caller about the result of a Channel IO operation. Should the OK response not be a simple boolean, handle this instead of calling this function.

Parameters

  • L: lua_State
  • status: I/O status of the operation
  • error: Pointer to a GError structure with further information
  • bytes_transferred: Bytes transferred (and discarded) so far

Return value:

3 items on the Lua stack. In file: src/glib/channel.c line 190
local _watch_destroy_notify (data)
Clean up the data of a watch. Some callback information is stored in the registry of the given Lua state; remove it, then free the struct _watch_info.

Parameters

  • data: A struct _watch_info.
In file: src/glib/channel.c line 167
local _watch_handler (gio, cond, data)
This is the handler for channel related events. Call the appropriates Lua callback with the prototype of GIOFunc, it is passed the following arguments: [1] GIOChannel [2] The condition that led to the activation of the callback [3] The data that was passed to g_io_add_watch It is expected to return a boolean (true=keep listening for this event) Note: this runs within the initial Lua state. Maybe a new state would be better, i.e. in l_gtk_init luaL_newstate(). This might lead to other problems, like variables not visible from within the handler. So, all I can do now is take care that the stack of the global Lua state isn't modified - well now this would lead to strange bugs...

Parameters

  • gio: The I/O channel that was signaled
  • cond: Condition that caused the callback
  • data: a struct _watch_info

Return value:

true if to continue watching for this event, false otherwise. In file: src/glib/channel.c line 82
local g_io_add_watch (GIOChannel, conditions, callback, thread)
Add a new watch on a GIOChannel to the main loop. The callback function will be called in the context of the main thread. Information is stored in the main thread's environment (i.e. the environment of the module gtk). The callback can't be run in the thread context of the caller, because this thread might terminate, leaving L pointing nowhere. Also, it can't be run in the thread that will handle the callback (a thread can't resume itself).

Parameters

  • GIOChannel: (object)
  • conditions: (integer, or ENUM)
  • callback: (Lua function)
  • thread: the callback runs in

Return values:

  1. ID of the new watch; this can be used to remove it, see g_source_remove().
In file: src/glib/channel.c line 236
local g_io_channel_flush (channel)
Flush the IO Channel.

Parameters

  • channel:
In file: src/glib/channel.c line 381
local g_io_channel_read_chars (channel, maxbytes)
Read data from the channel up to a given maximum length.

Parameters

  • channel:
  • maxbytes:

Return values:

  1. The string read, or nil on error
  2. on error, a message
  3. on error, number of bytes read (and discarded)
In file: src/glib/channel.c line 288
local g_io_channel_read_line (channel)
Read the next line from the channel. Newlines at the end are chopped off automatically. The channel has to be buffered in order for this to work.

Parameters

  • channel:

Return values:

  1. string, or nil, error message, bytes transferred
In file: src/glib/channel.c line 319
local g_io_channel_write_chars (channel, buf)
Write a buffer to the given IO Channel.

Parameters

  • channel:
  • buf: The string to write

Return values:

  1. true on success, else nil
  2. on error, a message
In file: src/glib/channel.c line 352

Valid XHTML 1.0!