Port string.pack and string.unpack from Lua 5.3 to RBX.Lua

As a Roblox developer, it is currently too hard to save player data in a binary format.

However, string.pack can solve that as it lets you convert things like floats, integers or shorts and more to binary strings. You can see what it does here.

This would help store high amounts of data without hitting the DataStore size limitations.

10 Likes

This would be extremely useful. Datastores don’t support binary data though:

Lua strings are very good at packing binary data, it’s often disappointing that the Roblox API treats them like ordinary non-Lua strings.

4 Likes

Although, it would still decrease save size after conversion to Base64/128.

2 Likes

Storing player data in binary format is almost always unnecessary. Unless you have some type of UGC with no defined upper limit you’re probably better off just saving plain dictionaries, with some simple RLE at the most.

For the longest time roblox itself was using XML for place files because it worked fine until they had to scale to millions of concurrent users.

Oh my, this still sounds fun for doing things like custom interpreters/compilers. Would help out a hell of a lot in the more obscure sides of Roblox Lua.

This may be true for most games, but I would love to see more libraries from newer versions of Lua ported over. It’s just useful.

2 Likes

Agreed. Like the bit32 library from Lua 5.2!

2 Likes

A string packed in that fashion is only guaranteed to correctly unpack on the same platform.

3 Likes

I also thought this was an absurd thing to be added to the core Lua 5.3 library. Especially with how minimal the Lua standard library is.

If we were to add this we’d have to strip out like 80% of the format options and quite likely reimplement the function entirely from scratch. I wouldn’t be surprised if you can cause crashes using this function like you can using the reference interpreter’s implementation of os.date.

I also think that introducing this function to get around datastore caps is an X/Y solution. Storing binary data in data stores shouldn’t be required.

6 Likes