From 3c5cf1687c2da09f56ca1de340e5ada2119efca9 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sat, 11 Feb 2017 17:11:56 +0100 Subject: No more LuaVM class, moved functions around --- src/lfunc.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/lfunc.js') diff --git a/src/lfunc.js b/src/lfunc.js index e9ec377..77eb853 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -49,7 +49,47 @@ class UpVal { } +const findupval = function(L, level) { + let pp = L.openupval; + + while(pp !== null && pp.v >= level) { + let p = pp; + + if (p.v === level) + return p; + + pp = p.u.open.next; + } + + let uv = new UpVal(); + uv.refcount = 0; + uv.u.open.next = pp; + uv.u.open.touched = true; + + pp = uv; + + uv.v = level; + + // Thread with upvalue list business ? lfunc.c:75 + + return uv; +} + +const luaF_close = function(L, level) { + while (L.openupval !== null && L.openupval.v >= level) { + let uv = L.openupval; + assert(uv.isopen()); + L.openupval = uv.u.open.next; /* remove from 'open' list */ + if (uv.refcount > 0) { + uv.value = L.stack[uv.v]; + uv.v = null; + } + } +} + module.exports = { Proto: Proto, - UpVal: UpVal + UpVal: UpVal, + findupval: findupval, + luaF_close: luaF_close }; \ No newline at end of file -- cgit v1.2.3-54-g00ecf