seed r313 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r313 - trunk/libseed
- Date: Mon, 24 Nov 2008 00:38:45 +0000 (UTC)
Author: racarr
Date: Mon Nov 24 00:38:44 2008
New Revision: 313
URL: http://svn.gnome.org/viewvc/seed?rev=313&view=rev
Log:
Add C extension modules.
Modified:
trunk/libseed/Makefile.am
trunk/libseed/seed-engine.c
trunk/libseed/seed-engine.h
trunk/libseed/seed-private.h
trunk/libseed/seed.h
Modified: trunk/libseed/Makefile.am
==============================================================================
--- trunk/libseed/Makefile.am (original)
+++ trunk/libseed/Makefile.am Mon Nov 24 00:38:44 2008
@@ -25,6 +25,7 @@
$(LIBSEED_LIBS)
AM_CPPFLAGS = \
+ -lgmodule-2.0 \
$(LIBSEED_CFLAGS)
seedheaders_HEADERS = \
Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c (original)
+++ trunk/libseed/seed-engine.c Mon Nov 24 00:38:44 2008
@@ -769,6 +769,30 @@
return TRUE;
}
+static GModule * seed_try_load_extension(gchar * name)
+{
+ GModule * module;
+ gchar * path;
+ gchar * lowername;
+
+ lowername = g_utf8_strdown(name, -1);
+
+ path = g_module_build_path("/usr/local/lib", lowername);
+
+ module = g_module_open(path, G_MODULE_BIND_LAZY);
+
+ if (!module)
+ {
+ g_free(path);
+ path = g_module_build_path("/usr/lib", lowername);
+
+ module = g_module_open(path, G_MODULE_BIND_LAZY);
+ }
+ g_free(path);
+ g_free(lowername);
+ return module;
+}
+
static JSValueRef
seed_gi_import_namespace(JSContextRef ctx,
JSObjectRef function,
@@ -778,12 +802,13 @@
{
GIBaseInfo *info;
GError *e = 0;
- const gchar *namespace;
- const gchar *extension;
+ gchar *namespace;
const gchar *version = 0;
+ gchar * jsextension;
JSObjectRef namespace_ref;
JSStringRef extension_script;
gint n, i;
+ GModule * extension;
if (argumentCount == 0)
{
@@ -799,6 +824,21 @@
{
version = seed_value_to_string(arguments[1], exception);
}
+
+ extension = seed_try_load_extension(namespace);
+ if (extension)
+ {
+ SeedModuleInitCallback * init;
+
+ g_module_symbol(extension,
+ "seed_module_init",
+ (gpointer *)&init);
+
+ (*init)(eng);
+
+ g_free(namespace);
+
+ }
if (!g_irepository_require(g_irepository_get_default(), namespace,
version, 0, &e))
@@ -958,12 +998,12 @@
}
- extension =
+ jsextension =
g_strdup_printf("try{Seed.include(\"/usr/share/seed/%s.js\");}"
"catch(e){}"
"Seed.include(\"/usr/local/share/seed/%s.js\");",
namespace, namespace);
- extension_script = JSStringCreateWithUTF8CString(extension);
+ extension_script = JSStringCreateWithUTF8CString(jsextension);
JSEvaluateScript(ctx, extension_script, NULL, NULL, 0, NULL);
JSStringRelease(extension_script);
Modified: trunk/libseed/seed-engine.h
==============================================================================
--- trunk/libseed/seed-engine.h (original)
+++ trunk/libseed/seed-engine.h Mon Nov 24 00:38:44 2008
@@ -47,4 +47,6 @@
gboolean instance);
void seed_create_function(gchar * name, gpointer func, JSObjectRef obj);
+typedef void (*SeedModuleInitCallback) (SeedEngine * eng);
+
#endif
Modified: trunk/libseed/seed-private.h
==============================================================================
--- trunk/libseed/seed-private.h (original)
+++ trunk/libseed/seed-private.h Mon Nov 24 00:38:44 2008
@@ -25,6 +25,7 @@
#include <JavaScriptCore/JavaScript.h>
#include <glib.h>
#include <glib-object.h>
+#include <gmodule.h>
#include <stdlib.h>
#include <stdio.h>
#include <girepository.h>
Modified: trunk/libseed/seed.h
==============================================================================
--- trunk/libseed/seed.h (original)
+++ trunk/libseed/seed.h Mon Nov 24 00:38:44 2008
@@ -31,6 +31,11 @@
typedef struct _SeedScript SeedScript;
+typedef struct _SeedEngine {
+ SeedContextRef context;
+ SeedValue global;
+} SeedEngine;
+
/*
* seed-engine.c
*/
@@ -101,4 +106,7 @@
void seed_create_function(gchar * name, SeedFunctionCallback callback,
SeedObject object);
+
+typedef void (*SeedModuleInitCallback) (SeedEngine * eng);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]