The Programs of the Week We Joined Mastodon
This Week’s Program: Apr 3 - Apr 7
My commits are dense and all over the place this week. Just as I hit my stride in my GIR library, I hit a wall with how to represent something in the API. I need the weekend to chew on a game plan.
Thankfully there’s a nice distraction to be had in Mastodon. The new federated social network has captured the imagination of those of us who are more than a little burnt on Twitter and more than a little interested in networks built on standard protocols and technologies. I am @mw@mastodon.social.
I find Mastodon fascinating, not so much because of its potential as a
Twitter escape hatch, but because the protocols that drive a federated
publication/syndication network are ripe for exploitation. Could you
make an experience like Snapchat Stories on the Mastodon/GNU Social
protocols? The potential for new experiences and interfaces is so
interesting. It reminds me of peak RSS or when I first discovered
tumblelogs. When I reach a conclusion with overscan
, I’ll be
eyeballing Mastodon for my next project.
Despite my fascination with Mastodon, I’m finding myself more and more fatigued with social networking. There’s been a downward trend in my “engagement”. My tweets aren’t liked or RT’d. My subscription count is stagnant if not down for this newsletter. Am I losing touch? Are people just not into this whole Racket thing? What does my (tiny) audience expect from me? What do you, dear reader, expect?
I hope you expect the sickest code.
f1438547294b2dc41e7845e6a5c242921032d24f
I create a base struct gi-base
, for all the other GObject
Introspection structs to inherit from. I’m trying to get my codebase
to be a better match to what GIR actually does. I also make it so that
when invoking a function returns a pointer, I cast it to another
pointer that represents a structure that can be introspected. This
way, I can call methods on GObject instances.
7e1a037439add2a1b453aae67808c09bc830f8eb
I alter a handful of foreign function signatures to accept or return a
_symbol
type. C represents these as Strings (char *
more
precisely) but Racket will transform them into interned symbols.
725d6ee7f3e5c7fe06f3531fe4c014bf9387de8a
At this point, I stumble across something in the Racket FFI docs that show that I can actually alter the definition of some of these C functions. So that:
(define-gir g_base_info_get_name (_fun _gi-base-info -> _string))
Can be renamed in Racket but refer to the same function like so:
(define-gir gi-base-name (_fun _gi-base-info -> _string)
#:c-id g_base_info_get_name)
Before, I was creating my own Racket functions that just wrapped these C functions. I don’t need those wrappers at all! I’m really impressed with the flexibility that Racket’s FFI offers.
aadb78788439577bdef21b019a8cd266fa0c859a
This flexibility allows me to update the _gi-base-info
base
type. Instead of just an empty pointer value, I can do some
intelligent conversions here. Now, whenever a C function returns a
_gi-base-info
type, Racket will unwrap that pointer into the
appropriate struct.
Here’s where the wheels fell off a little bit. Let’s say I have a C
function that I’ve wrapped with GIR and it returns a pointer to a C
Struct. What do I unwrap that struct into? I know what fields that
struct has, what methods it can call, its name… I tried to make
a new (Racket) struct type on the fly, but that’s
not quite right. I think I have to turn to Macros here so that
whenever a Registered Type is introspected, it creates definitions for
instances of that type for Racket. Alternatively I can create a
struct-instance
struct that holds the details, but that API is less
than ideal. It’s driving me a bit mad.
Toot me on Mastodon if you have some thoughts or suggestions.
– Mark