From ed24912b2bfe3666a51760ca4b8e1a29ada12e25 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 6 Feb 2017 22:45:51 +0100 Subject: VARARG --- src/lvm.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/lvm.js') diff --git a/src/lvm.js b/src/lvm.js index e0901c5..98dfa76 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -449,6 +449,25 @@ class LuaVM { break; } case "OP_VARARG": { + let b = i.B - 1; + let n = base - ci.funcOff - cl.p.numparams - 1; + let j + + if (n < 0) /* less arguments than parameters? */ + n = 0; /* no vararg arguments */ + + if (b < 0) { + b = n; /* get all var. arguments */ + base = ci.u.l.base; + ra = this.RA(i); /* previous call may change the stack */ + L.top = ra + n; + } + + for (j = 0; j < b && j < n; j++) + L.stack[ra + j] = L.stack[base - n - j]; + + for (; j < b; j++) /* complete required results with nil */ + L.stack[ra + j] = new TValue(CT.LUA_TNIL, null); break; } case "OP_EXTRAARG": { -- cgit v1.2.3-54-g00ecf