diff options
author | daurnimator <quae@daurnimator.com> | 2018-01-06 22:14:27 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-01-06 22:14:27 +1100 |
commit | 9057e6fd7c36d4aa1ec8425f672d63901f041c20 (patch) | |
tree | ddcc4fb38ae04f70edd7fa80de0ffe6030064e33 /src | |
parent | 28f5e1052c7ee7fb15585621bd7c32ce72c02a82 (diff) | |
download | fengari-9057e6fd7c36d4aa1ec8425f672d63901f041c20.tar.gz fengari-9057e6fd7c36d4aa1ec8425f672d63901f041c20.tar.bz2 fengari-9057e6fd7c36d4aa1ec8425f672d63901f041c20.zip |
Support environments without a Uint8Array.from
Diffstat (limited to 'src')
-rw-r--r-- | src/defs.js | 22 | ||||
-rw-r--r-- | src/lstring.js | 2 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/defs.js b/src/defs.js index d162636..629e0af 100644 --- a/src/defs.js +++ b/src/defs.js @@ -131,16 +131,25 @@ class lua_Debug { } +let luastring_from; +if (typeof Uint8Array.from === "function") { + luastring_from = Uint8Array.from.bind(Uint8Array); +} else { + luastring_from = function(a) { + let i = 0; + let len = a.length; + let r = new Uint8Array(len); + while (len > i) r[i] = a[i++]; + return r; + }; +} + let luastring_of; if (typeof Uint8Array.of === "function") { luastring_of = Uint8Array.of.bind(Uint8Array); } else { luastring_of = function() { - let i = 0; - let len = arguments.length; - let r = new Uint8Array(len); - while (len > i) r[i] = arguments[i++]; - return r; + return luastring_from(arguments); }; } @@ -252,7 +261,7 @@ const to_luastring = function(str, cache) { outU8Array[outIdx++] = 0x80 | (u & 63); } } - outU8Array = Uint8Array.from(outU8Array); + outU8Array = luastring_from(outU8Array); if (cache) to_luastring_cache[str] = outU8Array; @@ -442,6 +451,7 @@ module.exports.lua_upvalueindex = lua_upvalueindex; module.exports.thread_status = thread_status; module.exports.is_luastring = is_luastring; module.exports.luastring_cmp = luastring_cmp; +module.exports.luastring_from = luastring_from; module.exports.luastring_of = luastring_of; module.exports.to_jsstring = to_jsstring; module.exports.to_luastring = to_luastring; diff --git a/src/lstring.js b/src/lstring.js index c8da56a..4350165 100644 --- a/src/lstring.js +++ b/src/lstring.js @@ -50,7 +50,7 @@ const luaS_bless = function(L, str) { /* makes a copy */ const luaS_new = function(L, str) { - return luaS_bless(L, Uint8Array.from(str)); + return luaS_bless(L, defs.luastring_from(str)); }; /* takes a js string */ |