[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lex parsing floating point values
- From: "Peter Loveday" <peter@...>
- Date: Wed, 28 May 2003 10:25:53 -0400
Is this your own file format? If so, I'd strongly suggest making the data
file a Lua program. Then to read it, you just load it and execute it (in a
protected way of course, to deal with errors).
Love, Light and Peace,
- Peter Loveday
Director of Development, eyeon Software
----- Original Message -----
From: "Mike Spencer" <mike@creative-asylum.com>
To: <lua@bazar2.conectiva.com.br>
Sent: Wednesday, May 28, 2003 9:09 AM
Subject: lex parsing floating point values
> what is the best way to parse floating point values from an external file?
>
> you will have to forgive me, i am new to Lua and i am not familiar with
lex
> either
>
> my test data consists of an integer and 2 float values:
>
> Particles = 100
> Emitter.delay = 0.001
> Emitter.delayFuzz = 0
>
> i would like to read in floats that could be in various formats:
> e.g.
> 1
> 1.0
> .01
> -1
> -.01
> -1.68587e-007
>
> this is the Lua code i'm trying to use to parse the file, but as i say i
> don't know lex well enough:
>
> readfrom( 'export.txt' )
> file = read( "*a" )
>
> particle = {}
> particle.emitter = {}
>
> i = 1
> i, j = strfind( file, "Particles =" )
> i, j, particle.particles = strfind( file, "(%d+)", j + 1 )
> dprintf( '%i\n', particle.particles )
>
> i, j = strfind( file, "Emitter.delay =", j + 1 )
> i, j, particle.emitter.delay = strfind( file, "(%d%.%e)", j + 1 )
> dprintf( '%i %i\n', i, j )
> dprintf( '%f\n', particle.emitter.delay )
>
> i, j = strfind( file, "Emitter.delayFuzz =", j + 1 )
> i, j, particle.emitter.delayFuzz = strfind( file, "([0-9.e])", j + 1 )
> dprintf( '%f\n', particle.emitter.delayFuzz )
>
> readfrom()
>
> hope someone can help me, thanks
>