Separation of glib
authorMyhailo Danylenko <isbear@ukrpost.net>
Mon, 09 Feb 2009 13:39:36 +0200
changeset 3 4fd19a188509
parent 2 34b6fedde9eb
child 4 5770be2d5f3f
Separation of glib
CMakeLists.txt
glib.c
glib_io.c
glib_main_context.c
glib_main_context.h
glib_source.c
glib_source.h
glib_timeout.c
glib_timeout.h
glib_types.c
glib_types.h
--- a/CMakeLists.txt	Mon Feb 09 13:00:42 2009 +0200
+++ b/CMakeLists.txt	Mon Feb 09 13:39:36 2009 +0200
@@ -3,11 +3,8 @@
 
 # Define targets
 add_library(loudmouth MODULE util.c lm_types.c lm_proxy.c lm_ssl.c lm_connection.c lm_message.c lm_message_node.c lm_message_handler.c lm.c)
-add_library(glib MODULE glib.c glib_types.c glib_main_context.c glib_source.c glib_timeout.c util.c)
 
 # Check for dependencies
-find_package(ZLIB REQUIRED)
-
 find_package(Lua51 REQUIRED)
 
 find_package(PkgConfig REQUIRED)
@@ -17,6 +14,5 @@
 # Set building options
 include_directories(SYSTEM ${LUA_INCLUDE_DIR} ${GLIB_INCLUDE_DIRS} ${LM_INCLUDE_DIRS})
 target_link_libraries(loudmouth ${LUA_LIBRARIES} ${GLIB_LIBRARIES} ${LM_LIBRARIES})
-target_link_libraries(glib ${LUA_LIBRARIES} ${GLIB_LIBRARIES})
-set_target_properties(loudmouth glib PROPERTIES PREFIX "")
+set_target_properties(loudmouth PROPERTIES PREFIX "")
 
