Using FlatBuffers with Lua

The docs section on realtime multiplayer recommends using a binary format to send data. So I decided to go with one of the listed options - FlatBuffers. The implementation was relatively smooth up to the point where I tried to actually deserialize data that was sent from my client. After some debugging I found out, that FlatBuffers Lua implementation uses Lua 5.3, but the Nakama server only has a Lua 5.1 runtime. Specifically FlatBuffers uses the string.unpack function, which doesn’t exist in Lua 5.1 (Maybe there’s more, this is the first error I’ve run into)

According to this topic it is not trivial to upgrade Nakama to use Lua 5.3 and there are no plans to do so.

Did anyone find a workaround to use FlatBuffers with Lua? Or would I be better off just using Go (which would be a bit of a shame as I would have to rewrite all of my server-side code)?

Hey @Dumblecore welcome :wave:

You should be able to incorporate this patch for Flatbuffers runtime which adds compat with the Lua 5.1 implementation we support: https://github.com/b1nhm1nh/flatbuffers/commit/1ba3b896b99ca04983f820f50ff44fda3c13980b

The patch is a bit old but worked the last time we needed it on a project.

Hey, thank you for the help (on a sunday!)

Unfortunately the proposed fix still uses the string.unpack and string.pack functions which are not available in Lua 5.1. So I still got the same error the first time I tried:

binaryarray.lua:119: attempt to call a non-function object

The code in question:

local sunpack = string.unpack
[...]
return sunpack(fmt, s.str, pos + 1)

When I tried again to make sure I didn’t miss anything I get an error on startup saying the bit32 module wasn’t found. But it’s getting pretty late here, so I’ll try again after work tomorrow.

Thanks again!