aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-03-04 12:53:13 +1100
committerdaurnimator <quae@daurnimator.com>2018-03-04 12:58:56 +1100
commitb2c7f18f2d3b70daf3a18fedf486cac71e16dc58 (patch)
tree78c26f789279ae216e27a72052d09de927dfcb17
parent79a9c5e4c123da9e58979a61d17557398b0c1be7 (diff)
downloadfengari-b2c7f18f2d3b70daf3a18fedf486cac71e16dc58.tar.gz
fengari-b2c7f18f2d3b70daf3a18fedf486cac71e16dc58.tar.bz2
fengari-b2c7f18f2d3b70daf3a18fedf486cac71e16dc58.zip
src/luaconf.js: Add LUA_COMPAT_FLOATSTRING
For #113
-rw-r--r--src/lobject.js5
-rw-r--r--src/luaconf.js35
2 files changed, 21 insertions, 19 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 8896c1e..e3b92f7 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -55,6 +55,7 @@ const {
} = require('./lstring.js');
const ltable = require('./ltable.js');
const {
+ LUA_COMPAT_FLOATSTRING,
ldexp,
lua_getlocaledecpoint,
lua_integer2str,
@@ -585,15 +586,13 @@ const luaO_str2num = function(s, o) {
}
};
-/* this currently returns new TValue instead of modifying */
const luaO_tostring = function(L, obj) {
let buff;
if (obj.ttisinteger())
buff = to_luastring(lua_integer2str(obj.value));
else {
let str = lua_number2str(obj.value);
- // Assume no LUA_COMPAT_FLOATSTRING
- if (/^[-0123456789]+$/.test(str)) { /* looks like an int? */
+ if (!LUA_COMPAT_FLOATSTRING && /^[-0123456789]+$/.test(str)) { /* looks like an int? */
str += String.fromCharCode(lua_getlocaledecpoint()) + '0'; /* adds '.0' to result */
}
buff = to_luastring(str);
diff --git a/src/luaconf.js b/src/luaconf.js
index 9e0d571..278173d 100644
--- a/src/luaconf.js
+++ b/src/luaconf.js
@@ -1,5 +1,7 @@
"use strict";
+const LUA_COMPAT_FLOATSTRING = false;
+
const LUA_MAXINTEGER = 2147483647;
const LUA_MININTEGER = -2147483648;
@@ -73,19 +75,20 @@ const ldexp = function(mantissa, exponent) {
return result;
};
-module.exports.LUAI_MAXSTACK = LUAI_MAXSTACK;
-module.exports.LUA_IDSIZE = LUA_IDSIZE;
-module.exports.LUA_INTEGER_FMT = LUA_INTEGER_FMT;
-module.exports.LUA_INTEGER_FRMLEN = LUA_INTEGER_FRMLEN;
-module.exports.LUA_MAXINTEGER = LUA_MAXINTEGER;
-module.exports.LUA_MININTEGER = LUA_MININTEGER;
-module.exports.LUA_NUMBER_FMT = LUA_NUMBER_FMT;
-module.exports.LUA_NUMBER_FRMLEN = LUA_NUMBER_FRMLEN;
-module.exports.LUAL_BUFFERSIZE = LUAL_BUFFERSIZE;
-module.exports.frexp = frexp;
-module.exports.ldexp = ldexp;
-module.exports.lua_getlocaledecpoint = lua_getlocaledecpoint;
-module.exports.lua_integer2str = lua_integer2str;
-module.exports.lua_number2str = lua_number2str;
-module.exports.lua_numbertointeger = lua_numbertointeger;
-module.exports.luai_apicheck = luai_apicheck;
+module.exports.LUAI_MAXSTACK = LUAI_MAXSTACK;
+module.exports.LUA_COMPAT_FLOATSTRING = LUA_COMPAT_FLOATSTRING;
+module.exports.LUA_IDSIZE = LUA_IDSIZE;
+module.exports.LUA_INTEGER_FMT = LUA_INTEGER_FMT;
+module.exports.LUA_INTEGER_FRMLEN = LUA_INTEGER_FRMLEN;
+module.exports.LUA_MAXINTEGER = LUA_MAXINTEGER;
+module.exports.LUA_MININTEGER = LUA_MININTEGER;
+module.exports.LUA_NUMBER_FMT = LUA_NUMBER_FMT;
+module.exports.LUA_NUMBER_FRMLEN = LUA_NUMBER_FRMLEN;
+module.exports.LUAL_BUFFERSIZE = LUAL_BUFFERSIZE;
+module.exports.frexp = frexp;
+module.exports.ldexp = ldexp;
+module.exports.lua_getlocaledecpoint = lua_getlocaledecpoint;
+module.exports.lua_integer2str = lua_integer2str;
+module.exports.lua_number2str = lua_number2str;
+module.exports.lua_numbertointeger = lua_numbertointeger;
+module.exports.luai_apicheck = luai_apicheck;