I’ve been putting this question aside for a while, but I need it addressed now: is there a way to tell codea to take into account accentuated characters? Every time I tried drawing a string with accentuated characters, I got gibberish. When I tried putting the string in a table, the characters are removed.
In a W.I.P. encryption program I’m working on I get a similar problem. I coded in UTF-8 support for the encryption algorithm, but parameter.text() doesn’t seem to acknowledge accented characters.
@Rodolphe what are you trying to do? Are you trying to print accented characters on the screen or to use them as variable names. The former is easy, the latter is probably a bad idea.
function setup()
mots = {}
t = "de l'hôpital au musée"
l = string.len(t)
i = 0
j = 0
for word in string.gmatch(t, "%a+") do
i = i + 1
table.insert(mots,i,word)
end
for i,v in pairs(mots) do
print(v)
end
end
j = 0
k = 0
l = 0
function draw()
k = k + 1
l = l + 1
m = mots[j+1]
background(36, 57, 90, 255)
fontSize(40)
font("Georgia")
fill(255, 255, 255, 255)
if k == 10 then
k = 0
if j < #mots then
j = j + 1
else
m = "-"
end
end
text(m,WIDTH/2,HEIGHT/2)
end
The problem there is that lua works byte-wise so its patterns aren’t set up to deal with unicode (or non-ascii) characters. Thus the %a is matching bytes which are letters and this doesn’t include the accented characters because these are two bytes (or more).
One option is to use a UTF8 library. I have one which is in this gist as the file utf8.lua. This allows you to iterate over characters rather than bytes.
For the specific code that you’ve posted then there is a simpler solution. If you change %a to %S then it works. This is because %S matches a non-space byte and that includes the bytes in the non-ascii letters.