summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-04-08 01:24:07 +1000
committerdaurnimator <quae@daurnimator.com>2018-04-08 01:24:07 +1000
commit87e38b8ae8d98064e5013ba5e9e73e035046c841 (patch)
tree805ccfd6f46a47f0e4594aac95cd76e2aa833284
parente2bea197494e295180742678a678eea4da3e2d4e (diff)
downloadfengari-87e38b8ae8d98064e5013ba5e9e73e035046c841.tar.gz
fengari-87e38b8ae8d98064e5013ba5e9e73e035046c841.tar.bz2
fengari-87e38b8ae8d98064e5013ba5e9e73e035046c841.zip
src/lauxlib.js: e argument is not compulsory
e.g. when file:write fails due to short write
-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;
}
};