diff options
author | daurnimator <quae@daurnimator.com> | 2018-04-08 01:24:07 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-04-08 01:24:07 +1000 |
commit | 87e38b8ae8d98064e5013ba5e9e73e035046c841 (patch) | |
tree | 805ccfd6f46a47f0e4594aac95cd76e2aa833284 /src/lauxlib.js | |
parent | e2bea197494e295180742678a678eea4da3e2d4e (diff) | |
download | fengari-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
Diffstat (limited to 'src/lauxlib.js')
-rw-r--r-- | src/lauxlib.js | 14 |
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; } }; |