lua-users home
lua-l archive

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


2015-01-16 2:58 GMT+02:00 Jorge <xxopxe@gmail.com>:

> read() is not not supposed to read *anything*, only *values*. When it
> returns nil, it isn't retuning anything of what you wanted to get from the
> call: it failed.

file:read() is a beautiful function, a marvellous example of the
pragmatism that characterizes Lua: ite reads mainly raw bytes,
optionally delimited by end-of line, but can read a specified quantity
of numbers delimited by whitespace.

But I'm still missing an inverse to string.format, the way that
string.unpack is an inverse to string.pack.

> fmt = "n=%3i x=%6.3g"
> s = fmt:format(10,6.35762); s
> fmt:scan(s)
10    6.36

I suspect it is not as simple as making an API to C's sscanf,
dropping field length modifiers, otherwise we would have had
it already.