Page 1 of 1

what does "appending keystrokes" mean?

Posted: Wed Sep 24, 2014 6:42 pm
by BozoDel
I'm not sure I get this:
In version 0.8.0 and older, love.graphics.print stops at the first '\0' (null) character. This can bite you if you are appending keystrokes to form your string, as some of those are multi-byte unicode characters which will likely contain null bytes.
It's in [wiki]love.graphics.print[/wiki]. In order to translate "appending keystrokes" most appropriately, I need to know how it works. Does it have to do with [wiki]love.textinput[/wiki]?

I'm also curious about the bug itself, was it a problem with Lua handling unicode, or with the way keystrokes were stored?

Re: what does "appending keystrokes" mean?

Posted: Wed Sep 24, 2014 7:26 pm
by DaedalusYoung
Appending keystrokes means you are changing a string, depending on user input. If a user enters a letter, you then append this letter to the string.

It doesn't have anything to do with love.textinput, because that didn't exist in 0.8.0 yet, but even if it did, it wouldn't be, since this was a print bug, not a textinput bug.

I don't know the details about the bug though.

Re: what does "appending keystrokes" mean?

Posted: Thu Sep 25, 2014 4:30 pm
by BozoDel
Hm, but I think the user input has to come through love.textinput, otherwise there's no unicode support. I think that's it.

Any translation I can find for keystroke sounds weird, but in that case, keystroke is synonym with user input, so I can translate it more freely.

Re: what does "appending keystrokes" mean?

Posted: Thu Sep 25, 2014 6:44 pm
by DaedalusYoung
In previous versions, love.keypressed's second argument was the unicode number of the key pressed, so there was unicode support in 0.8.0. I guess some keyboards, like Cyrillic, can send a multi-byte character from a single key press.

Re: what does "appending keystrokes" mean?

Posted: Fri Sep 26, 2014 12:21 pm
by markgo
In previous versions of Love (0.8 and older in this case), many Love text functions did not properly support UTF-8 encoded strings. The old love.keypressed receives a unicode number as its second argument. That job is now delegated to love.textinput (receives a string instead). The wiki is just warning you that if you built strings like:

Code: Select all

function love.keypressed(k,u)
  text = text .. UTF8numberToString(u)
end
The text will not be printed correctly because the text can contain null bytes from multi byte UTF-8 characters.