[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bug in lua lexer
- From: Glenn Maynard <glenn@...>
- Date: Tue, 6 Dec 2005 17:02:24 -0500
On Mon, Dec 05, 2005 at 01:30:38PM -0500, John Passaniti wrote:
> Antero Vipunen wrote:
> >Lua lexer treats dot `.' as separator. But relies (by default) on
> >strtod() for converting, and thus if your ``local'' separator is `,',
> >you are unable to compile the following sample program:
I can think of four solutions, and they're all ugly:
#1: Lua rolls its own conversion. Bloats the code, but can be omitted
on embedded platforms where strtod() will do what's expected.
#2: Figure out the locale separator, and adjust strings being parsed.
sprintf(s, "%f", 1.0f); s[1];
That may mean making a copy of the string to replace into, but only
if s[1] != '.'. The result could be cached in a static (to avoid an
sprintf() for every call), but that would break if the locale changes.
#3: Say "it's up to the application to handle setting LC_NUMERIC to a locale
whose separator is '.'". That's bad. It might be a library using Lua, in
which case the requirement infects other libraries. It may be very
difficult for an application to arrange for it to be safe to temporarily
set LC_NUMERIC. Lua can parse during normal execution, so in the general
case this would have to be done for all Lua execution, not just parsing.
Finally, it's wrong; Lua code might actually want to use LC_NUMERIC with
locale separators.
#4: Call setlocale() to set LC_NUMERIC to "C" during lexing. Libraries
shouldn't touch the locale, since it's not threadsafe, and it's nonportable.
I think #1 and #2 are reasonable, and #3 and #4 aren't. Any better options?
--
Glenn Maynard