summaryrefslogtreecommitdiff
path: root/src/lfunc.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-02-11 17:11:56 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-11 21:33:14 +0100
commit3c5cf1687c2da09f56ca1de340e5ada2119efca9 (patch)
tree630bd9c476f050ea5e5cc367cb8767265b9172e2 /src/lfunc.js
parent5284fd99c801dcde51094ca68d2eae6c56aaa3f0 (diff)
downloadfengari-3c5cf1687c2da09f56ca1de340e5ada2119efca9.tar.gz
fengari-3c5cf1687c2da09f56ca1de340e5ada2119efca9.tar.bz2
fengari-3c5cf1687c2da09f56ca1de340e5ada2119efca9.zip
No more LuaVM class, moved functions around
Diffstat (limited to 'src/lfunc.js')
-rw-r--r--src/lfunc.js42
1 files changed, 41 insertions, 1 deletions
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