lua-users home
lua-l archive

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

Sylvain Fabre wrote:
>  We are also evaluating luajit and we get a strange error each time
> we deal with a float (ie like 3.14116) : we get a 'Malformed number
> ...' error.
> In the main core of the program embedding lua, we call the
> setlocale(LC_ALL, "C"); but it does not seem to change anything.
> Even calling the os.setlocale from the lua script does not change
> this.

Maybe some other component is changing the locale (readline or
GTK+ are often the culprits). Or something is setting LC_NUMERIC,
which overrides LC_ALL.

> But i we set the value 3,14116 (ie "french-like"), then the number
> is accepted.

Well, this would still break loadfile() et al.

> Any idea to fix this ? After a look in the luajit code, i was no
> table to find where the decimal point is detected (or not).

This is really deep inside libc in strtod(), which can neither be
easily replaced, nor easily convinced to ignore the locale. Lua
has some NLS-specific workaround, but I had to remove these from
the codebase to reduce dependencies (not every embedded OS/libc
supports the NLS APIs and structs).

Try os.setlocale("C", "numeric") or the equivalent C call after
all other libraries have been initialized.