[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to terminate lua script correctly?
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Wed, 26 Sep 2012 12:33:21 +0100
2012/9/26 Булычев Михаил <mbul@arqa.ru>:
> lua_close(L) throw exception when LUA is in C-function.
> and it seems to me that it leads to stack curruption.
I'm assuming that you have embedded Lua in a C application, and you
have called lua_(p)call to execute some Lua code that in turns
executed one of your lua_CFunction-s. If your setup is different
please provide more details.
When you are currently running a lua_CFunction through the Lua
interpreter, it means that in the C call stack there are some
functions currently running that are using the Lua state that you're
trying to close (typically at least one of
lua_call/lua_pcall/lua_resume, and more internal Lua functions). If
you close it this will lead to problems as soon as you return control
from your lua_CFunction.
Instead you need to first make sure no C code from the Lua interpreter
is in your C stack. One way to do that is to throw an error by calling
lua_error. If the error is not caught it will propagate down the call
stack and the interpreter will give back control to your root C code,
which will then be able to call lua_close safely.