Git Product home page Git Product logo

node-gir's Introduction

node-gir

Node-gir is Node.js bindings to GObject Introspection making it possible to make automatic and dynamic calls to any library that has GI annotations installed. This includes most libraries from the GNOME project.

This will make it possible to script a GNOME desktop system entirely from node much in the way it's done today with Seed, GJS or pygtk. It also allows using GNOME libraries in Node.js applications. With it you can also write the performance-intensive parts of your applications in Vala and call them from Node.js and other languages.

Installation

You need GObject Introspection library to be installed. On a Debian-like system this would be handled by:

$ sudo apt-get install libgirepository1.0-dev

Then just build node-gir with:

$ npm install gir

Testing

The node-gir repository comes with a set of tests that utilize the Midgard2 library to test against. You need also that installed, and then run:

$ npm test

Travis is used for Continous Integration:

Build Status

Architecture

The following graph shows all the parts and how they work together. The only missing part is node bindings to libgirepository. Hence this project.

BUILD TIME:

          +-----------------------------------------------------------+
          |   foo.c                                                   |
          |   foo.h                                                   |
          |                                                           |
          | Library sources, with type annotations                    |
          +-----------------------------------------------------------+
              |                                      |
             gcc                                 g-ir-scanner
              |                                      |
              |                                      V
              |                              +------------------------+
              |                              |    Foo.gir             |
              |                              |                        |
              |                              |    <GI-name>.gir       |
              |                              |                        |
              |                              | XML file               |
              |                              |                        |
              |                              | Invocation information |
              |                              | Required .gir files    |
              |                              | API docs               |
              |                              |                        |
              |                              +------------------------+
              |                                          |
              |                                     g-ir-compiler
              |                                          |
  DEPLOYMENT TIME:                                       |
              |                                          |
              V                                          V
        +-----------------------------+      +---------------------------+
        |   libfoo.so                 |      |    Foo.typelib            |
        |                             |      |                           |
        |                             |      | Binary version of the     |
        |  ELF file                   |      | invocation info and       |
        |                             |      | required .typelib files   |
        |  Machine code, plus         |      +---------------------------+
        | dynamic linkage information |                  A
        | (DWARF debug data, etc)     |                  |
        +-----------------------------+                  |
                     A                                   |
                     |                       +---------------------------+
                     |                       |  libgirepository.so       |
                +-----------+                |                           |
                | libffi.so |                |  Can read typelibs and    |
                |           |                |  present them in a        |
                +-----------+                |  libffi-based way         |
                     A                       |                           |
                     |                       +---------------------------+
                     |                                  A
                     |                                  |
                     |                          +------------+
                     +--------------------------|  node-gir  |
                                                |            |
                                     +--------->+------------+
                                     |
                           +------------------+
                           |      NodeJS      |
                           +------------------+

Why not use Seed or GJS

Because they are nice, but not what I'm looking for. Node is really popular and it would be nice to be able to use it for desktop tools and applications.

Implementation Notes

Here are some links and notes as I try to figure out how to do this.

API Ideas

Some of these ideas will go in this binding and some will go in nice wrappers that use it. I'll know more as we progress.

  • Use camelCase for methods that are bound to look JavaScripty.
  • Use .on(name, callback) to attach signals.
  • Keep the same constructor style used by Seed and GJS
  • Make the module system as node-like as possible.

Things which work

  • All classes get created
  • classes get inherited
  • interface methods are inherited
  • A class has lists of all its properties, methods, signals, vfuncs and fields
  • C structures are propagated as objects (fields are properties)
  • Both methods and static method can be called
  • You can create a class
  • functions can be called (but it does not work so well with 'out' arguments which should be set as returned value)
  • GError is propagated as generic exception
  • property values can be set/get
  • events can be watched
  • flags, enums etc are set

Things which dont work (correct)

  • Conversion between a v8 value and a GValue/GArgument is veeeery buggy (but everything needs it so most things are buggy)
  • No support for libev/libuv; glib is using its own stuff (gst.main())
  • There is no good way to delete an object (memory management sucks at all)
  • types/function.cc need a rewrite
  • GError should be propagated as derived classes depending on GError domain

