lua-users home
lua-l archive

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


On Thu, Nov 02, 2006 at 10:19:49PM -0500, Rici Lake wrote:
> It's not going to lurk, by the way. In my experience, it simply 
> segfaults when you call luaopen_io. It might be nice to have a better 
> error message :) but I don't believe that it will leave any sort of 
> lurking poisoned chalice about. I could be wrong, though... I haven't 
> tested it on more than a few systems, and that accidentally.

This did lurk for me; I only noticed this when I read the earlier
message and noticed the API change from 5.0 that I'd overlooked
in the change list.

I don't load the I/O library, since all I/O goes through my own
functions (to use the engine's VFS, to let go of my monolithic
Lua lock while the file access is taking place so other threads
can use Lua in the meantime, etc).

> If you just use luaL_openlibs() from linit.c, customising the library 
> list according to your needs, then you avoid the whole problem. (Or if 
> you create a custom version which accepts a luaL_Reg structure as a 
> second parameter.) Assuming that the library writers don't follow my 
> advice and do pollute the global namespace with their libraries.

I'd prefer to open the libraries I want, rather than load them all and
then go back and remove the ones I don't want, so it's clear what's
being loaded.  If I don't want the debug and I/O libraries loaded, it
seems better to not load them in the first place.

> I think the following will implement the function you're looking for:
> 
> lua_Debug ar;
> if (lua_getstack(L, 0, &ar) = 0) {
>   printf("No call frame available");
>   exit(1);  /* Can't call lua_error() */
> }

lua_error should work, ending up in the panic function.  (That won't
print an error if no panic function was set, but neither would any
other errors, eg. OOM.)

-- 
Glenn Maynard