lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Walter Cruz wrote:
Hi all. I'm using lua package from Debian, (I'm using unstable)

But there's something strange. That little script:

_______
x = "Walter é"
print(x)
t={}
for word in string.gfind(x, "%w+") do
    table.insert(t,word)
end

table.foreach(t,print)
___________

returns :
_____
Walter é
1       Walter
_______

The accented char is losted. I have downloaded lua 5.1 beta and compiled it, but the behaviour is the same.

I don't know what is causing that :(

That's simple. By default, your locale is probably "C", so it doesn't see high Ascii as part of word.

Just put os.setlocale("fra_fra", "ctype") at the start of your code, and it will work.

Note 1: As a French, I used a French locale, but of course, you may want to use another language suited to your needs.

Note 2: testing this on Windows, I used the fra_fra locale, specific to Microsoft, but on Debian and other "sane" systems, you may want to use fr_fr (or es, or pt_br or whatever).

I tried a bit more: fr_fr doesn't work for me, but fr is OK.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --