summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 21:21:50 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 23:17:22 +1000
commite4c9580d20924a0db1ff7ed0d30da9b71dbb5066 (patch)
tree67b660ec32e31282d0cf305b178bff1da3baba39 /src/lapi.js
parent7e886ba08a443d9653c3033901ae8c83108d3701 (diff)
downloadfengari-e4c9580d20924a0db1ff7ed0d30da9b71dbb5066.tar.gz
fengari-e4c9580d20924a0db1ff7ed0d30da9b71dbb5066.tar.bz2
fengari-e4c9580d20924a0db1ff7ed0d30da9b71dbb5066.zip
Introduce lvm.cvt2str
In future this could be configurable
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lapi.js b/src/lapi.js
index f06fc65..f7ef82e 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -667,8 +667,11 @@ const lua_toboolean = function(L, idx) {
const lua_tolstring = function(L, idx) {
let o = index2addr(L, idx);
- if ((!o.ttisstring() && !o.ttisnumber()))
- return null;
+ if (!o.ttisstring()) {
+ if (!lvm.cvt2str(o)) { /* not convertible? */
+ return null;
+ }
+ }
return o.ttisstring() ? o.svalue() : defs.to_luastring(`${o.value}`);
};
@@ -678,8 +681,11 @@ const lua_tostring = lua_tolstring;
const lua_toljsstring = function(L, idx) {
let o = index2addr(L, idx);
- if ((!o.ttisstring() && !o.ttisnumber()))
- return null;
+ if (!o.ttisstring()) {
+ if (!lvm.cvt2str(o)) { /* not convertible? */
+ return null;
+ }
+ }
return o.ttisstring() ? o.jsstring() : `${o.value}`;
};
@@ -872,7 +878,7 @@ const lua_isnumber = function(L, idx) {
const lua_isstring = function(L, idx) {
let o = index2addr(L, idx);
- return o.ttisstring() || o.ttisnumber();
+ return o.ttisstring() || lvm.cvt2str(o);
};
const lua_isuserdata = function(L, idx) {