From f87a838f498c2ec6536ba813d7ae83bd1e78a506 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 29 May 2017 14:13:28 +1000 Subject: luaO_tostring should modify TValue --- src/lapi.js | 6 ++---- src/lobject.js | 8 +++++--- src/lvm.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lapi.js b/src/lapi.js index 42e87a9..b08f342 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -654,8 +654,7 @@ const lua_tolstring = function(L, idx) { if (!lvm.cvt2str(o)) { /* not convertible? */ return null; } - /* TODO: this should modify number on the stack */ - return lobject.luaO_tostring(L, o).getstr(); + lobject.luaO_tostring(L, o); } return o.svalue(); }; @@ -669,8 +668,7 @@ const lua_toljsstring = function(L, idx) { if (!lvm.cvt2str(o)) { /* not convertible? */ return null; } - /* TODO: this should modify number on the stack */ - return defs.to_jsstring(lobject.luaO_tostring(L, o).getstr()); + lobject.luaO_tostring(L, o); } return o.jsstring(); }; diff --git a/src/lobject.js b/src/lobject.js index 7f81438..db76cb5 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -530,7 +530,7 @@ const luaO_tostring = function(L, obj) { buff.push(char['0']); /* adds '.0' to result */ } } - return lstring.luaS_bless(L, buff); + obj.setsvalue(lstring.luaS_bless(L, buff)); }; const pushstr = function(L, str) { @@ -563,11 +563,13 @@ const luaO_pushvfstring = function(L, fmt, argp) { case char['d']: case char['I']: ldo.luaD_inctop(L); - setsvalue2s(L, L.top-1, luaO_tostring(L, new TValue(CT.LUA_TNUMINT, argp[a++]))); + L.stack[L.top-1].setivalue(argp[a++]); + luaO_tostring(L, L.stack[L.top-1]); break; case char['f']: ldo.luaD_inctop(L); - setsvalue2s(L, L.top-1, luaO_tostring(L, new TValue(CT.LUA_TNUMFLT, argp[a++]))); + L.stack[L.top-1].setfltvalue(argp[a++]); + luaO_tostring(L, L.stack[L.top-1]); break; case char['p']: let v = argp[a++]; diff --git a/src/lvm.js b/src/lvm.js index 5f32129..bb5a615 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -1080,7 +1080,7 @@ const tostring = function(L, i) { if (o.ttisstring()) return true; if (cvt2str(o)) { - lobject.setsvalue2s(L, i, lobject.luaO_tostring(L, o)); + lobject.luaO_tostring(L, o); return true; } -- cgit v1.2.3-70-g09d2