lua-users home
lua-l archive

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


RL> Are these really too expensive to retrieve, compared with the overhead of a scripting language? Otherwise, it's probably easier all round to just retrieve all of them.

I've considered this myself and this is the approach Perl, Python and Ruby have taken. However apr_stat() also returns permissions which I represent in three tables, user, group and world.

You might want to reconsider that. It is certainly a clean interface, but it might not be particularly useful in common cases. Off the top of my head, I'd say the common cases are: checking one or two permissions,
and reporting all the permissions in some string representation.

Now, consider these possibilities:

local stat = apr.stat(filename)

if stat.perms.world.readable then ... end
-- or
if stat.worldperms:match"r" then ... end

Just a thought.

Now if someone needs just the mtime of say a 1000 files this will require 4000 tables while a 1000 lua_Number's would have sufficed. 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. This works really well for filesystem-entry-type testing, for example:

if apr.stat(path, 't') == 'directory' then ...

At the risk of entering into PHP-land, I'd suggest that
  if apr.filetype(path) == 'directory' then ...
is clearer. But I certainly wouldn't extend that to an "is_directory" boolean. :)

I don't like functions which sometimes return tables and sometimes not; that's error-prone and confusing to the user.


And I'm *certainly* not going to implement filectime/filemtime/fileatime/file_exists/file_readable/is_directory/etc.. functions like PHP has :P

Sure. Probably only a couple are useful; the rest could be extracted from the general interface which returns a table.