summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lapi.js b/src/lapi.js
index cea0568..79c666c 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -91,8 +91,20 @@ const index2addr_ = function(L, idx) {
};
const lua_checkstack = function(L, n) {
+ let res;
let ci = L.ci;
- let res = L.stack.length < luaconf.LUAI_MAXSTACK;
+ assert(n >= 0, "negative 'n'");
+ if (L.stack.length - L.top > n) /* stack large enough? */
+ res = true;
+ else { /* no; need to grow stack */
+ let inuse = L.top + lstate.EXTRA_STACK;
+ if (inuse > luaconf.LUAI_MAXSTACK - n) /* can grow without overflow? */
+ res = false; /* no */
+ else { /* try to grow stack */
+ ldo.luaD_growstack(L, n);
+ res = true;
+ }
+ }
if (res && ci.top < L.top + n)
ci.top = L.top + n; /* adjust frame top */