--- a/glib.c	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-
-#include <lua.h>
-
-#include "glib_types.h"
-#include "glib_main_context.h"
-#include "glib_timeout.h"
-#include "glib_source.h"
-
-int luaopen_glib (lua_State *L)
-{
-	lua_pushstring (L, LGLIB_OBJREGISTRY);
-	lua_newtable (L);
-	lua_createtable (L, 0, 1);
-	lua_pushstring (L, "__mode");
-	lua_pushstring (L, "v");
-	lua_settable (L, -3);
-	lua_setmetatable (L, -2);
-	lua_rawset (L, LUA_REGISTRYINDEX);
-
-	lua_createtable (L, 3, 0);
-	lua_pushvalue (L, -1);
-	lua_setglobal (L, "g");
-
-	luaopen_glib_main_context (L);
-	luaopen_glib_source (L);
-	luaopen_glib_timeout (L);
-	lua_pop (L, 3);
-
-	return 1;
-}
-
--- a/glib_io.c	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <glib.h>
-#include <stdio.h>    // popen, pclose, fileno
-
-#include "util.h"
-#include "glib_types.h"
-
-static gchar lglib_io_buffer[128];
-
-void lglib_io_callback_destroy (lglib_io_callback_t *cb)
-{
-	luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	pclose (cb->fd);
-	luaL_free (cb->L, cb);
-}
-
-// data/nil
-static gboolean lglib_io_callback (GIOChannel *source, GIOCondition *condition, lglib_io_callback_t *cb)
-{
-	gsize read = 0;
-	int status;
-	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	status = g_io_channel_read_chars (source, lglib_io_buffer, 128, &read, NULL);
-	if (read) {
-		lua_pushlstring (cb->L, lglib_io_buffer, read);
-	} else if (status == G_IO_STATUS_EOF) {
-		lua_pushnil (cb->L);
-	} else {
-		return status != G_IO_STATUS_ERROR;
-	}
-	if (lua_pcall (cb->L, 1, 1, 0))
-		lua_error (cb->L);
-	return lua_toboolean (cb->L, -1);
-}
-
-// command function
-static int lglib_io_new (lua_State *L)
-{
-	const char *command = luaL_checkstring (L, 1);
-	lglib_io_callback_t *cb;
-	FILE *fd;
-	GIOChannel *channel;
-	//const char *charset;
-	luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
-
-	fd = popen (command, "r");
-	if (!fd) {
-		lua_pushstring (L, "Error opening pipe");
-		lua_error (L);
-	}
-	channel = g_io_channel_unix_new (fileno (fd));
-	//if (!g_get_charset (&charset))
-	//	g_io_channel_set_encoding (channel, charset, NULL);
-
-	cb = luaL_malloc (L, sizeof (lglib_io_callback_t));
-	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
-	cb->L         = L;
-	cb->fd        = fd;
-
-	g_io_add_watch_full (channel, G_PRIORITY_HIGH_IDLE, G_IO_IN,
-				(GSourceFunc)lglib_io_callback, cb,
-				(GDestroyNotify)lglib_io_callback_destroy);
-	return 0;
-}
-
-static const luaL_Reg lglib_io_reg_f[] = {
-	{ "new", lglib_io_new },
-	{ NULL,  NULL         },
-};
-
-int luaopen_glib_io (lua_State *L)
-{
-	luaL_register (L, "g.io", lglib_io_reg_f);
-	return 1;
-}
-
--- a/glib_main_context.c	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,248 +0,0 @@
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <glib.h>
-
-#include "glib_types.h"
-
-/// g.main_context
-/// Glib main context object. Mainly useful when lua needs to
-/// manage glib-based libs.
-
-/// g.main_context.new
-/// Creates new main context object.
-/// R: g main context object
-static int lglib_main_context_new (lua_State *L)
-{
-	GMainContext *context = g_main_context_new ();
-	lglib_main_context_bless (L, context);
-	g_main_context_unref (context);
-	return 1;
-}
-
-/// g.main_context.bless
-/// Blesses given pointer to g main context object.
-/// A: lightuserdata (C g main context object)
-/// R: g main context object
-static int lglib_main_context_bless_lua (lua_State *L)
-{
-	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "g main context lightuserdata expected");
-	lglib_main_context_bless (L, lua_touserdata (L, 1));
-	return 1;
-}
-
-/// g.main_context.default
-/// Returns default main context object.
-/// R: g main context object
-static int lglib_main_context_default (lua_State *L)
-{
-	GMainContext *context = g_main_context_default ();
-	lglib_main_context_bless (L, context);
-	// XXX g_main_context_unref (context);
-	return 1;
-}
-
-/// main_context:iteration
-/// Performs single full iteration in blocking or non-blocking manner,
-/// depending on value of argument.
-/// Returns true, if some events have been handled.
-/// A: boolean (optional)
-/// R: boolean
-static int lglib_main_context_iteration (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	int may_block = 0;
-	if ( lua_gettop (L) > 1 ) {
-		luaL_checktype (L, 2, LUA_TBOOLEAN);
-		may_block = lua_toboolean (L, 2);
-	}
-	lua_pushboolean (L, g_main_context_iteration (object->main_context, may_block));
-	return 1;
-}
-
-/// main_context:pending
-/// Indicates, if there are present events in sources.
-/// R: boolean
-static int lglib_main_context_pending (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	lua_pushboolean (L, g_main_context_pending (object->main_context));
-	return 1;
-}
-
-/// main_context:find_source
-/// Returns source with given id.
-/// A: integer (source id)
-/// R: g main context object or nil
-static int lglib_main_context_find_source (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	int id = luaL_checkint (L, 2);
-	GSource *source = g_main_context_find_source_by_id (object->main_context, id);
-	if (source) {
-		lglib_source_bless (L, source);
-		// XXX g_source_unref (source)
-	} else
-		lua_pushnil (L);
-	return 1;
-}
-
-/// main_context:wakeup
-/// Awakes main context if it currently poll() ing.
-/// XXX Seems to be threading-related routine, how lua will work in this case?
-static int lglib_main_context_wakeup (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	g_main_context_wakeup (object->main_context);
-	return 0;
-}
-
-/// main_context:acquire
-/// Tries to own main context.
-/// R: boolean (success)
-static int lglib_main_context_acquire (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	lua_pushboolean (L, g_main_context_acquire (object->main_context));
-	return 1;
-}
-
-/// main_context:release
-/// Disowns acquired context.
-/// Note: release context as many times, as you acquired it.
-static int lglib_main_context_release (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	g_main_context_release (object->main_context);
-	return 0;
-}
-
-/// main_context:owner
-/// Indicates if current thread is owner of context.
-/// R: boolean
-static int lglib_main_context_owner (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	lua_pushboolean (L, g_main_context_is_owner (object->main_context));
-	return 1;
-}
-
-/// main_context:wait
-/// For now this will not be implemented, as it requires threading part of glib
-
-/// WARNING: conventions for next four methods are likely to change
-/// as I become more familiar with all that stuff.
-
-/// main_context:prepare
-/// Polling preparation step.
-/// R: boolean (indicates readiness for dispatching before polling), integer (priority of most important ready source, if first value is true)
-static int lglib_main_context_prepare (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	gint priority;
-	gboolean ready = g_main_context_prepare (object->main_context, &priority);
-	lua_pushboolean (L, ready);
-	if (!ready)
-		return 1;
-	lua_pushnumber (L, priority);
-	return 0;
-}
-
-/// main_context:query
-/// Get necessary for polling information.
-/// A: integer (maximum priority), integer (number of fds to allocate)
-/// R: userdata (GPollFDs), integer (number of fds required), integer (timeout)
-static int lglib_main_context_query (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	int priority = luaL_checkint (L, 2);
-	int nfds = luaL_checkint (L, 3);
-	gint timeout;
-	GPollFD *fds = lua_newuserdata (L, sizeof (GPollFD) * nfds);
-	lua_pushnumber (L, g_main_context_query (object->main_context, priority, &timeout, fds, nfds));
-	lua_pushnumber (L, timeout);
-	return 3;
-}
-
-/// main_context:check
-/// Passes results of polling back to main loop.
-/// A: integer (priority), userdata (GPollFDs), integer (number of fds)
-/// R: boolean (readiness for dispatching)
-static int lglib_main_context_check (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	int priority = luaL_checkint (L, 2);
-	GPollFD *fds = lua_touserdata (L, 3); // FIXME
-	int nfds = luaL_checkint (L, 4);
-	lua_pushboolean (L, g_main_context_check (object->main_context, priority, fds, nfds));
-	return 1;
-}
-
-/// main_context:dispatch
-/// Actually dispatches pending event sources
-static int lglib_main_context_dispatch (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	g_main_context_dispatch (object->main_context);
-	return 0;
-}
-
-/// main_context:poll_function
-/// main_context:add_poll
-/// main_context:remove_poll
-/// Let's delay implementing this until fd objects will be ready...
-
-/// main_context:pointer
-/// Returns pointe to underlying C structure.
-/// A: g main context object
-/// R: lightuserdata
-static int lglib_main_context_pointer (lua_State *L)
-{
-	lglib_main_context_t *object = luaL_checklglib_main_context (L, 1);
-	lua_pushlightuserdata (L, object->main_context);
-	return 1;
-}
-
-static int lglib_main_context_gc (lua_State *L)
-{
-	lglib_main_context_t *object = lua_touserdata (L, 1);
-	g_main_context_unref (object->main_context);
-	return 0;
-}
-
-static const luaL_Reg lglib_main_context_reg_f[] = {
-	{ "new",     lglib_main_context_new       },
-	{ "bless",   lglib_main_context_bless_lua },
-	{ "default", lglib_main_context_default   },
-	{ NULL,      NULL                         },
-};
-
-static const luaL_Reg lglib_main_context_reg_m[] = {
-	{ "iteration",   lglib_main_context_iteration   },
-	{ "pending",     lglib_main_context_pending     },
-	{ "find_source", lglib_main_context_find_source },
-	{ "wakeup",      lglib_main_context_wakeup      },
-	{ "acquire",     lglib_main_context_acquire     },
-	{ "release",     lglib_main_context_release     },
-	{ "owner",       lglib_main_context_owner       },
-	{ "prepare",     lglib_main_context_prepare     },
-	{ "query",       lglib_main_context_query       },
-	{ "check",       lglib_main_context_check       },
-	{ "dispatch",    lglib_main_context_dispatch    },
-	{ "pointer",     lglib_main_context_pointer     },
-	{ "__gc",        lglib_main_context_gc          },
-	{ NULL,          NULL                           },
-};
-
-int luaopen_glib_main_context (lua_State *L)
-{
-	luaL_newmetatable (L, "glib.main_context" );
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
-	luaL_register (L, NULL, lglib_main_context_reg_m);
-	lua_pop (L, 1);
-	luaL_register (L, "g.main_context", lglib_main_context_reg_f);
-	return 1;
-}
-
--- a/glib_main_context.h	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-
-#ifndef LGLIB_MAIN_CONTEXT
-#define LGLIB_MAIN_CONTEXT
-
-#include <lua.h>
-
-int luaopen_glib_main_context (lua_State *L);
-
-#endif
-
--- a/glib_source.c	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <glib.h>
-
-#include "glib_types.h"
-#include "util.h"
-
-/// g.source.bless
-/// Blesses given pointer to g source object.
-/// A: lightuserdata (pointer to C glib event source object)
-/// R: g source object
-static int lglib_source_bless_lua (lua_State *L)
-{
-	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "glib source lightuserdata expected");
-	lglib_source_bless (L, lua_touserdata (L, 1));
-	return 1;
-}
-
-/// source:context
-/// Connects event source to main context or returns context,
-/// to which this source is connected.
-/// A: lglib main context object
-/// R: int (source id, when called with args) or g main context object or nil (if called with no args)
-static int lglib_source_context (lua_State *L)
-{
-	lglib_source_t *object = luaL_checklglib_source (L, 1);
-	if (lua_gettop (L) > 1) { // Attach
-		lglib_main_context_t *context = luaL_checklglib_main_context (L, 2);
-		lua_pushnumber (L, g_source_attach (object->source, context->main_context));
-	} else { // Get
-		GMainContext *context = g_source_get_context (object->source);
-		if (context) {
-			lglib_main_context_bless (L, context);
-			// XXX g_main_context_unref (context);
-		} else
-			lua_pushnil (L);
-	}
-	return 1;
-}
-
-/// source callback function
-/// Does processing of events. Return value indicates, if source should not be destroyed.
-/// R: boolean (continue)
-static gboolean lglib_source_callback (lglib_callback_t *cb)
-{
-	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	if (lua_pcall (cb->L, 0, 1, 0)) {
-		// XXX lua_error (cb->L);
-		lua_pop (cb->L, 1);
-		return FALSE;
-	}
-	return lua_toboolean (cb->L, -1);
-}
-
-/// source:callback
-/// Sets callback function for given event source.
-/// A: source callback function
-static int lglib_source_set_callback (lua_State *L)
-{
-	lglib_source_t *object = luaL_checklglib_source (L, 1);
-	lglib_callback_t *cb;
-	luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
-	
-	cb = luaL_malloc (L, sizeof (lglib_callback_t));
-	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
-	cb->L         = L;
-
-	g_source_set_callback (object->source, (GSourceFunc)lglib_source_callback,
-			       cb, (GDestroyNotify)lglib_callback_destroy);
-	return 0;
-}
-
-/// source:priority
-/// Sets or gets priority of source.
-/// A: integer (optional priority)
-/// R: integer (when called with no args)
-static int lglib_source_priority (lua_State *L)
-{
-	lglib_source_t *object = luaL_checklglib_source (L, 1);
-	if (lua_gettop (L) > 1) {
-		g_source_set_priority (object->source, luaL_checkint (L, 2));
-		return 0;
-	} else {
-		lua_pushnumber (L, g_source_get_priority (object->source));
-		return 1;
-	}
-}
-
-/// source:pointer
-/// Returns pointer to underlying C structure.
-/// A: g source object
-/// R: lightuserdata
-static int lglib_source_pointer (lua_State *L)
-{
-	lglib_source_t *object = luaL_checklglib_source (L, 1);
-	lua_pushlightuserdata (L, object->source);
-	return 1;
-}
-
-static int lglib_source_gc (lua_State *L)
-{
-	lglib_source_t *object = lua_touserdata (L, 1);
-	g_source_unref (object->source);
-	return 0;
-}
-
-const luaL_Reg lglib_source_reg_f[] = {
-	{ "bless", lglib_source_bless_lua },
-	{ NULL,    NULL                   },
-};
-
-const luaL_Reg lglib_source_reg_m[] = {
-	{ "context",  lglib_source_context      },
-	{ "priority", lglib_source_priority     },
-	{ "callback", lglib_source_set_callback },
-	{ "pointer",  lglib_source_pointer      },
-	{ "__gc",     lglib_source_gc           },
-	{ NULL,       NULL                      },
-};
-
-int luaopen_glib_source (lua_State *L)
-{
-	luaL_newmetatable (L, "glib.source");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
-	luaL_register (L, NULL, lglib_source_reg_m);
-	lua_pop (L, 1);
-	luaL_register (L, "g.source", lglib_source_reg_f);
-	return 1;
-}
-
--- a/glib_source.h	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-
-#ifndef LGLIB_SOURCE_H
-#define LGLIB_SOURCE_H
-
-#include <lua.h>
-
-int luaopen_glib_source (lua_State *L);
-
-#endif
-
--- a/glib_timeout.c	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <glib.h>
-
-#include "util.h"
-#include "glib_types.h"
-
-/// timeout callback function
-/// Function, that will be called periodically until it returns false.
-/// R: boolean
-static gboolean lglib_timeout_callback (lglib_callback_t *cb)
-{
-	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	if (lua_pcall (cb->L, 0, 1, 0)) {
-		// XXX lua_error (cb->L);
-		lua_pop (cb->L, 1);
-		return FALSE;
-	}
-	return lua_toboolean (cb->L, -1);
-}
-
-/// g.timeout.new
-/// Creates new timeout in default context.
-/// A: integer (priority), integer (interval, seconds), timeout callback function
-/// R: integer (id of the event source)
-static int lglib_timeout_new (lua_State *L)
-{
-	int priority = luaL_checkint (L, 1);
-	int interval = luaL_checkint (L, 2);
-	lglib_callback_t *cb;
-	luaL_argcheck (L, lua_isfunction (L, 3), 3, "function expected");
-
-	cb = luaL_malloc (L, sizeof (lglib_callback_t));
-	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
-	cb->L         = L;
-
-	lua_pushnumber (L, g_timeout_add_seconds_full (priority, interval,
-						       (GSourceFunc)lglib_timeout_callback,
-						       cb,
-						       (GDestroyNotify)lglib_callback_destroy));
-	return 1;
-}
-
-/// g.timeout.source
-/// Creates new timeout source.
-/// A: interval
-/// R: g source object
-static int lglib_timeout_source (lua_State *L)
-{
-	int interval = luaL_checkint (L, 1);
-	GSource *source = g_timeout_source_new_seconds (interval);
-	lglib_source_bless (L, source);
-	// XXX s_source_unref (source);
-	return 1;
-}
-
-static const luaL_Reg lglib_timeout_reg_f[] = {
-	{ "new",    lglib_timeout_new    },
-	{ "source", lglib_timeout_source },
-	{ NULL,     NULL                 },
-};
-
-int luaopen_glib_timeout (lua_State *L)
-{
-	luaL_register (L, "g.timeout", lglib_timeout_reg_f);
-	return 1;
-}
-
--- a/glib_timeout.h	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-
-#ifndef LGLIB_TIMEOUT_H
-#define LGLIB_TIMEOUT_H
-
-#include <lua.h>
-
-int luaopen_glib_timeout (lua_State *L);
-
-#endif
-
--- a/glib_types.c	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <glib.h>
-
-#include "glib_types.h"
-#include "util.h"
-
-void lglib_callback_destroy (lglib_callback_t *cb)
-{
-	luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	luaL_free (cb->L, cb);
-}
-
-#define LGLIB_CHECK(WHAT, TYPE)                                               \
-lglib_##WHAT##_t *luaL_checklglib_##WHAT (lua_State *L, int index)            \
-{                                                                             \
-	lglib_##WHAT##_t *object = luaL_checkudata (L, index, "glib." #WHAT); \
-	luaL_argcheck (L, object != NULL, index, "glib " #WHAT " expected");  \
-	return object;                                                        \
-}
-
-#define LGLIB_BLESS(WHAT, TYPE)                                                   \
-lglib_##WHAT##_t *lglib_##WHAT##_bless (lua_State *L, TYPE *WHAT)                 \
-{                                                                                 \
-	lglib_##WHAT##_t *object;                              /* top of stack */ \
-	lua_pushstring (L, LGLIB_OBJREGISTRY);       /* 1 registry table name  */ \
-	lua_rawget (L, LUA_REGISTRYINDEX);                 /* 1 registry table */ \
-	lua_pushlightuserdata (L, WHAT);                   /* 2 light userdata */ \
-	lua_rawget (L, -2);                                    /* 2 object/nil */ \
-	if (!lua_isnil (L, -1)) {                                  /* 2 object */ \
-		lua_remove (L, -2);                                /* 1 object */ \
-		object = lua_touserdata (L, -1);                                  \
-		return object;                                                    \
-	}                                                                         \
-	                                                              /* 2 nil */ \
-	lua_remove (L, -1);                                /* 1 registry table */ \
-	object = lua_newuserdata (L, sizeof (lglib_##WHAT##_t)); /* 2 userdata */ \
-	luaL_getmetatable (L, "glib." #WHAT);                   /* 3 metatable */ \
-	lua_setmetatable (L, -2);                                  /* 2 object */ \
-	lua_pushlightuserdata (L, WHAT);                   /* 3 light userdata */ \
-	lua_pushvalue (L, -2);                                     /* 4 object */ \
-	lua_rawset (L, -4);                                        /* 2 object */ \
-	lua_remove (L, -2);                                        /* 1 object */ \
-	object->WHAT = WHAT;                                                      \
-	g_##WHAT##_ref (WHAT);                                                    \
-	return object;                                                            \
-}
-
-#define LGLIB_DEFINE(WHAT, TYPE) \
-LGLIB_CHECK (WHAT, TYPE)         \
-LGLIB_BLESS (WHAT, TYPE)
-
-LGLIB_DEFINE (main_context, GMainContext)
-LGLIB_DEFINE (source, GSource)
-
-#undef LGLIB_DEFINE
-
--- a/glib_types.h	Mon Feb 09 13:00:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-
-#ifndef LGLIB_TYPES_H
-#define LGLIB_TYPES_H
-
-#include <lua.h>
-#include <glib.h>
-
-#ifndef LGLIB_OBJREGISTRY
-#define LGLIB_OBJREGISTRY ( "lglib.obj_registry" )
-#endif
-
-typedef struct {
-	int reference;
-	lua_State *L;
-} lglib_callback_t;
-
-void lglib_callback_destroy (lglib_callback_t *cb);
-
-
-#define LGLIB_DECLARE(WHAT, TYPE)                         \
-typedef struct {                                            \
-	TYPE *WHAT;                                           \
-} lglib_##WHAT##_t;                                             \
-                                                                  \
-lglib_##WHAT##_t *luaL_checklglib_##WHAT (lua_State *L, int index); \
-lglib_##WHAT##_t *lglib_##WHAT##_bless (lua_State *L, TYPE *WHAT);
-
-LGLIB_DECLARE (main_context, GMainContext)
-LGLIB_DECLARE (source, GSource)
-
-#undef LGLIB_DECLARE
-
-#endif
-