lua-users home
lua-l archive

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


Mike Spencer wrote:

>but i would also like to know how to parse floating point using lex

The code below will split the line into the fields you want.
To test whether the value is a valid number, use tonumber.

 while true do
  local line=io.read()
  if line==nil then break end
  local ok,_,name,value=string.find(line,"%s*(%S+)%s*=%s*(%S+)%s*")
  if ok then print(name,value) else error("bad line: "..line) end
 end

--lhf