lua-users home
lua-l archive

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


	Hi Bernhard,

> 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.
	I don't know SDL not even how your wrapper works, but I've made
some Lua libraries that have similar problems.  A clean way to do that
is to create a userdata (it will look like a Lua object) which exports
your functions (its methods) and define a metatable for it.  The __gc
field of the metatable could store a function that calls SDL_Quit.

	Tomas