From be73f72fcc944a8ebae2c60d2ce84139acb011b9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 18 Jun 2019 16:52:22 -0300 Subject: New function 'setCstacklimit' Added new functions to dynamically set the C-stack limit ('lua_setCstacklimit' in the C-API, 'debug.setCstacklimit' in Lua). --- ldo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ldo.c') diff --git a/ldo.c b/ldo.c index 0ad3120b..1a327ffd 100644 --- a/ldo.c +++ b/ldo.c @@ -139,7 +139,8 @@ l_noret luaD_throw (lua_State *L, int errcode) { int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { - l_uint32 oldnCcalls = L->nCcalls + L->nci; + global_State *g = G(L); + l_uint32 oldnCcalls = g->Cstacklimit - (L->nCcalls + L->nci); struct lua_longjmp lj; lj.status = LUA_OK; lj.previous = L->errorJmp; /* chain new error handler */ @@ -148,7 +149,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { (*f)(L, ud); ); L->errorJmp = lj.previous; /* restore old error handler */ - L->nCcalls = oldnCcalls - L->nci; + L->nCcalls = g->Cstacklimit - oldnCcalls - L->nci; return lj.status; } @@ -671,7 +672,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, else if (L->status != LUA_YIELD) /* ended with errors? */ return resume_error(L, "cannot resume dead coroutine", nargs); if (from == NULL) - L->nCcalls = LUAI_MAXCSTACK; + L->nCcalls = CSTACKTHREAD; else /* correct 'nCcalls' for this thread */ L->nCcalls = getCcalls(from) + from->nci - L->nci - CSTACKCF; if (L->nCcalls <= CSTACKERR) -- cgit v1.2.3-55-g6feb