writing some tcl GI bindings

in

introduction

hello, everyone! it’s been a while. i thought i’d post an update on this site for once…

lately, I’ve been writing a lot of Tcl. it’s a very interesting language (I think). anyhow, one thing that I think the language would benefit hugely from is GI bindings (well, aside from better FFI in general)

what is GI?

GI (short for GObject Introspection) is a framework that allows one to introspect the type definitions of GLib libraries. a program called g-ir-scanner(1) first is used to generate .gir files, which are then compiled into Typelib files via g-ir-compiler(1), which can then be inspected by using libgirepository.

what use does it have?

implementing GI support lets you access some interesting libraries. some that i would find quite nice are libwp (which lets you access wireplumber) and GStreamer (which lets you do stuff with media), but it most famously also gives you support for GTK.

how would it work with Tcl?

the nice thing about Tcl is that its require syntax fits well with the require system of GLib. in a language like Python, you need to do something like this:

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst

whereas in Tcl, you can specify versions directly in == so it would look like this:

package require gi 0.1
package require gi::Gst 1.0
# access commands under the gi::Gst namespace...

a major issue might be lifetime management. I think I’ll provide a function like g_autoptr that will use write and unset traces. I guess I could maybe map most things to TclOO classes (or classes in that style), and then map structs and errors to native Tcl.

how are you implementing this?

in order to reduce the cumbersome parts of writing such bindings, I wrote VAPI bindings for Vala, which allows me to use closures in C. You can view my work so for at https://codeberg.org/Makefile_dot_in/tcl-gi.

miscellaneous updates

i’ve been meaning to move this site off of Oracle to OVH because I don’t want to rely on Lary Ellison’s infrastructure, but it’s going quite slowly >.< I’ve had my VPS for a year by now and i haven’t gotten around to it. I hope to do it eventually.

this blog post is quite rushed, I’ll post another update if I ever manage to get this project to a better place.