From 0ca60aeadcba9ac66063abd539966c91a55064bd Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 9 Jun 2017 16:12:00 +1000 Subject: src/lapi.js: lua_todataview should use cvt2str --- src/lapi.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index 1971cd7..4b80d20 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -670,12 +670,15 @@ const lua_toljsstring = function(L, idx) { const lua_tojsstring = lua_toljsstring; -// Convert a string on the stack to a dataview, because lua_tostring will perform utf-8 to utf-16 conversion const lua_todataview = function(L, idx) { let o = index2addr(L, idx); - if (!o.ttisstring() && !o.ttisnumber()) - return null; + 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)); -- cgit v1.2.3-70-g09d2