lua-users home
lua-l archive

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



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?

Thank you!
Aladdin

On Thu, Sep 11, 2008 at 3:09 AM, Aladdin Lampé  hotmail.fr> wrote:
>
>
> Hi!
> In some C source interfacing with Lua I found lots of:
>
> lua_checkstack(L, nb);
>
> with no return value check. Is it of any use or can I either
> - remove them?
> - use luaL_checkstack(L, nb, "out of memory"); instead?
>
> What would you recommend? Is it really necessary to check the stack each time you push something to it or
will the VM raise the "out of memory" error anyway?
>
> Thank you!
> Aladdin

You should check the return value. Not doing so can lead to you
pushing items over the stack top causing a segmentation fault.
luaL_checkstack is the best option IME.

Cheers,

--
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant



_________________________________________________________________
Installez gratuitement les 20 émôticones Windows Live Messenger les plus fous ! Cliquez ici !
http://www.emoticones-messenger.fr/