From 8249248f80467f1660509a30623f40bb9ff1eba7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 15 Dec 2017 14:56:04 +1100 Subject: src/lapi.js: Have lua_todataview return view over actual underlying Uint8Array --- src/lapi.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/lapi.js') diff --git a/src/lapi.js b/src/lapi.js index afa94ce..111735f 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -672,19 +672,8 @@ const lua_toljsstring = function(L, idx) { const lua_tojsstring = lua_toljsstring; const lua_todataview = function(L, idx) { - let o = index2addr(L, idx); - - if (!o.ttisstring()) { - if (!lvm.cvt2str(o)) { /* not convertible? */ - return null; - } - lobject.luaO_tostring(L, o); - } - - let dv = new DataView(new ArrayBuffer(o.vslen())); - o.svalue().forEach((e, i) => dv.setUint8(i, e, true)); - - return dv; + let u8 = lua_tolstring(L, idx); + return new DataView(u8.buffer, u8.byteOffset, u8.byteLength); }; const lua_rawlen = function(L, idx) { -- cgit v1.2.3-54-g00ecf