[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to extract a floating point number locale-independantly
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 26 Apr 2016 09:51:47 -0300
> This means was suprising to me and has a number of consequences:
> - Using a seperator such as "," is impossible in the first place as:
> [...]
Using a separator such as "," is impossible in the first place because
print(1,0) already has a meaning in Lua. It would a be a big mess if
the lexer respected locales, and the mess has nothing to do with the
implementation.
> - If running in a locale where '.' is not the decimal separator,
> parsing lua could result in *many* calls to `localeconv`.
I am not sure what you count as "many", but the code seems to call
`localeconv` once per chunk (unless you change locales during
parsing, in which case is plus one per change).
> Fixing lua_str2number to be locale independent will:
> - allow the `trydecpoint` hack to be removed from llex.c
> - fix tonumber() to *not* be locale dependant.
One is false; as you said, we would have to fall back to it in C89.
Two is dubious; this "fix" may affect people that count on this
behavior.
Couldn't your library change the locale whean reading numbers and
then convert it back to what it was when done?
-- Roberto