• Status Closed
  • Percent Complete
  • Task Type Patches
  • Category Plugins
  • Assigned To No-one
  • Operating System All players
  • Severity Low
  • Priority Very Low
  • Reported Version Daily build (which?)
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: Rockbox
Opened by funman - 2010-06-03
Last edited by funman - 2010-06-18

FS#11347 - *dir LUA functions

LUA doesn’t implement any directory functions because those aren’t in ANSI C

There is an implementation on with :

attributes (filepath [, attributename]) (stat())
chdir (path)
currentdir () (getcwd)
dir (path) (readdir() iterator)
lock (fh, mode) ?
lfs.lock_dir (path) ?
mkdir (path)
rmdir (path)
setmode (filepath, mode) (TEXT/BINARY)
symlinkattributes (filepath [, attributename]) (lstat())
touch (filepath [, atime [, mtime]])
unlock (fh) ?

I only took the code for mkdir/rmdir and the directory iterator

The iterator returns 2 arguments: string (path) and bool (is directory), while the original code only returned a string relied on attributes/stat() to know if it was a directory.

It’s a new “luadir” module although I think it could be in rocklib
Tested in sim and target (fuzev1)

Closed by  funman
2010-06-18 13:11
Reason for closing:  Accepted
Additional comments about closing:   Warning: Undefined array key "typography" in /home/rockbox/flyspray/plugins/dokuwiki/inc/parserutils.php on line 371 Warning: Undefined array key "camelcase" in /home/rockbox/flyspray/plugins/dokuwiki/inc/parserutils.php on line 407


correct suggested return value mapping: 0 → true, non 0 → false

Looks good.

* You can #include “rocklibc.h” for errno (and remove the #include <errno.h>)
* I’d prefer a #define LUA_(LUA)DIRLIBNAME luaopen_luadir in luadir.h for consistency
* Perhaps rb→rmdir and rb→mkdir should be added to forbidden_functions in

Shouldn’t you return 1 in make_dir() and remove_dir() on failure? You’re only pushing one variable on the stack.

I’d prefer always returning a boolean instead of sometimes nil in make_dir() and remove_dir(), this simplifies error checking in Lua scripts.

- #include “rockblibc.h” for errno
- use a define for module entry
- I don’t remember what the does :/ can you figure if it’s needed at all?

I removed the push of an error string in make_dir/remove_dir but forgot to adjust return number, both return 1 now

Also I’m not sure of which meaning should the boolean return value have (false == not success; or false == 0 == success like in C)
This version returns true if the function succeeded (so the opposite of C function retval)

Hmm, the attachment gives a ‘file does not exist anymore’ error for me.. Flyspray bug?

I’d go with a 0→true, nonzero→false mapping (not sure what the original luafs did?). automatically generates wrappers from plugin.h, so if mkdir and rmdir wouldn’t be removed, there’d be 2 ways to call them.

Sorry I did upload an incomplete patch and replaced it almost just after hoping you wouldn’t be so fast ;)

About mkdir / rmdir I didn’t know they were accessible from lua already, I only really needed directory iterator and left mkdir/rmdir in the patch because they were present in luafilesystem and usable in rockbox (unlike functions using *stat() / symlinks etc..)

Perhaps then this patch should only contain the iterator?

I prefer mkdir/rmdir being accesible from luadir instead of rb.

* I made a mistake, LUA_DIRLIBNAME should be defined to “luadir”, not luaopen_luadir :) (you could also use this in luaopen_luadir())
* The line “lua_pushboolean (L, entry→attribute & ATTR_DIRECTORY);” isn’t aligned properly
* You can remove #define errno *rb→errno, that’s what #include “rocklibc.h” is for (eventually the errno used in Lua should be replace with *rb→errno)

This one also removes tabs

Shouldn’t that be !rb→mkdir(path) and !rb→rmdir(path)?

Apart from that it looks OK, are you going to commit it?


Available keyboard shortcuts


Task Details

Task Editing