| View previous topic :: View next topic |
| Author |
Message |
Teggles
Joined: 16 Jan 2006 Posts: 27
|
Posted: Mon Jul 10, 2006 7:37 am Post subject: LuaPlayer "bug". |
|
|
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. |
|
| Back to top |
|
 |
Drakonite Site Admin

Joined: 17 Jan 2004 Posts: 989
|
Posted: Mon Jul 10, 2006 8:48 am Post subject: |
|
|
It's supposed to do that... null termination :P _________________ Shoot Pixels Not People!
Makeshift Development |
|
| Back to top |
|
 |
Teggles
Joined: 16 Jan 2006 Posts: 27
|
Posted: Mon Jul 10, 2006 6:10 pm Post subject: |
|
|
*shakes fist*
It may be, but I can't avoid it without modifying the string. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Jul 10, 2006 9:34 pm Post subject: |
|
|
| Take a look at the serial port example in Lua Player for a full terminal simulation with newline and scrolling. |
|
| Back to top |
|
 |
Drakonite Site Admin

Joined: 17 Jan 2004 Posts: 989
|
Posted: Tue Jul 11, 2006 6:55 am Post subject: |
|
|
You'll either have to modify the string or treat the data differently. _________________ Shoot Pixels Not People!
Makeshift Development |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Thu Jul 13, 2006 6:00 am Post subject: |
|
|
| in c the \0 is to signify the end of the entire string. LUA is useing the same format. |
|
| Back to top |
|
 |
SSpeare
Joined: 23 May 2006 Posts: 63
|
Posted: Thu Jul 13, 2006 6:13 am Post subject: |
|
|
| romero126 wrote: | | in c the \0 is to signify the end of the entire string. LUA is useing the same format. |
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.
In the end, any string code should probably assume that '\0' will terminate the string, even though in Lua it actually won't. |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Thu Jul 13, 2006 6:57 am Post subject: |
|
|
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." |
|
| Back to top |
|
 |
Teggles
Joined: 16 Jan 2006 Posts: 27
|
Posted: Thu Jul 13, 2006 4:50 pm Post subject: |
|
|
| It's a tedious matter to edit ID3v2 tags, as some have padding. I have to remove then re-insert the padding. Although that is possible and a reasonably easy task, it still seems better to at least give a setting to change how it works. I don't know. I guess I'll just put up with it. |
|
| Back to top |
|
 |
|