"Library-style" interpreter (for use in Godot/another engine)?

Hi! I would really like to be able to use the output of Inform 7 in Godot, in a manner similar to Ink (i.e. sending text input to the Inform 7 game, getting simple text back as output, and choosing how to display that text in Godot, presumably alongside fancy graphics).

Unfortunately, I’m having trouble finding an existing interpreter (for either z-code or glulx) with the sort of API I want. It seems like there are tons of interpreters out there, but half of them are poorly-documented hobby projects, and more annoyingly, they mostly either are in the form of a standalone application, or expect to be combined with a Glk “library” (not really a library) to produce a standalone executable, but the Glk API really feels like it’s structured for a different use case than what I have in mind.

I just want to be able to do something like this (sorry for GDscript-ish pseudocode):

var story_data = load("path/to/story.z8 or whatever");
var story = new IFInterpreter(story_data);
...
function on_user_input_in_textbox_or_whatever():
    var input = get_user_input_somehow()
    story.send_input(input)
    // wait in a *non-blocking* way to receive string output somehow,
    //    like via a signal or callback or something

It doesn’t need to be exactly that API, but the point is, I just want to use Inform7 for the parsing and world model, sending and receiving simple text, and basically ignore any instructions from the interpreter about windows, styling, graphics, etc., because I want to define all that stuff in Godot.

Is there a way for me to do this without having to write a full “Glk library,” or full interpreter, of my own?

My current best solution would be to link glulxe with RemGlk and run that as a subprocess of Godot via OS.execute_with_pipe(), and then ignore like half the output, but this sucks because I can’t export it for web (also, more complicated to bundle/distribute and probably more likely to get flagged by antivirus). Alternately, any solution that involves compiling RemGlk to WASM, or using an existing javascript library, could be made to work in a web export but not in a non-web build or when running from the Godot editor.

I’m kinda stumped. Has anyone else found a good way to do something similar?

1 Like

You might be able to do something with the Inform->C translation. You can wire the input and output to your code. You’d have to make it async though. Also, i can’t remember whether the game is “baked into” the C output, or whether it can load a game, since i don’t think the C version supports a game file format, nor save games for that matter. Unless things have changed recently. which they might have.

The Glk API can be used for that pretty easily. There’s all sort of stuff about windows and events in there, but if you ignore all of that it’s simple text in, simple text out. The cheapglk library demonstrates this.

I realize this doesn’t solve the bundling problem.

I guess my problem is that when I look at “cheapglk,” a supposedly minimal glk implementation, and see thousands of lines of code across dozens of files, it doesn’t exactly fill me with confidence that this would be quick & simple to implement.

Copy and paste it all in? You’re not touching most of it.

If I were doing this in a C/C++ engine, I’d have the game start up a background thread and adapt cheapglk’s main.c to be the thread function. Then modify the glk_select() function in cgmisc.c so that instead of calling fgets(), it blocks and waits for the main thread to throw it an input line. Just about everything else can remain as it is.

2 Likes