Simplify dir_iter_factory slightly.

This commit is contained in:
Reuben Thomas
2011-06-09 14:57:27 +01:00
parent d61eb8078d
commit f42e7e3543

View File

@@ -465,21 +465,19 @@ static int dir_iter_factory (lua_State *L) {
dir_data *d; dir_data *d;
lua_pushcfunction (L, dir_iter); lua_pushcfunction (L, dir_iter);
d = (dir_data *) lua_newuserdata (L, sizeof(dir_data)); d = (dir_data *) lua_newuserdata (L, sizeof(dir_data));
luaL_getmetatable (L, DIR_METATABLE);
lua_setmetatable (L, -2);
d->closed = 0; d->closed = 0;
#ifdef _WIN32 #ifdef _WIN32
d->hFile = 0L; d->hFile = 0L;
luaL_getmetatable (L, DIR_METATABLE);
lua_setmetatable (L, -2);
if (strlen(path) > MAX_PATH-2) if (strlen(path) > MAX_PATH-2)
luaL_error (L, "path too long: %s", path); luaL_error (L, "path too long: %s", path);
else else
sprintf (d->pattern, "%s/*", path); sprintf (d->pattern, "%s/*", path);
#else #else
luaL_getmetatable (L, DIR_METATABLE);
lua_setmetatable (L, -2);
d->dir = opendir (path); d->dir = opendir (path);
if (d->dir == NULL) if (d->dir == NULL)
luaL_error (L, "cannot open %s: %s", path, strerror (errno)); luaL_error (L, "cannot open %s: %s", path, strerror (errno));
#endif #endif
return 2; return 2;
} }