6.5. Binding to Vala Libraries from Other Languages¶
Vala produces C code and also produces C headers. Binding from C is relatively easy, although the library may make use of a lot of GObject boiler plate code.
For Vala based projects, using either the Vala or Genie syntax, a VAPI can be produced that makes bindings easy.
The Vala compiler can also produce a GObject Introspection Repository (GIR) file. This makes bindings from languages that support GObject Introspection very easy. Often the binding is at runtime so a typelib file also needs to be produced and libgirepository and libffi are used at runtime for the binding.
6.5.1. Haskell¶
As of January 2017 the Haskell generator from GObject introspection repositories, haskell-gi, is described as complete. The Haskell wiki page on GObject Introspection advises “The Haskell code generator at haskell-gi is now essentially complete: all the information exposed in the bindings should now be available from the autogenerated bindings. This includes: ordinary functions, signals, virtual functions, structure fields, object properties, etc.”
haskell-gi - Generate Haskell bindings for GObject-Introspection capable libraries
6.5.2. JavaScript¶
node-gtk - “uses the GObject Introspection library (as PyGObject, for example), so any gobject-introspectable library is supported”
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…With it you can also write the performance-intensive parts of your applications in Vala and call them from Node.js and other languages.”
6.5.3. Lua¶
LGI provides runtime bindings for Lua 5.1+ and LuaJIT2. It uses libgirepository to read typelib files.
There are alternative binding generators: lgob and LuiGI. lgob parses GIR files to generate Lua modules. LuiGI was an experimental dynamic binding generator. LGI should be used instead of LuiGI.
LGI - “LGI is gobject-introspection based dynamic Lua binding to GObject based libraries…LGI is tested and compatible with standard Lua 5.1, Lua 5.2, Lua 5.3 and LuaJIT2.”
lgob - “lgob provides bindings of GObject-based libraries (like GTK+ and WebKitGTK+), for Lua 5.1 / 5.2 / LuaJIT. It consists of a compiler that parses GObject-Instrospection gir files and generates Lua modules. lgob ships with bindings for GTK+, pango, cairo, vte, WebKitGtk, GtkTextView, and others”
Some thoughts (and code) around GObject-Introspection- blog post from 2010 about the origins of LuiGI, “the kind people there made me note about LGI, which is also a dynamic GI binding for Lua…but looking at its code I can tell that it is more complete than my own, so I will be probably contributing to it instead of duplicating efforts”
6.5.4. Perl¶
perl-Glib-Object-Introspection creates Perl bindings at runtime from a typelib file.
Glib::Object::Introspection - CPAN module of perl-Glib-Object-Introspection. The CPAN page includes examples.
6.5.5. Python¶
PyGObject is a Python package providing bindings using GObject introspection.
PyGObject Documentation - “PyGObject provides full support of GObject Introspection and all of its features (callbacks, GVariant support, closures, sub-classing, etc.)”
pgi-docgen - GitHub repository of the API Documentation Generator for PyGObject
PyGObject API Reference - pre-built API documentation for numerous libraries available through PyGObject
6.5.6. Rust¶
The gtk-rs project has developed the gir
tool to generate Rust bindings from a GIR file.
gtk-rs/gir - GitHub repository for the
gir
tool. A GIR file is needed and an additional TOML file is used to pass binding metadata to the tool