summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lcode.js2
-rw-r--r--tests/lexparse.js34
2 files changed, 35 insertions, 1 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 9380d1a..9fb32e2 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -487,7 +487,7 @@ const addk = function(fs, key, v) {
let idx = fs.ls.h.__index(fs.ls.h, key); /* index scanner table */
if (idx && !idx.ttisnil()) { /* is there an index there? */
/* correct value? (warning: must distinguish floats from integers!) */
- if (f.k[idx.value].ttype() === v.ttype() && f.k[idx.value].value === v.value)
+ if (idx.value < fs.nk && f.k[idx.value].ttype() === v.ttype() && f.k[idx.value].value === v.value)
return idx.value; /* reuse index */
}
/* constant not found; create a new entry */
diff --git a/tests/lexparse.js b/tests/lexparse.js
index e819c3c..500ef76 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -644,4 +644,38 @@ test('SETTABUP, GETTABUP', function (t) {
"world",
"Program output is correct"
);
+});
+
+
+test('SELF', function (t) {
+ let luaCode = `
+ local t = {}
+
+ t.value = "hello"
+ t.get = function (self)
+ return self.value
+ end
+
+ return t:get()
+ `, 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.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "hello",
+ "Program output is correct"
+ );
}); \ No newline at end of file