summaryrefslogtreecommitdiff
path: root/src/lvm.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-08 17:45:21 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-08 18:23:04 +1000
commit767dfd4196106b6ecb45a5253030778100cb1bc4 (patch)
treede8be4033bbeaeb4910db577dc4260303a70b6db /src/lvm.js
parent28f53e175e1609fc5882b571a726c6761151b05d (diff)
downloadfengari-767dfd4196106b6ecb45a5253030778100cb1bc4.tar.gz
fengari-767dfd4196106b6ecb45a5253030778100cb1bc4.tar.bz2
fengari-767dfd4196106b6ecb45a5253030778100cb1bc4.zip
src/lvm.js: Use TValue accessors to use strings
Diffstat (limited to 'src/lvm.js')
-rw-r--r--src/lvm.js39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/lvm.js b/src/lvm.js
index 15081ad..1ea4f65 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -719,7 +719,7 @@ const luaV_lessthan = function(L, l, r) {
if (l.ttisnumber() && r.ttisnumber())
return LTnum(l, r) ? 1 : 0;
else if (l.ttisstring() && r.ttisstring())
- return l_strcmp(l, r) < 0 ? 1 : 0;
+ return l_strcmp(l.tsvalue(), r.tsvalue()) < 0 ? 1 : 0;
else {
let res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LT);
if (res < 0)
@@ -734,7 +734,7 @@ const luaV_lessequal = function(L, l, r) {
if (l.ttisnumber() && r.ttisnumber())
return LEnum(l, r) ? 1 : 0;
else if (l.ttisstring() && r.ttisstring())
- return l_strcmp(l, r) <= 0 ? 1 : 0;
+ return l_strcmp(l.tsvalue(), r.tsvalue()) <= 0 ? 1 : 0;
else {
res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LE);
if (res >= 0)
@@ -773,18 +773,7 @@ const luaV_equalobj = function(L, t1, t2) {
return t1.value === t2.value ? 1 : 0;
case CT.LUA_TSHRSTR:
case CT.LUA_TLNGSTR: {
- let l1 = t1.value.length;
- let l2 = t2.value.length;
-
- if (l1 !== l2) return 0;
-
- let i;
- for (i = 0; i < l1; i++) {
- if (t1.value[i] !== t2.value[i])
- return 0;
- }
-
- return 1;
+ return lstring.luaS_eqlngstr(t1.tsvalue(), t2.tsvalue()) ? 1 : 0;
}
case CT.LUA_TLIGHTUSERDATA:
case CT.LUA_TUSERDATA:
@@ -927,12 +916,12 @@ const LTintfloat = function(l, r) {
** The code is a little tricky because it allows '\0' in the strings.
*/
const l_strcmp = function(ls, rs) {
- let l = ls.value;
- let jl = ls.jsstring();
- let ll = l.length;
- let r = rs.value;
- let lr = r.length;
- let jr = rs.jsstring();
+ let l = ls;
+ let ll = ls.length;
+ let jl = defs.to_jsstring(l);
+ let r = rs;
+ let lr = rs.length;
+ let jr = defs.to_jsstring(r);
for (;;) {
let temp = jl === jr; // TODO: strcoll ?
if (!temp) /* not equal? */
@@ -949,14 +938,10 @@ const l_strcmp = function(ls, rs) {
ll -= len;
r = r.slice(len);
lr -= len;
- jl = new lobject.TValue(null, l).jsstring();
- jr = new lobject.TValue(null, r).jsstring();
+ jl = defs.to_jsstring(l);
+ jr = defs.to_jsstring(r);
}
}
-
- ls = ls.jsstring();
- rs = rs.jsstring();
- return ls === rs ? 0 : (ls < rs ? -1 : 1);
};
/*
@@ -973,7 +958,7 @@ const luaV_objlen = function(L, ra, rb) {
}
case CT.LUA_TSHRSTR:
case CT.LUA_TLNGSTR:
- L.stack[ra] = new lobject.TValue(CT.LUA_TNUMINT, rb.value.length);
+ L.stack[ra] = new lobject.TValue(CT.LUA_TNUMINT, rb.vslen());
return;
default: {
tm = ltm.luaT_gettmbyobj(L, rb, ltm.TMS.TM_LEN);