summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann@users.noreply.github.com>2017-05-22 20:06:57 +0200
committerGitHub <noreply@github.com>2017-05-22 20:06:57 +0200
commite3bdd1fea3665df28de25ed76f6399faf957179d (patch)
tree6884757b43064fa7163b54b86aa4561d185b5ca2 /src/lobject.js
parent25e2110a5eac0a2e6c7b4d502ffbd53fc61af301 (diff)
parent8a439e5563f12335e3d35dd63b4f8cbcc25a9bd8 (diff)
downloadfengari-e3bdd1fea3665df28de25ed76f6399faf957179d.tar.gz
fengari-e3bdd1fea3665df28de25ed76f6399faf957179d.tar.bz2
fengari-e3bdd1fea3665df28de25ed76f6399faf957179d.zip
Merge pull request #63 from daurnimator/fix-skipped-tests
Investigated + fixed some skipped tests
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 41c3a84..8c70985 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -448,8 +448,26 @@ const luaO_utf8esc = function(x) {
};
};
+/* this currently returns new TValue instead of modifying */
+const luaO_tostring = function(L, obj) {
+ let buff;
+ if (obj.ttisinteger())
+ buff = defs.to_luastring(luaconf.lua_integer2str(obj.value));
+ else {
+ let str = luaconf.lua_number2str(obj.value);
+ buff = defs.to_luastring(str);
+ // Assume no LUA_COMPAT_FLOATSTRING
+ if (/^[-0123456789]+$/.test(str)) { /* looks like an int? */
+ buff.push(char[luaconf.lua_getlocaledecpoint()]);
+ buff.push(char['0']); /* adds '.0' to result */
+ }
+ }
+ return new TValue(CT.LUA_TLNGSTR, lstring.luaS_bless(L, buff));
+};
+
const pushstr = function(L, str) {
- L.stack[L.top++] = new TValue(CT.LUA_TLNGSTR, lstring.luaS_new(L, str));
+ ldo.luaD_inctop(L);
+ L.stack[L.top-1] = new TValue(CT.LUA_TLNGSTR, lstring.luaS_new(L, str));
};
const luaO_pushvfstring = function(L, fmt, argp) {
@@ -476,8 +494,12 @@ const luaO_pushvfstring = function(L, fmt, argp) {
break;
case char['d']:
case char['I']:
+ ldo.luaD_inctop(L);
+ L.stack[L.top-1] = luaO_tostring(L, new TValue(CT.LUA_TNUMINT, argp[a++]));
+ break;
case char['f']:
- pushstr(L, defs.to_luastring(''+argp[a++]));
+ ldo.luaD_inctop(L);
+ L.stack[L.top-1] = luaO_tostring(L, new TValue(CT.LUA_TNUMFLT, argp[a++]));
break;
// case char['p']:
case char['U']:
@@ -616,6 +638,7 @@ module.exports.luaO_int2fb = luaO_int2fb;
module.exports.luaO_pushfstring = luaO_pushfstring;
module.exports.luaO_pushvfstring = luaO_pushvfstring;
module.exports.luaO_str2num = luaO_str2num;
+module.exports.luaO_tostring = luaO_tostring;
module.exports.luaO_utf8desc = luaO_utf8desc;
module.exports.luaO_utf8esc = luaO_utf8esc;
module.exports.numarith = numarith;