[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Locale problem
- From: David Jones <drj@...>
- Date: Fri, 6 Feb 2004 10:40:04 +0000
On Feb 05, 2004, at 17:23, Stoil Todorov wrote:
First, thanks for support!:-)
Second I still have problems with locals:-(
In code, I call os.setlocale("C", "numeric") in first
line, because I use data with decimal point, but I get
error message: "Syntax error during pre-compilation.:
[string "Run_Code"]:144: malformed number near `0.05'"
How can I avoid this?
I'm not entirely sure, but I think the following is what is happening:
You need to make sure that the locale is changed before the Lua chunk
is compiled.
This is probably best achieved by calling
setlocale(LC_NUMERIC, "C")
in your C program before loading/compiling/running any Lua code.
You'll need to #include <locale.h> as well. Early on in main() is
probably a good place.
If you must do it in Lua then you need to execute
os.setlocale('c', 'numeric')
in a separate chunk to the rest of your code. I don't how your Lua
code and your host application are organised, but putting that in a
separate file or string that is executed before other Lua code should
work.
It doesn't work to put os.setlocale('c', 'numeric') in the Lua file
that you want to use decimal points in. That's because the file has
been lexed and compiler before the locale has changed, so the lexer -
the part that recognises numbers - will use the old locale. I should
have spotted that before.
Hope this helps.
David Jones