summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 11:31:05 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 11:31:05 +0100
commitaee0f65dea0456635e96b4496f6597188526e647 (patch)
tree3afcb057b08b3a6b7ce091111e7be0db236ff3f4
parenteb838303ed7c3ddc2da0665ed0b5ca3843bf7b96 (diff)
downloadfengari-aee0f65dea0456635e96b4496f6597188526e647.tar.gz
fengari-aee0f65dea0456635e96b4496f6597188526e647.tar.bz2
fengari-aee0f65dea0456635e96b4496f6597188526e647.zip
[Parsing tests] SETTABUP, GETTABUP
-rw-r--r--src/lcode.js8
-rw-r--r--src/lua.js4
-rw-r--r--tests/lexparse.js38
3 files changed, 44 insertions, 6 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 64e890e..9380d1a 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -487,12 +487,12 @@ 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].ttype() === v.ttype() && f.k[idx].value === v.value)
- return idx; /* reuse index */
+ if (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 */
let k = fs.nk;
- fs.ls.h.__newindex(fs.ls.h, key, k);
+ fs.ls.h.__newindex(fs.ls.h, key, new TValue(CT.LUA_TNUMINT, k));
f.k[k] = v;
fs.nk++;
return k;
@@ -616,7 +616,7 @@ const luaK_dischargevars = function(fs, e) {
op = OpCodesI.OP_GETTABUP; /* 't' is in an upvalue */
}
e.u.info = luaK_codeABC(fs, op, 0, e.u.ind.t, e.u.ind.idx);
- e.k = OpCodesI.VRELOCABLE;
+ e.k = ek.VRELOCABLE;
break;
}
case ek.VVARARG: case ek.VCALL: {
diff --git a/src/lua.js b/src/lua.js
index ef5385c..95d0ef8 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -57,8 +57,6 @@ const constant_types = {
LUA_NUMTAGS: 9
};
-const CT = constant_types;
-
constant_types.LUA_TSHRSTR = constant_types.LUA_TSTRING | (0 << 4); /* short strings */
constant_types.LUA_TLNGSTR = constant_types.LUA_TSTRING | (1 << 4); /* long strings */
@@ -69,6 +67,8 @@ constant_types.LUA_TLCL = constant_types.LUA_TFUNCTION | (0 << 4); /* Lua closu
constant_types.LUA_TLCF = constant_types.LUA_TFUNCTION | (1 << 4); /* light C function */
constant_types.LUA_TCCL = constant_types.LUA_TFUNCTION | (2 << 4); /* C closure */
+const CT = constant_types;
+
/*
** Comparison and arithmetic functions
*/
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 50b9c3f..e819c3c 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -606,4 +606,42 @@ test('SETUPVAL, GETUPVAL', function (t) {
"world",
"Program output is correct"
);
+});
+
+
+test('SETTABUP, GETTABUP', function (t) {
+ let luaCode = `
+ t = {}
+
+ t[1] = "hello"
+ t["two"] = "world"
+
+ return t
+ `, L;
+
+ t.plan(3);
+
+ 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_topointer(L, -1).get(0).value,
+ "hello",
+ "Program output is correct"
+ );
+
+ t.strictEqual(
+ lapi.lua_topointer(L, -1).get("two").value,
+ "world",
+ "Program output is correct"
+ );
}); \ No newline at end of file