summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS7
-rw-r--r--README.md1
-rw-r--r--package.json2
-rw-r--r--src/defs.js21
-rw-r--r--src/fengaricore.js2
-rw-r--r--src/lauxlib.js23
-rw-r--r--src/liolib.js7
-rw-r--r--src/loadlib.js2
-rw-r--r--src/loslib.js14
-rw-r--r--src/luaconf.js11
-rw-r--r--yarn.lock12
11 files changed, 64 insertions, 38 deletions
diff --git a/NEWS b/NEWS
index c53c902..fbb983b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,13 @@
UNRELEASED
+ - More node 6 compatibility fixes
+
+
+0.1.1 - 2018-04-03
+
- Fix node 6 compatibility
+ - Removed duplicate LUA_PATH entries
+
0.1.0 - 2018-03-31
diff --git a/README.md b/README.md
index 425f706..505c90a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/fengari-lua/fengari.svg?branch=master)](https://travis-ci.org/fengari-lua/fengari)
+[![npm](https://img.shields.io/npm/v/fengari.svg)](https://npmjs.com/package/fengari)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![#fengari on Freenode](https://img.shields.io/Freenode/%23fengari.png)](https://webchat.freenode.net/?channels=fengari)
diff --git a/package.json b/package.json
index 7424f82..9988883 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "fengari",
- "version": "0.1.0",
+ "version": "0.1.1",
"description": "A Lua VM written in JS ES6 targeting the browser",
"main": "src/fengari.js",
"directories": {
diff --git a/src/defs.js b/src/defs.js
index 98269ea..daa5f70 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -56,6 +56,7 @@ const luastring_eq = function(a, b) {
return true;
};
+const unicode_error_message = "cannot convert invalid utf8 to javascript string";
const to_jsstring = function(value, from, to, replacement_char) {
if (!is_luastring(value)) throw new TypeError("to_jsstring expects a Uint8Array");
@@ -72,18 +73,18 @@ const to_jsstring = function(value, from, to, replacement_char) {
/* single byte sequence */
str += String.fromCharCode(u0);
} else if (u0 < 0xC2 || u0 > 0xF4) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
} else if (u0 <= 0xDF) {
/* two byte sequence */
if (i >= to) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u1 = value[i++];
if ((u1&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
@@ -91,19 +92,19 @@ const to_jsstring = function(value, from, to, replacement_char) {
} else if (u0 <= 0xEF) {
/* three byte sequence */
if (i+1 >= to) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u1 = value[i++];
if ((u1&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u2 = value[i++];
if ((u2&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
@@ -119,25 +120,25 @@ const to_jsstring = function(value, from, to, replacement_char) {
} else {
/* four byte sequence */
if (i+2 >= to) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u1 = value[i++];
if ((u1&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u2 = value[i++];
if ((u2&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u3 = value[i++];
if ((u3&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
diff --git a/src/fengaricore.js b/src/fengaricore.js
index c34b560..1335ba8 100644
--- a/src/fengaricore.js
+++ b/src/fengaricore.js
@@ -11,7 +11,7 @@ const defs = require("./defs.js");
const FENGARI_VERSION_MAJOR = "0";
const FENGARI_VERSION_MINOR = "1";
const FENGARI_VERSION_NUM = 1;
-const FENGARI_VERSION_RELEASE = "0";
+const FENGARI_VERSION_RELEASE = "1";
const FENGARI_VERSION = "Fengari " + FENGARI_VERSION_MAJOR + "." + FENGARI_VERSION_MINOR;
const FENGARI_RELEASE = FENGARI_VERSION + "." + FENGARI_VERSION_RELEASE;
const FENGARI_AUTHORS = "B. Giannangeli, Daurnimator";
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 */
}
diff --git a/src/liolib.js b/src/liolib.js
index bd78f87..92dda58 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -130,6 +130,11 @@ const io_output = function(L) {
return g_iofile(L, IO_OUTPUT, "w");
};
+/* node <= 6 doesn't support passing a Uint8Array to fs.writeSync */
+const prepare_string_for_write = process.versions.node > 6 ?
+ (s) => s : // identity function
+ (s) => Buffer.from(s.buffer, s.byteOffset, s.byteLength);
+
const g_write = function(L, f, arg) {
let nargs = lua_gettop(L) - arg;
let status = true;
@@ -137,7 +142,7 @@ const g_write = function(L, f, arg) {
for (; nargs--; arg++) {
let s = luaL_checklstring(L, arg);
try {
- status = status && (fs.writeSync(f.fd, Uint8Array.from(s)) === s.length);
+ status = status && (fs.writeSync(f.fd, prepare_string_for_write(s), 0, s.length) === s.length);
} catch (e) {
status = false;
err = e;
diff --git a/src/loadlib.js b/src/loadlib.js
index f6679ba..49cfc5a 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -85,7 +85,7 @@ const global_env = (function() {
return self;
} else {
/* unknown global env */
- return eval('this'); /* use non-strict mode to get global env */
+ return (0, eval)('this'); /* use non-strict mode to get global env */
}
})();
diff --git a/src/loslib.js b/src/loslib.js
index 6fec903..6c6b2f4 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -251,13 +251,17 @@ if (typeof process === "undefined") {
syslib.remove = function(L) {
let filename = luaL_checkstring(L, 1);
try {
- if (fs.lstatSync(filename).isDirectory()) {
- fs.rmdirSync(filename);
+ fs.unlinkSync(filename);
+ } catch (e) {
+ if (e.code === 'EISDIR') {
+ try {
+ fs.rmdirSync(filename);
+ } catch (e) {
+ return luaL_fileresult(L, false, filename, e);
+ }
} else {
- fs.unlinkSync(filename);
+ return luaL_fileresult(L, false, filename, e);
}
- } catch (e) {
- return luaL_fileresult(L, false, filename, e);
}
return luaL_fileresult(L, true);
};
diff --git a/src/luaconf.js b/src/luaconf.js
index 7a6fe40..387e813 100644
--- a/src/luaconf.js
+++ b/src/luaconf.js
@@ -43,12 +43,12 @@ if (typeof process === "undefined") {
const LUA_LDIR = "./lua/" + LUA_VDIR + "/";
module.exports.LUA_LDIR = LUA_LDIR;
- const LUA_JSDIR = "./lua/" + LUA_VDIR + "/";
+ const LUA_JSDIR = LUA_LDIR;
module.exports.LUA_JSDIR = LUA_JSDIR;
const LUA_PATH_DEFAULT = to_luastring(
LUA_LDIR + "?.lua;" + LUA_LDIR + "?/init.lua;" +
- LUA_JSDIR + "?.lua;" + LUA_JSDIR + "?/init.lua;" +
+ /* LUA_JSDIR excluded as it is equal to LUA_LDIR */
"./?.lua;./?/init.lua"
);
module.exports.LUA_PATH_DEFAULT = LUA_PATH_DEFAULT;
@@ -100,15 +100,14 @@ if (typeof process === "undefined") {
const LUA_LDIR2 = LUA_ROOT2 + "share/lua/" + LUA_VDIR + "/";
module.exports.LUA_LDIR = LUA_LDIR;
- const LUA_JSDIR = LUA_ROOT + "share/lua/" + LUA_VDIR + "/";
+ const LUA_JSDIR = LUA_LDIR;
module.exports.LUA_JSDIR = LUA_JSDIR;
- const LUA_JSDIR2 = LUA_ROOT2 + "share/lua/" + LUA_VDIR + "/";
+ const LUA_JSDIR2 = LUA_LDIR2;
const LUA_PATH_DEFAULT = to_luastring(
LUA_LDIR + "?.lua;" + LUA_LDIR + "?/init.lua;" +
LUA_LDIR2 + "?.lua;" + LUA_LDIR2 + "?/init.lua;" +
- LUA_JSDIR + "?.lua;" + LUA_JSDIR + "?/init.lua;" +
- LUA_JSDIR2 + "?.lua;" + LUA_JSDIR2 + "?/init.lua;" +
+ /* LUA_JSDIR(2) excluded as it is equal to LUA_LDIR(2) */
"./?.lua;./?/init.lua"
);
module.exports.LUA_PATH_DEFAULT = LUA_PATH_DEFAULT;
diff --git a/yarn.lock b/yarn.lock
index a32a6fd..15b2d0a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -945,8 +945,8 @@ esprima@^4.0.0:
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
esquery@^1.0.0:
- version "1.0.0"
- resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.0.tgz#cfba8b57d7fba93f17298a8a006a04cda13d80fa"
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708"
dependencies:
estraverse "^4.0.0"
@@ -1039,8 +1039,8 @@ extend@~3.0.0, extend@~3.0.1:
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
external-editor@^2.0.4:
- version "2.1.0"
- resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.1.0.tgz#3d026a21b7f95b5726387d4200ac160d372c3b48"
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.2.0.tgz#045511cfd8d133f3846673d1047c154e214ad3d5"
dependencies:
chardet "^0.4.0"
iconv-lite "^0.4.17"
@@ -2855,8 +2855,8 @@ regex-not@^1.0.0, regex-not@^1.0.2:
safe-regex "^1.1.0"
regexpp@^1.0.1:
- version "1.0.1"
- resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-1.0.1.tgz#d857c3a741dce075c2848dcb019a0a975b190d43"
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-1.1.0.tgz#0e3516dd0b7904f413d2d4193dce4618c3a689ab"
remove-trailing-separator@^1.0.1:
version "1.1.0"