Writing a Library with Vala:

Binding to the Library 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.





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 - source code for haskell-gi on GitHub, "Generate Haskell bindings for GObject-Introspection capable libraries"


  • 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."


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"



perl-Glib-Object-Introspection creates Perl bindings at runtime from a typelib file.


PyGObject is a Python package providing bindings using GObject introspection.



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


Projects/Vala/LibraryWritingBindings (last edited 2019-04-18 16:24:55 by AlThomas)