lua-users home
lua-l archive

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


>what is the best way to parse floating point values from an external file?
>
>Particles = 100
>Emitter.delay = 0.001
>Emitter.delayFuzz = 0

Why parse this by hand at all? This file is valid Lua file: let Lua do
the work for you with lua_dofile. You'll have to create Emitter first.
Something like this (in Lua 5.0, but similar code works for Lua 4.0):

 local particle = {Emitter={}}
 local f=assert(loadfile("yourfile"))
 setfenv(f,particle)
 f()
 print(particle.Particles)
 print(particle.Emitter.delay)
 print(particle.Emitter.delayFuzz)

If you don't mind polutting the global space then dofile("yourfile") suffices.
--lhf