lua-users home
lua-l archive

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


On Thu, Jan 25, 2007 at 10:27:54PM -0800, Matthew Armstrong wrote:
> I ran across this item:
> Floating point numbers locale bug. Lua needs some dirty hacks to keep your
> scripts working when using floating point numbers.

The only thing I can think of is the usual LC_NUMERIC business.  If
you use libc functions to convert between floats and strings, they'll
use the decimal separator specified by LC_NUMERIC.  In some locales,
like pl_PL, the separator is a comma.

This wiki item sounds more like someone bitten by not understanding
LC_NUMERIC and deciding to blame Lua for it.  :)

When you call setlocale(), you should only set the locale types that
your code and libraries are designed to handle.  Many programs will
misbehave in various ways due to LC_NUMERIC; don't set it, or set it to
"C", unless you're prepared to deal with the behavior of basic string
functions changing.  (The "dirty hacks" may be the practice of changing
LC_NUMERIC back and forth.  Only do that if you really do need it; it's
not threadsafe.)

This is really an effect of C's awful localization API--there should be
a way to get a handle to a locale set, and alternate functions for
sscanf, printf, strtod, etc. that take a handle as an additional parameter.

> On a related note, how easy is it to adapt lua to unicode?

You can pass UTF-8 strings to Lua without any changes.  There's no
API to manipulate them, except as raw strings, but if you need
them they're easy to add.

Lua 5.1.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> a = "ÀÁÂÃÄ";
> print(a);
ÀÁÂÃÄ
> print(#a);
10

-- 
Glenn Maynard