aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lvm.js34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/lvm.js b/src/lvm.js
index 1f78dd3..e796e4e 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -607,20 +607,7 @@ const luaV_execute = function(L) {
}
case OCi.OP_CLOSURE: {
let p = cl.p.p[i.Bx];
- let nup = p.upvalues.length;
- let uv = p.upvalues;
- let ncl = new lobject.LClosure(L, nup);
- ncl.p = p;
-
- L.stack[ra] = new lobject.TValue(CT.LUA_TLCL, ncl);
-
- for (let i = 0; i < nup; i++) {
- if (uv[i].instack)
- ncl.upvals[i] = lfunc.luaF_findupval(L, base + uv[i].idx);
- else
- ncl.upvals[i] = cl.upvals[uv[i].idx];
- ncl.upvals[i].refcount++;
- }
+ pushclosure(L, p, cl.upvals, base, ra); /* create a new one */
break;
}
case OCi.OP_VARARG: {
@@ -948,6 +935,25 @@ const luaV_shiftl = function(x, y) {
}
};
+/*
+** create a new Lua closure, push it in the stack, and initialize
+** its upvalues.
+*/
+const pushclosure = function(L, p, encup, base, ra) {
+ let nup = p.upvalues.length;
+ let uv = p.upvalues;
+ let ncl = new lobject.LClosure(L, nup);
+ ncl.p = p;
+ L.stack[ra] = new lobject.TValue(CT.LUA_TLCL, ncl);
+ for (let i = 0; i < nup; i++) {
+ if (uv[i].instack)
+ ncl.upvals[i] = lfunc.luaF_findupval(L, base + uv[i].idx);
+ else
+ ncl.upvals[i] = encup[uv[i].idx];
+ ncl.upvals[i].refcount++;
+ }
+};
+
const cvt2str = function(o) {
return o.ttisnumber();
};