summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lcode.js10
-rw-r--r--src/ljstype.js4
-rw-r--r--tests/lexparse.js30
3 files changed, 38 insertions, 6 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 46b8c74..3c6500d 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -513,8 +513,8 @@ const luaK_stringK = function(fs, s) {
** are no "precision" problems.
*/
const luaK_intK = function(fs, n) {
- let k = new TValue(CT.LUA_TLNGSTR, `${n.value}`);
- let o = new TValue(CT.LUA_TNUMINT, n.value);
+ let k = new TValue(CT.LUA_TLNGSTR, `${n}`);
+ let o = new TValue(CT.LUA_TNUMINT, n);
return addk(fs, k, o);
};
@@ -522,7 +522,8 @@ const luaK_intK = function(fs, n) {
** Add a float to list of constants and return its index.
*/
const luaK_numberK = function(fs, r) {
- return addk(fs, r, r); /* use number itself as key */
+ let o = new TValue(CT.LUA_TNUMFLT, r);
+ return addk(fs, o, o); /* use number itself as key */
};
@@ -530,7 +531,8 @@ const luaK_numberK = function(fs, r) {
** Add a boolean to list of constants and return its index.
*/
const boolK = function(fs, b) {
- return addk(fs, b, b); /* use boolean itself as key */
+ let o = new TValue(CT.LUA_TBOOLEAN, b);
+ return addk(fs, o, o); /* use boolean itself as key */
};
diff --git a/src/ljstype.js b/src/ljstype.js
index a92c8d0..ef4be1d 100644
--- a/src/ljstype.js
+++ b/src/ljstype.js
@@ -15,11 +15,11 @@ const lisspace = function(c) {
};
const lislalpha = function(c) {
- return /^[_a-zA-z]$/.test(c.charAt(0));
+ return /^[_a-zA-Z]$/.test(c.charAt(0));
};
const lislalnum = function(c) {
- return /^[_a-zA-z0-9]$/.test(c.charAt(0));
+ return /^[_a-zA-Z0-9]$/.test(c.charAt(0));
};
module.exports.lisdigit = lisdigit;
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 10c4845..2604e72 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -67,4 +67,34 @@ test('MOVE', function (t) {
"Correct element(s) on the stack"
);
+});
+
+
+test('Binary op', function (t) {
+ let luaCode = `
+ local a = 5
+ local b = 10
+ return a + b, a - b, a * b, a / b, a % b, a^b, a // b, a & b, a | b, a ~ b, a << b, a >> b
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, luaCode, "test", "text");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.deepEqual(
+ L.stack.slice(L.top - 12, L.top).map(e => e.value),
+ [15, -5, 50, 0.5, 5, 9765625.0, 0, 0, 15, 15, 5120, 0],
+ "Program output is correct"
+ );
+
}); \ No newline at end of file