node-gir's People

Contributors

ackalker avatar benwaffle avatar bergie avatar creationix avatar daball avatar jasperla avatar jonnor avatar piotras avatar swick avatar trevorlinton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-gir's Issues

Can't install on ubuntu

npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm http GET https://registry.npmjs.org/gir
npm http 304 https://registry.npmjs.org/gir

> [email protected] install /home/alan/Projetos/gir/node_modules/gir
> node-gyp rebuild

static library binding.gyp:girepository#target has several files with the same basename:
  function: src/function.cc src/types/function.cc
Some build systems, e.g. MSVC08, cannot handle that.
gyp: Duplicate basenames in sources section, see list above
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.8.0-30-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/alan/Projetos/gir/node_modules/gir
gyp ERR! node -v v0.10.18
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok 
npm ERR! weird error 1
npm ERR! not ok code 0

Xvfb support

Hi,
I'm trying to run some of your examples on a headless server / via Xvfb on a Linux box. I figured I'd ask if you had any advice / if this were possible.

The end goal is basically to run a headless server running some the examples in the ./examples dir, and then using a remote machine's browser to connect to the headless server to run the examples.

I'm going through it right now.

Thanks!

browser.js example fails

$ node browser.js 

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Requiring namespace 'Gtk' version '2.0', but '3.0' is already loaded
    at Object.<anonymous> (/home/james/src/node-gir/examples/webkit.js:6:35)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at require (module.js:346:19)
    at Object.<anonymous> (/home/james/src/node-gir/examples/browser.js:5:14)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)

yes I have gtk3 installed. example works fine when using gtk2.

use gtk3

the latest version of gtk is gtk3. node-gir is a brand new project, there's no reason to start it off by using legacy gtk versions.

Crash in the Guitar Tuner example

I ported the guitar tuner example from GNOME developer docs to node-gir and CoffeeScript:

https://github.com/bergie/node-gir/blob/master/examples/guitartuner.coffee

When I try to make GStreamer to play a sound (by clicking a button), there is a segfault. Backtrace is:

(gdb) run guitartuner.js
Starting program: /usr/bin/node guitartuner.js
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff63a8700 (LWP 14064)]
[New Thread 0x7fffee905700 (LWP 14065)]
[New Thread 0x7fffed093700 (LWP 14066)]
369.23

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5769d60 in g_base_info_equal () from /usr/lib/libgirepository-1.0.so.1
(gdb) bt full
#0  0x00007ffff5769d60 in g_base_info_equal () from /usr/lib/libgirepository-1.0.so.1
No symbol table info available.
#1  0x00007ffff599f21b in gir::GIRObject::New(_GObject*, _GIBaseInfoStub*) () from /home/bergie/Projects/node-gir/build/Release/lib.target/girepository.node
No symbol table info available.
#2  0x00007ffff599c358 in gir::Args::FromGType(_GIArgument*, _GIBaseInfoStub*, int) () from /home/bergie/Projects/node-gir/build/Release/lib.target/girepository.node
No symbol table info available.
#3  0x00007ffff599d35b in gir::Func::Call(_GObject*, _GIBaseInfoStub*, v8::Arguments const&, bool) ()
   from /home/bergie/Projects/node-gir/build/Release/lib.target/girepository.node
No symbol table info available.
#4  0x00007ffff599de75 in gir::GIRObject::CallStaticMethod(v8::Arguments const&) () from /home/bergie/Projects/node-gir/build/Release/lib.target/girepository.node
No symbol table info available.
#5  0x0000000000592b62 in ?? ()

Error in namespace_loader.cc:18:58 if I try to build node-gir

