From 87e38b8ae8d98064e5013ba5e9e73e035046c841 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 8 Apr 2018 01:24:07 +1000 Subject: src/lauxlib.js: e argument is not compulsory e.g. when file:write fails due to short write --- src/lauxlib.js | 14 +++++++++++--- 1 file 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; } }; -- cgit v1.2.3-70-g09d2