From a9b4bdf6020a5d95d52f52e521bd7f2dd66ea705 Mon Sep 17 00:00:00 2001 From: rxi Date: Tue, 21 Apr 2020 23:33:04 +0100 Subject: [PATCH] Made system.get_file_info() and list_dir() return (nil,msg) on error --- src/api/system.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index eaa32c4b..65dda196 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -1,7 +1,8 @@ #include +#include #include #include -#include +#include #include #include "api.h" #ifdef _WIN32 @@ -212,7 +213,11 @@ static int f_list_dir(lua_State *L) { const char *path = luaL_checkstring(L, 1); DIR *dir = opendir(path); - if (!dir) { luaL_error(L, "could not open directory: %s", path); } + if (!dir) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } lua_newtable(L); int i = 1; @@ -250,7 +255,11 @@ static int f_get_file_info(lua_State *L) { struct stat s; int err = stat(path, &s); - if (err < 0) { return 0; } + if (err < 0) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } lua_newtable(L); lua_pushnumber(L, s.st_mtime);