I've punted on adding a buffer type to luvit since the string type of lua is binary safe. However we're finding more and more we need a mutable or at least appendable buffer type.
If lua had constrings (an implementation detail that makes string concat very fast) I would just say to build the string a byte or more at a time, but it doesn't and concatenating strings can be very expensive.
Some lua code gets around this by using arrays of strings (remember browsers used to have the same issue before V8 friends implemented constrings)
I don't want to depend on FFI like we currently do with the beta buffer type since that locks us into using luajit. Yes luajit will stay the default engine (it's in the name after all). But I want the flexibility to use vanilla lua if I want to.
What should our buffer type look like?
My two cases are building a binary string a piece at a time. This means adding 4 bytes for a number, 8 for a larger number, n bytes for a string, etc..
The other case is actually changing values in place of a buffer. I don't know as many use cases for this, but I'm sure they exists. (I used mutable buffers in node to implement an in-memory database that was GC friendly)
Ideas?