Changeset 555


Ignore:
Timestamp:
11/10/08 06:38:25 (5 years ago)
Author:
reyalp
Message:

+ add os.listdir to lua oslib, updated llibtst.lua

syntax t=os.listdir("name",[showall])
returns array of filenames, or nil, strerror, errno
if showall is true, t includes ".", ".." and deleted entries
NOTE except for the root directory, names ending in / will not work

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHDK/SCRIPTS/TEST/llibtst.lua

    r539 r555  
    381381end 
    382382 
     383function tlistdir(name,showall) 
     384        log('os.listdir("',tostring(name),'",',tostring(showall),'): ') 
     385        local r,msg = os.listdir(name,showall) 
     386        if r then 
     387                logok() 
     388                log("{\n") 
     389                for k,v in ipairs(r) do 
     390                        log(' ',k,'="',tostring(v),'"\n') 
     391                end 
     392                log("}\n") 
     393        else 
     394                logfail(tostring(msg)) 
     395        end 
     396        return r 
     397end 
     398 
    383399function tutime(name,mtime,atime) 
    384400        log('os.utime("',tostring(name),'",',tostring(mtime),',',tostring(atime),'): ') 
     
    431447                tstat(tdir0) 
    432448                tren(tdir0..tdat0,tdir0..tdat1) 
     449                tlistdir(tdir0) 
     450                tlistdir(tdir0,true) 
    433451-- NOTE invalid operations frequently leave the filesystem in a corrupt state 
    434452--              trename(tdir0,tdir1) 
     
    436454                trem(tdir0) --fail, not empty 
    437455                trem("A/bogus") --fail missing 
     456                tlistdir("A/bogus") -- missing 
     457                tlistdir("A/llibtst.log") -- not a directory 
    438458                tstat("A/bogus") -- fail missing 
    439459                tutime("A/bogus") -- fail missing 
  • trunk/doc/version.txt

    r554 r555  
    22 
    33version / revision / author 
     40.7.4 / #555 / reyalp 
     5+ add os.listdir to lua oslib, updated llibtst.lua 
     6  syntax t=os.listdir("name",[showall]) 
     7  returns array of filenames, or nil, strerror, errno 
     8  if showall is true, t includes ".", ".." and deleted entries 
     9  NOTE except for the root directory, names ending in / will not work 
    410 
    5110.7.3 / #554 / PhyrePhoX 
  • trunk/lib/lua/loslib.c

    r538 r555  
    247247  const char *dirname = luaL_checkstring(L, 1); 
    248248  return os_pushresult(L, mkdir(dirname) == 0, dirname); 
     249} 
     250 
     251/* 
     252  syntax 
     253    t=os.listdir("name",[showall]) 
     254  returns array of filenames, or nil, strerror, errno 
     255  if showall is true, t includes ".", ".." and deleted entries 
     256  NOTE except for the root directory, names ending in / will not work 
     257*/ 
     258static int os_listdir (lua_State *L) { 
     259  DIR *dir; 
     260  struct dirent *de; 
     261  const char *dirname = luaL_checkstring(L, 1); 
     262  int all=lua_toboolean(L, 2); 
     263  int i=1; 
     264  dir = opendir(dirname); 
     265  if(!dir)  
     266    return os_pushresult(L, 0 , dirname); 
     267  lua_newtable(L);  
     268  while((de = readdir(dir))) { 
     269        if(!all && (de->name[0] == 0xE5 || (strcmp(de->name,".")==0) || (strcmp(de->name,"..")==0))) 
     270      continue; 
     271        lua_pushinteger(L, i); 
     272        lua_pushstring(L, de->name); 
     273        lua_settable(L,-3); 
     274        ++i; 
     275  } 
     276  closedir(dir); 
     277  return 1; 
    249278} 
    250279 
     
    322351#endif 
    323352  {"mkdir",     os_mkdir}, // reyalp - NOT STANDARD 
     353  {"listdir",   os_listdir}, // reyalp - NOT STANDARD 
    324354  {"stat",      os_stat}, // reyalp - NOT STANDARD 
    325355  {"utime",     os_utime}, // reyalp - NOT STANDARD 
  • trunk/version.inc

    r553 r555  
    1 BUILD_NUMBER := 0.7.3 
     1BUILD_NUMBER := 0.7.4 
Note: See TracChangeset for help on using the changeset viewer.