Make lua listdir functions return useful error messages

develop
lethosor 2015-08-10 12:44:27 -04:00
parent 05f36856f4
commit 9c84c78129
1 changed files with 13 additions and 2 deletions

@ -2209,7 +2209,14 @@ static int filesystem_listdir(lua_State *L)
luaL_checktype(L,1,LUA_TSTRING);
std::string dir=lua_tostring(L,1);
std::vector<std::string> files;
DFHack::Filesystem::listdir(dir, files);
int err = DFHack::Filesystem::listdir(dir, files);
if (err)
{
lua_pushnil(L);
lua_pushstring(L, strerror(err));
lua_pushinteger(L, err);
return 3;
}
lua_newtable(L);
for(int i=0;i<files.size();i++)
{
@ -2232,8 +2239,12 @@ static int filesystem_listdir_recursive(lua_State *L)
if (err)
{
lua_pushnil(L);
if (err == -1)
lua_pushfstring(L, "max depth exceeded: %d", depth);
else
lua_pushstring(L, strerror(err));
lua_pushinteger(L, err);
return 2;
return 3;
}
lua_newtable(L);
int i = 1;