LuaPlayer "bug".

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Teggles
Posts: 27
Joined: Mon Jan 16, 2006 9:30 am

LuaPlayer "bug".

Post by Teggles »

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.
User avatar
Drakonite
Site Admin
Posts: 989
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

It's supposed to do that... null termination :P
Shoot Pixels Not People!
Makeshift Development
Teggles
Posts: 27
Joined: Mon Jan 16, 2006 9:30 am

Post by Teggles »

*shakes fist*

It may be, but I can't avoid it without modifying the string.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Take a look at the serial port example in Lua Player for a full terminal simulation with newline and scrolling.
User avatar
Drakonite
Site Admin
Posts: 989
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

You'll either have to modify the string or treat the data differently.
Shoot Pixels Not People!
Makeshift Development
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

in c the \0 is to signify the end of the entire string. LUA is useing the same format.
SSpeare
Posts: 63
Joined: Tue May 23, 2006 11:45 pm
Contact:

Post by SSpeare »

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.
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

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."
Teggles
Posts: 27
Joined: Mon Jan 16, 2006 9:30 am

Post by Teggles »

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.
Post Reply