lua-users home
lua-l archive

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

On 2-Nov-06, at 9:39 PM, Glenn Maynard wrote:

Anyhow, a "lua_checkfunctionenv(L)" function to throw an error if L is
not in a Lua C call could prevent "didn't call through Lua" from being a
lurking bug.

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.

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 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() */