Serializing Lua data, part IV

The last Lua [1] data type to serialize—threads.

It's more difficult than serializing a function [2], but probably a bit easier than serializing a userdata [3]. Possibly. I haven't actually tried it yet, as it can't be done through Lua.

The issue is that there's no API (Application Programming Interface) to manipulate the callstack, and without that, you're stuck with dipping into the internals of Lua via C, which explains why most existing serialization modules [4] haven't bothered with threads. And the only one (pluto) [5] that has attempted it, only works for Lua 5.1.

And that's why I didn't bother with it, either.

* * * * *

It was an interesting experience to write a serialization library for Lua. It became apparent exactly why so many don't bother with functions, userdata or threads—they're not easy to universally support.

I also skipped out on supporting metatables [6], not because they're hard, but because I just didn't get around to it [7]. I also think that CBOR (Concise Binary Object Representation) [8] makes for a good serialization format. The primitives are well chosen, it's a consistent format and the semantic tagging makes it easy to extend.

And like I said earlier, I had fun playing around with this stuff.

[1] http://www.lua.org/

[2] /boston/2015/03/31.1

[3] /boston/2015/04/01.2

[4] http://lua-users.org/wiki/TableSerialization

[5] http://luaforge.net/projects/pluto/

[6] http://www.lua.org/manual/5.3/manual.html#2.4

[7] https://www.amazon.com/exec/obidos/ASIN/B008OVQZR4/conmanlaborat-20

[8] https://www.ietf.org/rfc/rfc7049.txt

Gemini Mention this post

Contact the author