Implementing autosave in Spatterlight

I’d like to implement autosave for Spatterlight, at least for the Glulxe interpreter, but I’m having a harder time with this than with any of the other features I’ve added so far.

I’ve read Zarf’s discourse on interpreter autosave, and the problem seems clear enough.

Spatterlight neatly splits into three distinct parts: the interpreter, the Glk implementation and the Objective-C GUI, and an autosave must include the state of all three of these parts. The first one is basically a standard save file with some extra data, and the third can use the Cocoa NSCoder interface, just like iOSGlk. It is the second one, the Glk library implementation, that is giving me a hard time.

Just like Gargoyle, Spatterlight uses a modified Cheapglk library written in C, with no support for serializing its state. I guess the obvious way forward would be to use a C serialization library, such as protobuf-c or FlatBuffers, or perhaps it would even be possible to output the GlkOte JSON data format with something like Frozen? I don’t have a lot of C experience and have never done anything like this, so I’m a bit unsure which one to choose and how to go about it.

I suppose an alternative would be to transplant the necessary parts of the iOSGlulxe Objective-C Glk library and its autosave code and simply copy all the needed state information from the existing C structs to a new Obj-C object and back. Perhaps this would require less work, but it would be a pretty inefficient hack.

Has anyone tried to do anything like this or thought about it? Any suggestions at all would be helpful at this point.