lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

If I'm recursing deeply (pushing a couple parameters on the stack each
time), and I'm checking lua_gettop(..) each time through, I presume it will
be larger each time?  That is, lua_gettop reveals the total stack size, not
just the size of the current recursive frame?


-----Original Message-----
[]On Behalf Of Rici Lake
Sent: Tuesday, August 30, 2005 2:56 PM
To: Lua list
Subject: Re: stack overflow?

On 30-Aug-05, at 4:24 PM, Brent Arias wrote:

> How big can the lua stack get, before it overflows?

Assuming you have enough memory, the limitations are the values in
src/llimits.h (5.0.2) or src/luaconf.h (5.1)

LUA_MAXCALLS determines the maximum number of call frames. In 5.0.2 it
was a short, but it seems that in 5.1 it's an int, so you could set it
a lot higher if you wanted to.

LUA_MAXCCALLS is the maximum number of recursive entries to the VM
itself; in effect, the maximum number of C (as opposed to Lua) call
frames. It's much smaller. I think that 10 would suffice for 99.9% of
Lua programs, but the default value is a bit more than that.

The maximum size of a C stack frame is controlled by LUA_MAXCSTACK, by
default 2048. C programs need to use lua_checkstack() if they are
planning on using more than LUA_MINSTACK slots (that one is defined in

By the way, the largest possible Lua stack frame is 255 slots.
(LUA_MAXSTACK + LUA_EXTRA_STACK, but don't change these!) The actual
size of a stack frame used by a Lua function is set at compile time to
the actual number of slots needed; this rarely exceeds 20 and is often
much smaller, like 4.

If you're asking because you want to have very deep recursion, you
should increase LUA_MAXCALLS, remembering that in 5.0.2 it's a short.
If you're asking because you want to protect yourself from deep
recursion, then you might want to decrease it.

>   Also, is there a
> hard-limit restriction of how many coroutines can be created/used?  Is
> there
> a limit or restriction on how many coroutines may be simultaneously
> yielded?

It would basically be a memory limit.