lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> No, it's not weird. It would only get weird if there was a string of
> negative length, an "imaginary" string so to say :). And even then it might
> have its merits.

And I could even imagine that the length of a string not being an
integer number.
For example, if #s == 2.125, that would mean there are 17 meaningful
bits in it !
Often, when dealing with bit stream, you have to pad the last byte
with extra bits.
It could be interesting if in Lua you could add individual bits to a string !

That said, I do not know for now what is a string of length 3.1416...

> I don't think so, because an empty string ( its memory ) still contains the NULL
> character, correct? So, it has the length of 0, but it still is a string.

Internally, Lua adds an extra zero byte at the end of any string (so
also for  the empty string), but this is only to simplify interfacing
with C host code. Lua by itself never use that zero terminating byte
nor count it in the length ; it stores the length of a string together
with the pointer and the hash value.