GObject Introspection is coming to Node.js
GObject Introspection (GIR) is a way to create automatic bindings to GNOME libraries for various different programming languages. I’ve written before about the benefits of bringing GIR to PHP, and now it seems something similar is happening on Node.js.
node-gir has been written by Tim Caswell, with help from Sebastian Wick and Piotr Pokora.
I’ve been following the progress for a while, and today, during a flight from Helsinki to Salzburg, I was finally able to open a Midgard repository connection with it. The API still is a bit weird, and lacks support for the asynchronous nature of Node, but those will hopefully change soon. Quick example:
var Midgard, gir, config, mgd;
gir = require("../gir");
gir.init();
Midgard = gir.load("Midgard");
Midgard.init();
// Use a local SQLite database file
config = new Midgard.Config();
config.__set_property__("dbdir", __dirname);
config.__set_property__("dbtype", "SQLite");
config.__set_property__("database", "midgard");
// Open connection to the database
mgd = new Midgard.Connection();
if (!mgd.__call__("open_config", config)) {
console.error("Failed to open connection");
process.exit();
}
node-gir is being developed on GitHub if you want to lend a hand or try it out. To build it, run npm install
and you should be able to run the code examples.
Having GIR support for Node would make it a full-fledged GNOME environment, and mean that there would be proper GObject Introspection in all three major JavaScript runtimes - SpiderMonkey, JavaScriptCore and V8. And this way GNOME JavaScript developers could also utilize the wealth of existing Node.js modules.