[PATCH] Allow specifying typelib versions
Johan Bilien <[email protected]> Wed, 22 Oct 2008 11:37:41 +0200
| Newsgroups | gmane.comp.gnome.language-bindings |
|---|---|
| Message-ID | <[email protected]> |
--X1bOJ3K7DJ5YkBrT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline If you would require clutter-0.8, you would set imports.gi.versions.clutter = '0.8'; -- Johan Bilien <[email protected]> --X1bOJ3K7DJ5YkBrT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="gjs-gi-versions.diff" Index: gi/repo.c =================================================================== --- gi/repo.c (revision 34) +++ gi/repo.c (working copy) @@ -59,17 +59,40 @@ GIRepository *repo; GError *error; char *fixed_ns_name; + JSContext *load_context; + jsval versions_val; + JSObject *versions; + jsval version_val; + const char *version; + load_context = gjs_runtime_get_load_context(JS_GetRuntime(context)); + if (!gjs_object_require_property(load_context, repo_obj, "versions", &versions_val) || + !JSVAL_IS_OBJECT(versions_val)) { + gjs_throw(context, "No 'versions' property in GI repository object"); + return NULL; + } + + versions = JSVAL_TO_OBJECT(versions_val); + fixed_ns_name = gjs_fix_ns_name(ns_name); + version = NULL; + if (JS_GetProperty(load_context, versions, ns_name, &version_val) && + JSVAL_IS_STRING(version_val)) { + version = gjs_string_get_ascii(version_val); + } else if (JS_GetProperty(load_context, versions, fixed_ns_name, &version_val) && + JSVAL_IS_STRING(version_val)) { + version = gjs_string_get_ascii(version_val); + } + repo = g_irepository_get_default(); error = NULL; - g_irepository_require(repo, fixed_ns_name, NULL, 0, &error); + g_irepository_require(repo, fixed_ns_name, version, 0, &error); if (error != NULL) { gjs_throw(context, - "Requiring %s fixed as %s: %s", - ns_name, fixed_ns_name, error->message); + "Requiring %s fixed as %s, version %s: %s", + ns_name, fixed_ns_name, version?version:"none", error->message); g_error_free(error); g_free(fixed_ns_name); return JS_FALSE; @@ -218,6 +241,7 @@ { JSObject *repo; JSObject *global; + JSObject *versions; /* We have to define the class in the global object so we can JS_ConstructObject */ @@ -262,6 +286,16 @@ return JS_FALSE; } + versions = JS_ConstructObject(context, NULL, NULL, NULL); + + JS_DefineProperty(context, repo, + "versions", + OBJECT_TO_JSVAL(versions), + NULL, NULL, + JSPROP_PERMANENT); + + g_assert(gjs_object_has_property(context, repo, "versions")); + /* FIXME - hack to make namespaces load, since * gobject-introspection does not yet search a path properly. */ Index: examples/clutter.js =================================================================== --- examples/clutter.js (revision 34) +++ examples/clutter.js (working copy) @@ -1,3 +1,4 @@ +imports.gi.versions.clutter = '0.8'; const Clutter = imports.gi.clutter; Clutter.init(null, null); --X1bOJ3K7DJ5YkBrT Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ language-bindings mailing list [email protected] http://mail.gnome.org/mailman/listinfo/language-bindings --X1bOJ3K7DJ5YkBrT--