node-waf configure
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for node path                   : not found 
Checking for node prefix                 : not found 
Checking for gobject-introspection-1.0   : yes 
Checking for glib-2.0                    : yes 
'configure' finished successfully (0.060s)
node-waf build
Waf: Entering directory `/my-node-gir-path/build'
[ 3/10] cxx: src/namespace_loader.cc -> build/Release/src/namespace_loader_1.o
[ 6/10] cxx: src/values.cc -> build/Release/src/values_1.o
[ 7/10] cxx: src/types/object.cc -> build/Release/src/types/object_1.o
[ 8/10] cxx: src/types/struct.cc -> build/Release/src/types/struct_1.o
../src/namespace_loader.cc: In static elementfunction »static void gir::NamespaceLoader::Initialize(v8::Handle<v8::Object>)«:
../src/namespace_loader.cc:18:58: Error: »NODE_SET_METHOD« not defined
Waf: Leaving directory `/my-node-gir-path/build'
Build failed:  -> task failed (err #1): 
    {task: cxx namespace_loader.cc -> namespace_loader_1.o}

What's wrong?

Where can I find documents about node-gir please?

As I discovered that GNOME's docs are really unfriendly to JS-only developers.
And after a long time I didn't find a document about seed or gjs as friendly as Node APIs.
That's why I want to try node-gir.
Please is there any document I can refer to in writing GTK applications with node-gir?
I mean is there a plain description about gir when you implement node-gir?

Thanks.

Arguments in structure constructor

C structures are propagated as objects. However, node gir structure's constructor doesn't accept arguments if C function requires such to create new structure.

Creation methods with parameters are ignored

For example

var box = new gtk.Box(gtk.Orientation.vertical, 4);

or

var box = new gtk.Box({orientation:gtk.Orientation.vertical});

are not working, the box has no vertical orientation or an error.

But this works:

box.orientation = gtk.Orientation.vertical;

Similar in

label = new gtk.Label("test");

This label has not the given text "test" inside it.

But this works:

label.set_label("test");

or this works,too:

label = new gtk.Label({label:"test"});

Segfault when loading the Midgard GIR file

This script:

var Midgard, gir;
gir = require("./build/default/girepository.node");
gir.init();
Midgard = gir.load("Midgard");

Causes:

Program received signal SIGSEGV, Segmentation fault.
0x00007fffd1cc63f4 in g_base_info_get_name ()
   from /usr/lib/libgirepository-1.0.so.1
(gdb) 
(gdb) bt full
#0  0x00007fffd1cc63f4 in g_base_info_get_name ()
   from /usr/lib/libgirepository-1.0.so.1
No symbol table info available.
#1  0x00007fffd1f2c41a in gir::GIRObject::PropertyList (info=0xc4c800)
    at ../src/interfaces/object.cc:554
        parent = 0x0
        l = 0
        list = {val_ = 0xc16b18}
        first = false
        gcounter = 0
#2  0x00007fffd1f299c5 in gir::GIRObject::Prepare (target=..., 
    info=0xc4c800) at ../src/interfaces/object.cc:152
        temp = {<v8::Handle<v8::FunctionTemplate>> = {
            val_ = 0xc16ad0}, <No data fields>}
        oft = {type_name = 0xc3ea80 "ParamLongtext", info = 0xc4c800, 
          function = {<v8::Handle<v8::FunctionTemplate>> = {
              val_ = 0x7ffff7fa3d88}, <No data fields>}, type = 12893408}
        scope = {prev_next_ = 0xc16ad0, prev_limit_ = 0xc18860, 
          is_closed_ = false}
        name_ = 0x7fffd1f0b7a4 "ParamLongtext"
        name = 0xc3ea80 "ParamLongtext"
        t = {<v8::Handle<v8::FunctionTemplate>> = {
            val_ = 0x7ffff7fa3d88}, <No data fields>}
        l = 0
#3  0x00007fffd1f25166 in gir::NamespaceLoader::BuildClasses (
    namespace_=0xc40eb0 "Midgard") at ../src/namespace_loader.cc:75
        info = 0xc4c800
        i = 58
        exports = {val_ = 0xc16898}
        length = 171
#4  0x00007fffd1f25073 in gir::NamespaceLoader::LoadNamespace (
    namespace_=0xc40eb0 "Midgard") at ../src/namespace_loader.cc:52
        er = 0x0
        lib = 0xc42000
