summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lauxlib.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 1300f2a..2276bd0 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -290,11 +290,19 @@ const luaL_fileresult = function(L, stat, fname, e) {
return 1;
} else {
lua_pushnil(L);
+ let message, errno;
+ if (e) {
+ message = e.message;
+ errno = -e.errno;
+ } else {
+ message = "Success"; /* what strerror(0) returns */
+ errno = 0;
+ }
if (fname)
- lua_pushfstring(L, to_luastring("%s: %s"), fname, to_luastring(e.message));
+ lua_pushfstring(L, to_luastring("%s: %s"), fname, to_luastring(message));
else
- lua_pushstring(L, to_luastring(e.message));
- lua_pushinteger(L, -e.errno);
+ lua_pushstring(L, to_luastring(message));
+ lua_pushinteger(L, errno);
return 3;
}
};