diff options
Diffstat (limited to 'src/lauxlib.js')
-rw-r--r-- | src/lauxlib.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js index d575e99..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; } }; @@ -850,8 +858,9 @@ if (typeof process === "undefined") { let path = to_uristring(filename); let xhr = new XMLHttpRequest(); xhr.open("GET", path, false); - /* XXX: Synchronous xhr in main thread always returns a js string - Additionally, some browsers make console noise if you even attempt to set responseType + /* + Synchronous xhr in main thread always returns a js string. + Some browsers make console noise if you even attempt to set responseType */ if (typeof window === "undefined") { xhr.responseType = "arraybuffer"; @@ -871,7 +880,7 @@ if (typeof process === "undefined") { let com = skipcomment(lf); /* check for signature first, as we don't want to add line number corrections in binary case */ if (com.c === LUA_SIGNATURE[0] && filename) { /* binary file? */ - /* no need to re-open in node.js */ + /* no need to re-open */ } else if (com.skipped) { /* read initial portion */ lf.buff[lf.n++] = 10 /* '\n'.charCodeAt(0) */; /* add line to correct line numbers */ } @@ -949,7 +958,7 @@ if (typeof process === "undefined") { let com = skipcomment(lf); /* check for signature first, as we don't want to add line number corrections in binary case */ if (com.c === LUA_SIGNATURE[0] && filename) { /* binary file? */ - /* no need to re-open in node.js */ + /* no need to re-open */ } else if (com.skipped) { /* read initial portion */ lf.buff[lf.n++] = 10 /* '\n'.charCodeAt(0) */; /* add line to correct line numbers */ } |