lua-users home
lua-l archive

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

On Wed, Jun 23, 2010 at 01:39:15AM -0600, HyperHacker wrote:

> I'm not sure I understand the first question, but if you want to have
> a C function executed on any error, you can pass it to lua_pcall.

Sorry, but that doesn't help me at all.

Maybe it was too confusing that I presented two completely unrelated questions 
at once. So I try to explain the unsolved problem again in more detail.


I have written an extension module "" (system: GNU/Linux).
This is loaded by the lua script with "require 'lua-akfavatar'". It registers 
a table named "avt" with functions.
So again, there is not a C program that calls a lua script, but the lua 
script calls the C module. That works fine so far.
Now, the module needs some cleanup at the end. It does work when I export
a cleanup function, named "avt.quit()", and the script calls this function
at its end. So far so good. That works.

But it breaks, when the script doesn't call that function, for example
when there is an error in the script, or someone forgets to call that function.
So what I'd like to have is that a function is called automatically when
the script ends - whether it ends with an error or at a normal end.
What I want is something, that "atexit()" is supposed to do. But "atexit()"
doesn't work. I've tried that of course.


Well, I do also have it the other way round: a program that calls lua-scripts.
That works fine. There I use "atexit()". But it would be nice if I could have 
it both ways.

Don't get me wrong. I'm not complaining. I really like Lua!