I'm reading the Lua reference manual, and it talks about "embedded zeros", symbolized by "\0".
When I try to see it in the Lua console, it prints nothing meaningful:
> print "a \0 b"
a
So, what's this "embedded zero"?
Every character has an internal numeric representation, such as \97 for 'a'. A character with code \0 does not represent any visible character but is used as a terminator in C and other programming languages.
The manual wants to make it clear that a '\0' is not a terminator in Lua. It also means that you can load arbitrary bytes into a string (image, audio, video, native code, etc.) and you do not risk having it truncated at the first '\0' by some library function (which could happen in C if you use string-related functions).
\0
is just a byte with the value zero, it doesn't need any fancy name. Lua strings are just byte strings that keep track of their length, so they may contain any byte values, zero included. Some functions treat these byte strings as if they were C strings that terminate with \0
, apparently print
does this.
This means that in lua, #s
(string length) is O(1) vs. O(n) for C strings. And the application may use lua strings for any byte streams, for example UTF-16 encoded text or binary file contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With