[seed: 2/7] Add ffi.Library constructor
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed: 2/7] Add ffi.Library constructor
- Date: Sun, 2 Aug 2009 01:28:43 +0000 (UTC)
commit c9518305fb0e6403dea3cce677bc06d0d442e707
Author: Robert Carr <racarr gnome org>
Date: Sat Aug 1 17:32:23 2009 -0400
Add ffi.Library constructor
modules/ffi/Makefile.am | 24 ++++++++++++++
modules/ffi/seed-ffi.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+), 0 deletions(-)
---
diff --git a/modules/ffi/Makefile.am b/modules/ffi/Makefile.am
new file mode 100644
index 0000000..c13f2ea
--- /dev/null
+++ b/modules/ffi/Makefile.am
@@ -0,0 +1,24 @@
+if BUILD_FFI_MODULE
+
+seedlibdir = ${libdir}/seed
+
+seedlib_LTLIBRARIES = \
+ libseed_ffi.la
+
+libseed_ffi_la_SOURCES = \
+ seed-ffi.c
+
+AM_CPPFLAGS = \
+ -I top_srcdir@/libseed/ \
+ $(GOBJECT_INTROSPECTION_CFLAGS) \
+ $(SEED_DEBUG_CFLAGS) \
+ $(SEED_PROFILE_CFLAGS)
+
+libseed_ffi_la_LDFLAGS = \
+ $(GOBJECT_INTROSPECTION_LDFLAGS) \
+ $(SEED_PROFILE_LIBS)
+
+endif
+
+
+
diff --git a/modules/ffi/seed-ffi.c b/modules/ffi/seed-ffi.c
new file mode 100644
index 0000000..b7f97c7
--- /dev/null
+++ b/modules/ffi/seed-ffi.c
@@ -0,0 +1,80 @@
+/* -*- mode: C; indent-tabs-mode: t; tab-width: 8; c-basic-offset: 2; -*- */
+
+/*
+ * This file is part of Seed, the GObject Introspection<->Javascript bindings.
+ *
+ * Seed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ * Seed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Seed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) Robert Carr 2009 <carrr rpi edu>
+ */
+
+#include <glib.h>
+#include <seed-module.h>
+
+SeedEngine *eng;
+SeedObject namespace_ref;
+
+SeedClass ffi_library_class;
+
+static SeedObject
+seed_ffi_construct_library (SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException *exception)
+{
+ GModule *mod;
+ SeedObject ret;
+ gchar *filename;
+
+ if (argument_count != 1)
+ {
+ seed_make_exception (ctx, exception,
+ "ArgumentError",
+ "ffi.Library constructor expects 1 argument (filename), got %d",
+ argument_count);
+ return seed_make_null (ctx);
+ }
+ filename = seed_value_to_string (ctx, arguments[0], exception);
+
+ mod = g_module_open (filename, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
+ if (!mod)
+ {
+ seed_make_exception (ctx, exception, "GModuleError",
+ "Opening module (%s) failed with: %s",
+ filename, g_module_error ());
+ return seed_make_null (ctx);
+ }
+
+ ret = seed_make_object (ctx, ffi_library_class, mod);
+
+ return ret;
+}
+
+SeedObject
+seed_module_init(SeedEngine *local_eng)
+{
+ SeedObject library_constructor;
+ seed_class_definition ffi_library_def = seed_empty_class;
+
+ ffi_library_def.class_name = "FFILibrary";
+
+ ffi_library_class = seed_create_class (&ffi_library_def);
+
+ eng = local_eng;
+ namespace_ref = seed_make_object (eng->context, NULL, NULL);
+
+ library_constructor = seed_make_constructor (eng->context, ffi_library_class, seed_ffi_construct_library);
+ seed_object_set_property (eng->context, namespace_ref, "Library", library_constructor);
+
+ return namespace_ref;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]