summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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