lua-users home
lua-l archive

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


On Tuesday 06 December 2005 23.02, Glenn Maynard wrote:
> 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.

I decided to go this way from the start with EEL, part because of this 
issue (seen way too much of this with Delphi in the past...), and 
part because I wanted solid, portable support for base-n and base-n 
floating point numbers.

The code is found in e_bio.c, and you're free to grab it if it's of 
any use. (Nevermind the LGPL - I'm fine with the Lua license.) Works 
Here(TM), but no warranty. It's around 220 lines of C and expects a 
getchar() like interface for reading input.


As to "ugly", I consider this part of the lexer, just like skipping 
whitespace, extracting operators or parsing string literals. Of 
course, it would seem like a good idea to use standard C library 
functions when they're there - but these functions are intended for 
user interfaces! (That's why they care about locales at all.) The 
number literal format of a language is part of the language 
definition, so I think it's pretty logical to make it part of the 
lexer.


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---