diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/llex.js | 10 | ||||
-rw-r--r-- | src/lobject.js | 26 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/llex.js b/src/llex.js index 1adac0a..479fe48 100644 --- a/src/llex.js +++ b/src/llex.js @@ -250,7 +250,7 @@ const txtToken = function(ls, token) { case R.TK_NAME: case R.TK_STRING: case R.TK_FLT: case R.TK_INT: save(ls, '\0'); - return lapi.lua_pushstring(ls.L, `'${ls.buff.buffer}'`); + return lapi.lua_pushstring(ls.L, `'${ls.buff.buffer.join('')}'`); default: return luaX_token2str(ls, token); } @@ -306,7 +306,10 @@ const read_long_string = function(ls, seminfo, sep) { case '\n': case '\r': { save(ls, '\n'); inclinenumber(ls); - if (!seminfo) ls.buff.n = 0; + if (!seminfo) { + ls.buff.n = 0; + ls.buff.buffer = []; + } break; } default: { @@ -444,6 +447,7 @@ const read_string = function(ls, del, seminfo) { const llex = function(ls, seminfo) { ls.buff.n = 0; + ls.buff.buffer = []; for (;;) { switch (ls.current) { @@ -463,9 +467,11 @@ const llex = function(ls, seminfo) { if (ls.current === '[') { /* long comment? */ let sep = skip_sep(ls); ls.buff.n = 0; /* 'skip_sep' may dirty the buffer */ + ls.buff.buffer = []; if (sep >= 0) { read_long_string(ls, null, sep); /* skip long comment */ ls.buff.n = 0; /* previous call may dirty the buff. */ + ls.buff.buffer = []; break; } } diff --git a/src/lobject.js b/src/lobject.js index 93e23c2..f6c6ef0 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -294,22 +294,22 @@ const l_str2int = function(s) { let empty = true; let neg; - while (ljstype.lisspace(s.charAt(0))) s = s.slice(1); /* skip initial spaces */ - neg = s.charAt(0) === '-'; + while (ljstype.lisspace(s[0])) s = s.slice(1); /* skip initial spaces */ + neg = s[0] === '-'; - if (neg || s.charAt(0) === '+') + if (neg || s[0] === '+') s = s.slice(1); if (s[0] === '0' && (s[1] === 'x' || s[1] === 'X')) { /* hex? */ s = s.slice(2); /* skip '0x' */ - for (; ljstype.lisxdigit(s); s = s.slice(1)) { + for (; ljstype.lisxdigit(s[0]); s = s.slice(1)) { a = a * 16 + luaO_hexavalue(s); empty = false; } } else { /* decimal */ - for (; ljstype.lisdigit(s); s = s.slice(1)) { - let d = parseInt(s.charAt(0)); + for (; ljstype.lisdigit(s[0]); s = s.slice(1)) { + let d = parseInt(s[0]); if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ return null; /* do not accept it (as integer) */ a = a * 10 + d; @@ -317,9 +317,9 @@ const l_str2int = function(s) { } } - while (ljstype.lisspace(s.charAt(0))) s = s.slice(1); /* skip trailing spaces */ + while (ljstype.lisspace(s[0])) s = s.slice(1); /* skip trailing spaces */ - if (empty || s.charAt(0) !== "") return null; /* something wrong in the numeral */ + if (empty)/* TODO: || s[0] !== "") */ return null; /* something wrong in the numeral */ else { result[1] = neg ? -a : a; result[0] = s; @@ -332,19 +332,17 @@ const luaO_str2num = function(s) { let e = s2i[0]; let i = s2i[1]; - let o; - if (e !== null) /* try as an integer */ - o = new TValue(CT.LUA_TNUMINT, i); - else { /* else try as a float */ + if (e !== null) { /* try as an integer */ + return new TValue(CT.LUA_TNUMINT, i);; + } else { /* else try as a float */ s2i = l_str2d(s); e = s2i[0]; i = s2i[1]; if (e !== null) { - o = new TValue(CT.LUA_TNUMFLT, i); + return new TValue(CT.LUA_TNUMFLT, i); } else return false; /* conversion failed */ - return (e - s) + 1; // TODO: wrong } }; |