#5  0x00007fffd1f24e8c in gir::NamespaceLoader::Load (args=...)
    at ../src/namespace_loader.cc:32
        scope = {prev_next_ = 0xc16890, prev_limit_ = 0xc18860, 
          is_closed_ = false}
        namespace_ = {str_ = 0xc40eb0 "Midgard", length_ = 7}
        exports = {val_ = 0xc16890}
#6  0x000000000056db10 in ?? ()
No symbol table info available.
...

Midgard GIR file is from Ubuntu OBS packages, and today's checkout of node-gir.

GError implementation

GError should extend Exception. Every derived exception should depend on GError's domain. For example, GFileError should be propagated as FileError exception with particular codes.

reconsider name mangling on api

saw bergies post in node gir, im the maintainer of seed, so if you need help there is a javascript mailing list on gnome.

Please rethink the camels method mangling, it will break all compatibility between gjs and seed.

The connect<>on mentioned should be feasible in the javascript wrapper layer

Error message when linking library

I get an error message with the few code of var rpg = Gir.load('rpg', '0.3'); Nevertheless I can use my library.

** (process:17727): CRITICAL **: g_irepository_find_by_name: assertion `typelib != NULL' failed

** (process:17727): CRITICAL **: g_irepository_find_by_name: assertion `typelib != NULL' failed

** (process:17727): CRITICAL **: g_interface_info_get_n_prerequisites: assertion `GI_IS_INTERFACE_INFO (info)' failed

** (process:17727): CRITICAL **: g_interface_info_get_n_methods: assertion `GI_IS_INTERFACE_INFO (info)' failed

** (process:17727): CRITICAL **: g_irepository_find_by_name: assertion `typelib != NULL' failed

** (process:17727): CRITICAL **: g_irepository_find_by_name: assertion `typelib != NULL' failed

** (process:17727): CRITICAL **: g_interface_info_get_n_prerequisites: assertion `GI_IS_INTERFACE_INFO (info)' failed

** (process:17727): CRITICAL **: g_interface_info_get_n_methods: assertion `GI_IS_INTERFACE_INFO (info)' failed

** (process:17727): CRITICAL **: g_irepository_find_by_name: assertion `typelib != NULL' failed

** (process:17727): CRITICAL **: g_irepository_find_by_name: assertion `typelib != NULL' failed

** (process:17727): CRITICAL **: g_interface_info_get_n_prerequisites: assertion `GI_IS_INTERFACE_INFO (info)' failed

** (process:17727): CRITICAL **: g_interface_info_get_n_methods: assertion `GI_IS_INTERFACE_INFO (info)' failed

problem connecting signals (gir/gtk3)

hi

i've some problems to understand where i fall, because it seems that when i try to connect a callback to a menuitem, when i click on that, it repeats the launching of the callback a number of times equals to the number of elements in that menu.

probably the function that link callbacks needs some work.

example:

var menu1=new gtk.Menu();
var menu1label=new gtk.MenuItem({label: "File"});
var openlabel=new gtk.MenuItem({label:"Open"});
var quitlabel=new gtk.MenuItem({label:"Quit"});
quitlabel.on("select", function() { console.log("quit"); } );
openlabel.on("select", function() { console.log("open"); });
menubar.append(menu1label);  

menu1label.set_submenu(menu1);
menu1.append(openlabel);
menu1.append(quitlabel);
menu1label.show_all();

Failed to convert argument 2 "3" to GI Type tag "interface"

I understand it is a missing type in node-gir.

This comes up when doing
webView.get_main_frame().print_full(printOp, gtk.PrintOperationAction.export);
or the webkitgtk C equivalent :
webkit_web_frame_print_full(mywebframe, myPrintOperation, GTK_PRINT_OPERATION_ACTION_EXPORT)

New Maintainer

I'm looking for a new maintainer. I don't have time to even review pull requests for this project. Who wants to take over? @swick @daball

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.