From 662d01cc30a60a5ef63f489570c3cdaf3f35b9ce Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 12 May 2017 15:05:33 +1000 Subject: src/lstate.js: Implement freestack(), call from lua_close Work towards https://github.com/giann/fengari/commit/354d659f577fc27969784400c8c1e6090756da7b#commitcomment-21975897 --- src/lstate.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/lstate.js b/src/lstate.js index 664ef27..020971a 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -75,6 +75,11 @@ class global_State { } +const luaE_freeCI = function(L) { + let ci = L.ci; + ci.next = null; +}; + const stack_init = function(L1, L) { L1.stack = new Array(BASIC_STACK_SIZE); // TODO: for now we don't care about the stack size L1.top = 0; @@ -88,6 +93,12 @@ const stack_init = function(L1, L) { L1.ci = ci; }; +const freestack = function(L) { + L.ci = L.base_ci; + luaE_freeCI(L); + L.stack = null; +}; + /* ** Create registry table and its predefined values */ @@ -158,6 +169,7 @@ const lua_newstate = function() { const close_state = function(L) { lfunc.luaF_close(L, L.stack); /* close all upvalues for this thread */ + freestack(L); }; const lua_close = function(L) { -- cgit v1.2.3-70-g09d2