summaryrefslogtreecommitdiff
path: root/src/lvm.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 12:54:22 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 12:55:35 +0100
commit8f913dd74957ef18e144f15b78c3e55893744218 (patch)
treea47ff729efa6474c99d5371ec06272bed47a8417 /src/lvm.js
parent573a9c3b39bf1570a575ce3f077a33e752439165 (diff)
downloadfengari-8f913dd74957ef18e144f15b78c3e55893744218.tar.gz
fengari-8f913dd74957ef18e144f15b78c3e55893744218.tar.bz2
fengari-8f913dd74957ef18e144f15b78c3e55893744218.zip
lua_tonumber, lua_tointeger, lua_tostring, lua_toboolean
Diffstat (limited to 'src/lvm.js')
-rw-r--r--src/lvm.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lvm.js b/src/lvm.js
index e2c78b3..931b7a5 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -785,11 +785,15 @@ const luaV_tointeger = function(obj, mode) {
return false;
};
+const tointeger = function(o) {
+ return o.ttisinteger() ? o.value : luaV_tointeger(o, 0);
+};
+
const tonumber = function(v) {
- if (v.type === CT.LUA_TNUMFLT || v.type === CT.LUA_TNUMINT)
+ if (v.ttnov() === CT.LUA_TNUMBER)
return v.value;
- if (v.type === CT.LUA_TSHRSTR || v.type === CT.LUA_TLNGSTR)
+ if (v.ttnov() === CT.LUA_TSTRING)
return parseFloat(v.value); // TODO: luaO_str2num
return false;
@@ -873,7 +877,7 @@ const tostring = function(L, i) {
let o = L.stack[i];
let str = `${o.value}`;
- if (o.ttisstring() || (o.ttisnumber() && !isNaN(parseFloat(`${str}`)))) {
+ if (o.ttisstring() || (o.ttisnumber() && !isNaN(str))) {
L.stack[i] = new TValue(CT.LUA_TLNGSTR, str);
return true;
}
@@ -1023,6 +1027,7 @@ module.exports.luaV_equalobj = luaV_equalobj;
module.exports.forlimit = forlimit;
module.exports.luaV_tointeger = luaV_tointeger;
module.exports.tonumber = tonumber;
+module.exports.tointeger = tointeger;
module.exports.LTnum = LTnum;
module.exports.LEnum = LEnum;
module.exports.LEintfloat = LEintfloat;