lua-users home
lua-l archive

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


Hi,

Peter Odding wrote:
> My current implementation, 
> apr.stat(path, what), has two modes: if just one property is requested, 
> this is the property returned. More than one property means a table is 
> returned.

May I suggest a different API, giving you the best of both worlds:

  -- No property given: return table with all (named) properties.
  local st = apr.stat(path)
  print(st.size, st.mtime, ...)

  -- Individual properties given: use multiple return values.
  local size, mtime = apr.stat(path, "size", "mtime")
  if size > 0 and mtime ~= prev_mtime then ... end

  if apr.stat(path, "type") == "directory" then ... end

> *Microseconds*
> JG> i like fractional seconds.  i.e.  1.0 = 1 sec, 0.001 = 1msec, 
> 0.000001 = 1usec
> AQ> Use fractional seconds.
> RL> I like seconds.
> 
> Good, my preference as well. Thank you all!

Well, Lua can be compiled with an integer number type, e.g. for
embedded platforms. Sub-second timing seems relevant for embedded
platforms (except for the file APIs maybe).

So you might want to return two numbers (seconds, microseconds)
or a table or a userdata type in this case. But of course this
will break portability with Lua installations using doubles or
floats.

I don't see a clean solution. Maybe apply YAGNI and wait until
someone complains (and let'em explain what they really need).

Bye,
     Mike