Whenever the character "\0" is in a string, and it is displayed, nothing after it is displayed. For example:
local s = "first" .. "\0" .. "second"
screen:print(0, 0, "s", Color.new(0, 0, 0))
It will only display "first".
I haven't actually tested the above. However, I have io.read files with the \0 character into a variable, and the same effect occurs. I am not sure if the bug is with reading files or displaying strings.
I'm sure I'll get a snarky reply saying it's supposed to do that, but the newline character doesn't do what it's supposed to, making it a stupid thing to say.
LuaPlayer "bug".
Moderators: Shine, Insert_witty_name
Take a look at the serial port example in Lua Player for a full terminal simulation with newline and scrolling.
You'll either have to modify the string or treat the data differently.
Shoot Pixels Not People!
Makeshift Development
Makeshift Development
Actually, Lua uses 32-bit clean strings. It is legal to put '\0' character into a Lua string. It will not terminate the string and it will still report the correct string length. The problem occurs when you send that string over to C and some C code assumes that '\0' terminates the string.romero126 wrote:in c the \0 is to signify the end of the entire string. LUA is useing the same format.
In the end, any string code should probably assume that '\0' will terminate the string, even though in Lua it actually won't.
SSphear you are absolutly right '\0' is used by c programmers as a char[] terminator to avoid any errors during output. The length still remains the same. Even the string behind char[] remains the same.
While the data is not lost. char[] simply overwrites the data up to a certain level. What that means is that you can also use \0 in c/c++ and it have the same result. However most interpreters use the \0 as an endall for their code.
When you work with strings in c/c++ this gets thrown out since the system uses a allocated char[] based array which is static to the total size of the string. (IE the string is dynamic in size) So when you call string.len (i forget the actual command) it calls the allocated memory for that string. Instead of the first \0.
Simple yet complicated. Hince the previous simplistic comment
"in c the \0 is to signify the end of the entire string. LUA is useing the same format."
While the data is not lost. char[] simply overwrites the data up to a certain level. What that means is that you can also use \0 in c/c++ and it have the same result. However most interpreters use the \0 as an endall for their code.
When you work with strings in c/c++ this gets thrown out since the system uses a allocated char[] based array which is static to the total size of the string. (IE the string is dynamic in size) So when you call string.len (i forget the actual command) it calls the allocated memory for that string. Instead of the first \0.
Simple yet complicated. Hince the previous simplistic comment
"in c the \0 is to signify the end of the entire string. LUA is useing the same format."