aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-06-09 16:12:00 +1000
committerdaurnimator <quae@daurnimator.com>2017-06-09 16:18:14 +1000
commit0ca60aeadcba9ac66063abd539966c91a55064bd (patch)
tree527786fca102da9cb12db019ef632cb0ef9e0f40 /src
parentd0715205776884eda6727273d8cd52bcc50a775a (diff)
downloadfengari-0ca60aeadcba9ac66063abd539966c91a55064bd.tar.gz
fengari-0ca60aeadcba9ac66063abd539966c91a55064bd.tar.bz2
fengari-0ca60aeadcba9ac66063abd539966c91a55064bd.zip
src/lapi.js: lua_todataview should use cvt2str
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js9
1 files changed, 6 insertions, 3 deletions
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));