Redirected from page "Seed"

Clear message

/!\ The Seed project is unmaintained. If you are looking for the JavaScript bindings for the GNOME platform, use GJS instead. /!\

Seed - GObject JavaScriptCore bridge

Seed is a library and interpreter, dynamically bridging (through GObjectIntrospection) the WebKit JavaScriptCore engine, with the GNOME platform. Seed serves as something which enables you to write standalone applications in JavaScript, or easily enable your application to be extensible in JavaScript.

Latest release can be found here

https://download.gnome.org/sources/seed/

Introduction

Seed is built around the idea of "minimal-platform", in that it seems a theoretically ideal GNOME development language provides no platform of its own, but instead seamlessly integrates with the already quite large GNOME platform. Some of Seed are listed below:

  • Dynamically load and bind libraries for which GObjectIntrospection data is available.

  • Methods, constructors, properties, signals, interfaces, etc. transparently bind to JavaScript. Maps C-isms (say, out arguments, or enums) to things that make sense in JavaScript.

  • Garbage collector integration with GObject reference counts for automatic memory management. Structs are allocated and memory managed effeciently with g_slice.
  • Automatic and powerful type conversion, capable of converting between everything from simple types, to GList/Array, to boxing JavaScript functions up in C function pointers (required by some libraries for say, foreach functions).

  • Automatic GError integration with JavaScript exceptions. You leave the GError argument out of your arguments, and internally Seed passes it in to the method, and throws an exception with the proper name and message if an error is generated.

  • Some "syntactic sugar" which makes code more pleasant to write, such as JSON key/value pairs for constructor properties, literals for structs (stage.color = {red: 200}).
  • Ability to define new GTypes which inherit from existing GTypes. As of now you can not implement abstract methods, but beyond that it works. Signals and properties work.
  • A C module system, useful for binding libraries which are not GObject based (such as readline, sqlite, and many low level POSIX functons).

At this point, the vast majority of the GNOME platform is usable from Seed.

In general using any GObject based API (internal to your application, or a library) in Seed, should not be difficult, and should simply require a few changes to your build scripts to allow generation of the introspection data.

There is a writeup on Seed which I believe provides a good description.

Current Status

By and large Seed is able to properly bind anything in the GNOME platform. One of the biggest shortfalls in Seed as of now is the lack of ability to implement GObject interfaces (though in general subclassing does work). I believe Seed to be mostly leak free at this point, however it is not as memory efficient as it could be, in particular where closures are involved (It still compares quite favorably to languages such as Python however).

License

Seed is available under the LGPL. Most of the examples are under a BSD license, however some of the more complicated ones (such as lightsoff or same-seed) are under the GPL.

Documentation

Seed has a wide variety of examples, located at http://git.gnome.org/cgit/seed-examples, covering many common tasks in a "cookbook" style fashion, and several more complete applications. Seed has a (small) documentation site which covers the C API, the Seed runtime, and a tutorial aimed at Gtk beginners to create a small web browser. In the future this will likely be expanded.

There are now some documentation for the bound libraries, along with A short description on how it's generated

A small JavaScript Side tutorial is located here.

Editor Support

There may one day be an emacs mode for Seed, in the mean time I suggest espresso-mode, though some people prefer js2-mode. There is a Summer of Code project for adding JavaScript support to Anjuta.

Requirements

Seed is fairly light on dependencies:

  • GObject-Introspection from GIT
  • A recent version of WebKitGtk

To be useful, Seed will also require gir-repository.

Development is in Gnome's git repository

Browse : http://git.gnome.org/browse/seed

git clone git://git.gnome.org/seed 

Contact

Some discussion takes place in #seed on GIMPnet. Bugs can be reported in the issue tracker. There is a user/developer mailing list on GNOME mailman.

  • Robert Carr <racarr at gnome dot org>

  • Tim Horton <hortont424 at gmail dot com>

Examples

These are a few small examples, to give a quick picture of what Seed looks like.

Constructor

timeline = new Clutter.Timeline({fps:60, num_frames:30});

Methods and Properties

widget.events = Gdk.EventMask.all_events_mask;
description = widget.create_pango_context();

Signals

var update_url = function (web_view, web_frame, url_entry)
{
    url_entry.text = web_frame.get_uri();
}

browser_view.signal.load_commited.connect(update_url, entry);

Note that the function could be an inline anonymous function, instead of a closure. Also of interest is the fact that the second argument to the signal connections represents the userdata which is passed to the signal handler.

New Types and Signals

HelloLabel = new GType({
    parent: Gtk.Label.type,
    name: "HelloLabel",
    signals: [{name: "say-hello"}],
    init: function(klass){
        this.text = "Hello" // Hello labels always say hello.
    }
});
HelloLabel.prototype.say_goodbye = function(){this.text = "Goodbye"};
/* Later */
label1 = new HelloLabel();
label1.signal.say_hello.emit();

Error Handling

try{
    var file = Gio.file_new_for_path("/tmp");
    var fstream = file.replace();
}
catch (e){
    // e.name is equal to GIoError.
    // e.message is equal to "Error opening file '/tmp/': Is a directory
    // Also has source file/line number, as line and sourceURL properties
}

Struct/Boxed Literals

stage.color = {red: 255, alpha: 80}; // Struct is allocated (with GSlice). 
                                     // Other elements are initialised to zero.
                                     // When the stage is destroyed, or the color changes, the struct is freed.

Screenshots

Projects/Seed (last edited 2024-02-21 08:23:08 by EmmanueleBassi)