In a second major milestone for Bedquilt following last month’s release of Wasm2Glulx, I have uploaded an alpha release of the bedquilt-io
crate. This is a safe, idiomatic Rust API which wraps Glk and other system facilities that are available from within Glulx.
bedquilt-io
’s API looks rather different from Glk itself. The most prominent difference is that it wraps an async executor around Glk’s event loop. This means that, even though Glulx itself is strictly single-threaded, you can now program in concurrent style with lightweight, cooperative multitasking. This should make it much more ergonomic to deal with things like timers, sound notifications, and window redraw/rearrange events, because you can spawn an independent task to handle them rather than mixing all these concerns into the same event loop that handles user input.
Unicode handling in bedquilt-io
is much smoother than it is in Glk. As far as API users are concerned, everything is always UTF-8, and uses Rust’s standard String
type. Conversion to/from Latin-1 and UTF-32 happens entirely under the hood, using Glk’s Unicode functions if the gestalt is available and transparently falling back to the Latin-1 functions if not. For file IO, everything is always opened in binary mode so that Glk stays out of the encoding business altogether.
Some differences were born more out of necessity than convenience. For example, the fact that, in Glk, closing one of a pair window’s two children also closes the pair window, really doesn’t play well with Rust’s borrow checker. In order to maintain a safe API, I dealt with this by never providing any direct handle to a pair window. Instead, you can operate on pair windows (to split or rearrange them) by calling a method on one of their descendants and supplying an nth_ancestor
argument.
This is very much an alpha release, which means don’t expect very much out of this code just yet; it has a lot of features that I haven’t tested at all yet. The artifact of interest at this point should be the API documentation, not the implementation. Bugs will get worked out in the process of building on top of it as I implement Bedquilt’s parser and world model.
Before I get started on either of those things, though, the next thing I plan to work on is a cargo plugin to support Bedquilt development workflows. Instead of running one command to build a WASM module, another to invoke Wasm2Glulx, and a third to create a Blorb file, you’ll be able to just run cargo bedquilt build
. Of course there will also be cargo bedquilt init
, run
, test
, and so forth.