Le Mon, Sep 29, 2003 at 05:11:24PM +0300, you write :
Both LuaCheia and GluaX provide the kind of service you mention, and
it
works for Linux, Win32 and OS X. From gluax 'sys_module.c' (returns a
table using gluax macros):
[...]
struct dirent* entry;
dir= opendir( path );
while( (entry= readdir(dir)) != NULL )
closedir( dir );
Look at lposlib.c you can read :
What's the difference ?
static int pos_dir (lua_State *L)
{
DIR *d = NULL;
switch (lua_type(L, 1))
{
case LUA_TNONE:
d=opendir(".");
break;
case LUA_TSTRING:
d=opendir(lua_tostring(L, 1));
break;
default:
lua_error(L, "optional argument to function Dir must be
string");
}
if (d == NULL)
{
return pos_pusherr(L);
}
else
{
int i = 0;
struct dirent *entry;
lua_newtable(L);
while ((entry = readdir(d)) != NULL)
{
lua_pushnumber(L, ++i);
lua_pushstring(L, entry->d_name);
lua_settable(L, -3);
}
closedir(d);
lua_pushstring(L, "n");
lua_pushnumber(L, i);
lua_settable(L, -3);
return 1;
}
}