lua-users home
lua-l archive

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


So I've got this program written partly in Lua with a C backend.

Stuff can go wrong at basically any stage. This means I need to raise some sort of exception. I would really like these exceptions to be of a standard type so that third-party code can understand it.

For example: say a function in my C backend runs out of memory. What do I do? Currently I raise a string exception containing a text message describing the problem. *However*, the Lua internals use a different function that raises an error code... presumably so that other bits of Lua can respond to it. Am I allowed to do this? If so, how?

There seems to be nothing in the documentation about what types exceptions are. It just says that they can be of any type, and pretty much leaves it at that (unless I've missed that section).

I also have a related problem: occasionally I need to forcibly terminate the Lua interpreter on my embedded platform. What's the best way of doing that? My current thought is to use a signal-based timer to execute code every, say, second or so that checks a global variable. If set, the signal handler longjmps up to the top level where lua_close() would be called.

Will this clean up all Lua state correctly? Is there any risk on non-signalsafe code such as this:

	FILE* f = fopen(...);
	// f leaks if a signal arrives here!
	lua_pushuserdata(L, f);

If so, I'd have to come up with some other mechanism...

--
David Given
dg@cowlark.com