lua-users home
lua-l archive

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



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 functions:
- lua_pushboolean
- lua_pushcclosure
- lua_pushcfunction
- lua_pushfstring
- lua_pushinteger
- lua_pushlightuserdata
- lua_pushliteral
- lua_pushlstring
- lua_pushnil
- lua_pushnumber
- lua_pushstring
- lua_pushthread
- lua_pushvalue
- lua_pushvfstring

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.

Cheers,
 drj