[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Creating a lua extension from a recursive C function
- From: Peter Cawley <lua@...>
- Date: Sun, 8 May 2011 11:34:49 +0100
On Sun, May 8, 2011 at 5:53 AM, Emmanuel Oga <emmanueloga@gmail.com> wrote:
> For luajit, the lua stack dies when it reaches about 2**16 tables in
> it (65485 precisely). For lua, in the other hand, the program just
> halts at the iteration 876 without any error, and I need to kill it
> with Ctrl+C (weird).
In PUC-Rio Lua 5.1, the stack for a C function is limited to 8000
members, and this limit is raised to 1000000 in 5.2. There are two
stated reasons for this limit:
1) The limit needs to be less than -LUA_REGISTRYINDEX as otherwise
negative indicies would have ambiguous meanings.
2) It stops C functions from consuming unlimited stack space.
In order to reach this limit, you need to call lua_checkstack. This
will grow the stack by the given amount, or return false if doing so
would go over the 8000 limit (in 5.1, it can also throw a memory error
if the allocator function fails to realloc the stack). If you want to
continue recursing when lua_checkstack returns false, then make sure
that you have enough stack space to perform a call, then do lua_call
on yourself to create a new stack frame.