lua-users home
lua-l archive

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


> 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

Maybe you may want to add yet another option:

   -- Explicit table given: return that table with all (named) properties.
   local st = apr.stat(path, t)
   assert(st == t)
   print(st.size, st.mtime, ...)

The slowest part of returning tables is table creation. Reusing a table
cuts that cost.

-- Roberto