diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-08 15:41:19 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-08 16:07:38 +1000 |
commit | e67fb5f4cb51fbf4061ab647ef08ef4893b7f0e4 (patch) | |
tree | f42bc3854fe31ec86324dd55725d1d3ff963cf2e /src/lvm.js | |
parent | 41ad8917ca15b275c8aca20f6e3907a08ae7ad15 (diff) | |
download | fengari-e67fb5f4cb51fbf4061ab647ef08ef4893b7f0e4.tar.gz fengari-e67fb5f4cb51fbf4061ab647ef08ef4893b7f0e4.tar.bz2 fengari-e67fb5f4cb51fbf4061ab647ef08ef4893b7f0e4.zip |
Add accessors to TValue for TString values
Diffstat (limited to 'src/lvm.js')
-rw-r--r-- | src/lvm.js | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -859,7 +859,7 @@ const luaV_tointeger = function(obj, mode) { } else if (obj.ttisinteger()) { return obj.value; } else if (obj.ttisstring()) { - return luaV_tointeger(lobject.luaO_str2num(obj.value), mode); + return luaV_tointeger(lobject.luaO_str2num(obj.svalue()), mode); } return false; @@ -874,7 +874,7 @@ const tonumber = function(v) { return v.value; if (v.ttnov() === CT.LUA_TSTRING) - return lobject.luaO_str2num(v.value); + return lobject.luaO_str2num(v.svalue()); return false; }; @@ -999,6 +999,10 @@ const tostring = function(L, i) { return false; }; +const isemptystr = function(o) { + return o.ttisstring() && o.vslen() === 0; +}; + /* ** Main operation for concatenation: concat 'total' values in the stack, ** from 'L->top - total' up to 'L->top - 1'. @@ -1011,23 +1015,23 @@ const luaV_concat = function(L, total) { if (!(L.stack[top-2].ttisstring() || L.stack[top-2].ttisnumber()) || !tostring(L, top - 1)) ltm.luaT_trybinTM(L, L.stack[top-2], L.stack[top-1], top-2, ltm.TMS.TM_CONCAT); - else if (L.stack[top-1].ttisstring() && L.stack[top-1].value.length === 0) + else if (isemptystr(L.stack[top-1])) { tostring(L, top - 2); - else if (L.stack[top-2].ttisstring() && L.stack[top-2].value.length === 0) + } else if (isemptystr(L.stack[top-2])) { L.stack[top - 2] = L.stack[top - 1]; - else { + } else { /* at least two non-empty string values; get as many as possible */ - let tl = L.stack[top-1].value.length; + let tl = L.stack[top-1].vslen(); /* collect total length and number of strings */ for (n = 1; n < total && tostring(L, top - n - 1); n++) { - let l = L.stack[top - n - 1].value.length; + let l = L.stack[top - n - 1].vslen(); // TODO: string length overflow ? tl += l; } let ts = []; for (let i = n; i > 0; i--) { - ts = ts.concat(L.stack[top - i].value); + ts = ts.concat(L.stack[top - i].svalue()); } L.stack[top - n] = new lobject.TValue(CT.LUA_TLNGSTR, lstring.luaS_bless(L, ts)); |