summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-23 14:52:30 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-23 14:52:30 +0200
commit0133e556602950f71747ef518cdaa861fe422b32 (patch)
tree270ebdcb9dd2ad88fb93a913854bcbc3b427336c /src/lapi.js
parent8966842ba72fb1eef351355ead2e8950fd87141a (diff)
downloadfengari-0133e556602950f71747ef518cdaa861fe422b32.tar.gz
fengari-0133e556602950f71747ef518cdaa861fe422b32.tar.bz2
fengari-0133e556602950f71747ef518cdaa861fe422b32.zip
Handle when no upvalue found
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 99b0859..0231597 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -507,26 +507,33 @@ const aux_upvalue = function(L, fi, n) {
const lua_getupvalue = function(L, funcindex, n) {
let up = aux_upvalue(L, index2addr(L, funcindex), n);
- let name = up.name;
- let val = up.val;
- if (name)
+ if (up) {
+ let name = up.name;
+ let val = up.val;
+
L.stack[L.top++] = new TValue(val.type, val.value);
- return name.value;
+
+ return name.value;
+ }
+ return null;
};
const lua_setupvalue = function(L, funcindex, n) {
let fi = index2addr(L, funcindex);
assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack");
let aux = aux_upvalue(L, fi, n);
- let name = aux.name;
- let val = aux.val;
- if (name) {
+ if (aux) {
+ let name = aux.name;
+ let val = aux.val;
+
L.top--;
// TODO: what if it's not a pure TValue (closure, table)
val.type = L.stack[L.top].type;
val.value = L.stack[L.top].value;
+
+ return name.value;
}
- return name.value;
+ return null;
};
const lua_newtable = function(L) {