[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Calling a function on exit
- From: Jamie Webb <j@...>
- Date: Thu, 10 Jun 2004 01:05:37 +0100
On Thursday 10 June 2004 00:56, Bernhard Bliem wrote:
> Hello,
>
> I've written a little wrapper to use SDL from within Lua scripts. When I
> use SDL with C, I usually call atexit(SDL_Quit) after I initialized it.
> I have to call SDL_Quit on exit, because bad things could happen if I
> don't. However, since I initialize SDL in Lua, I have to make sure SDL_Quit
> (i.e. my wrapper function for it) gets called whenever the chunk
> execution ends. If there is an error in my script and it aborts, the
> program terminates without calling SDL_Quit. Is there some kind of
> "atexit" function for Lua? I have looked at hooks, but they don't seem
> to be made for this purpose. Unfortunately it is not an option to check
> if SDL_Quit has to be called by the interpreter after the script
> execution has ended.
Put your program body inside a function and then run it with the pcall library
function? When the call returns, you can call SDL_Quit, and then propagate
the error if there was one. That doesn't help if your program could abort by
some means other than the Lua error mechanism of course, in which case your
only option is probably to write C code to call atexit.
-- Jamie Webb