This is the bug/patch tracker for Rockbox. Click here for more information.
Quick links: Bugs · Patches · Rockbox frontpage
FS#11347 - *dir LUA functions
Attached to Project:
Rockbox
Opened by Rafaël Carré (funman) - Thursday, 03 June 2010, 02:37 GMT+2
Last edited by Rafaël Carré (funman) - Friday, 18 June 2010, 15:11 GMT+2
Opened by Rafaël Carré (funman) - Thursday, 03 June 2010, 02:37 GMT+2
Last edited by Rafaël Carré (funman) - Friday, 18 June 2010, 15:11 GMT+2
|
DetailsLUA doesn't implement any directory functions because those aren't in ANSI C
There is an implementation on http://www.keplerproject.org/luafilesystem 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) |
This task depends upon
Closed by Rafaël Carré (funman)
Friday, 18 June 2010, 15:11 GMT+2
Reason for closing: Accepted
Additional comments about closing: r26913
correct suggested return value mapping: 0 -> true, non 0 -> false
Friday, 18 June 2010, 15:11 GMT+2
Reason for closing: Accepted
Additional comments about closing: r26913
correct suggested return value mapping: 0 -> true, non 0 -> false
* 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 rocklib_aux.pl
EDIT:
Shouldn't you return 1 in make_dir() and remove_dir() on failure? You're only pushing one variable on the stack.
EDIT2:
I'd prefer always returning a boolean instead of sometimes nil in make_dir() and remove_dir(), this simplifies error checking in Lua scripts.
- use a define for module entry
- I don't remember what the rockblib_aux.pl 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)
I'd go with a 0->true, nonzero->false mapping (not sure what the original luafs did?).
Rocklib_aux.pl automatically generates wrappers from plugin.h, so if mkdir and rmdir wouldn't be removed, there'd be 2 ways to call them.
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 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)
Apart from that it looks OK, are you going to commit it?