lua-users home
lua-l archive

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

Lua has something like C's sprintf, i.e. string.format, but
not like C's sscanf.  
1. Surely someone has published the Lua patterns that match valid 
   signed and unsigned integers, and F-formatted and E-formatted floats? 
2. With the aid of those, I think I can mimic sscanf by exploiting the
   unused %A to %Z syntax space in string.match.  I make a table called
   _format such that _format.E is the pattern that captures E-format,
   etc. Then

getmetatable("").__call = function (string,format)
  for f,p in pairs(_format) do format = format:gsub('%%'..f,p) end
  print(format); return string:match(format)

allows me to say e.g.

line = '1.2e2 3.1416'
x,y = line('%E%s+%F')

I would like to say line:scan but assigning to getmetatable("").scan
causes no error but line:scan is still nil.