In C, the printf() function (when given %s as the first format arg), will continue printing what is in memory that is either stored in a char buff[] or const char* until it hits the null terminator (\0).
In Luau however, buffer.readstring() manually has to take a number of how many bytes (since char is 1 byte wide) to read from the buffer, if you don’t know the strings length when you need to read it, it becomes difficult to know how much to read without accidentally reading garbage.
Can this feature be implemented (as an overloaded function, so existing functionality doesn’t break) so that buffer.readstring() reads memory in the buffer until a \0 is hit?
Your request does not make a whole lot of sense because you are expected to track the length of the string you are writing into the buffer.
If you are using buffers like C strings, why not use buffer.len to get the length of the buffer when you need to read the string from it?
If you are not, null-terminated strings would not reduce the amount of data you need to keep track of since you still need to know where your string(s) begin(s).
Ultimately, there is nothing stopping you from implementing that behavior yourself, but I would advise against it since it scales poorly (e.g., if you have a buffer with the max size of 1 GiB you could potentially end up reading all 1,073,741,824 bytes in order to find the null-terminator and thus the size of the string).
I don’t think this is an unreasonable request, there’s cases where reading up until a null would be useful to store bulk string data and there’s no buffer.find or similar to do this efficiently.
Though since the buffer library is part of the base Luau language, this would normally be done through a Luau RFC, not through a Roblox feature request.
Right, I was more against adding the implicit expectation that strings in the buffer would need to be null-terminated prior to using a function like buffer.readstring.
I think the approach you mentioned of adding buffer.find or similar would be a much better solution because it would cover the use case of finding sentinel values in the buffer without putting any constraints on the existing buffer functions.