[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_checkstack and luaL_checkstack
- From: David Jones <drj@...>
- Date: Thu, 11 Sep 2008 10:55:08 +0100
On 11 Sep 2008, at 10:32, Aladdin Lampé wrote:
Thank you Patrick.
If I understand correctly, this means that I should first have a
call to luaL_checkstack() each time I use one of the following
Is there any way of telling the Lua interpreter once-for-all to
grow the stack "when needed", "if possible" and "with a specified
message in case of error" instead of a segmentation fault?
No, but it's rarely needed. Whenever Lua calls C it ensures that
there are at least 20 (or LUA_MINSTACK) slots available on the Lua
stack for your C code to use. Therefore if your C code doesn't push
more than 20 items, you'll be fine. If your C code does push more
than 20 items, but you can get some bound on the number, then you can
check once at the beginning of the C function that you have enough
space on the stack.
You only need to repeatedly call checkstack if you have a C function
that uses an amount of Lua stack that grows without bound (for
example, a loop that pushes lots of strings onto the stack, the
concatenates them in one go at the end of the loop). Such cases are
rare, and there are usually better ways of doing it.