summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-06-16 11:00:16 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-06-16 11:00:16 +0200
commitcad0eac50b70a280611dd89440a805912ebfad8b (patch)
treeef1946cd0da4e3c4acfd5f0032ddae6f36c5d76b
parent1f501616500ee308da6b88e2ecef4bf19490d1ee (diff)
downloadfengari-cad0eac50b70a280611dd89440a805912ebfad8b.tar.gz
fengari-cad0eac50b70a280611dd89440a805912ebfad8b.tar.bz2
fengari-cad0eac50b70a280611dd89440a805912ebfad8b.zip
packnum: num can be 32 bits
-rw-r--r--src/lstrlib.js5
-rw-r--r--tests/test-suite/inprogress/tpack.js3
2 files changed, 4 insertions, 4 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index f2518e0..9344794 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -548,9 +548,10 @@ const packint = function(b, n, islittle, size, neg) {
const packnum = function(b, n, islittle, size) {
let dv = new DataView(new ArrayBuffer(size));
- dv.setFloat64(0, n, islittle);
+ if (size === 4) dv.setFloat32(0, n, islittle);
+ else dv.setFloat64(0, n, islittle);
- for (let i = 0; i < 8; i++)
+ for (let i = 0; i < size; i++)
b.push(dv.getUint8(i, islittle));
};
diff --git a/tests/test-suite/inprogress/tpack.js b/tests/test-suite/inprogress/tpack.js
index f081edb..5b70410 100644
--- a/tests/test-suite/inprogress/tpack.js
+++ b/tests/test-suite/inprogress/tpack.js
@@ -400,9 +400,8 @@ test("[test-suite] tpack: overflow in packing)", function (t) {
});
-test("[test-suite] tpack: Lua integer size)", function (t) {
+test("[test-suite] tpack: Lua integer size", function (t) {
let luaCode = `
- for i = 1, sizeLI - 1 do
assert(unpack(">j", pack(">j", math.maxinteger)) == math.maxinteger)
assert(unpack("<j", pack("<j", math.mininteger)) == math.mininteger)
assert(unpack("<J", pack("<j", -1)) == -1) -- maximum unsigned integer