lua-users home
lua-l archive

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


On Wed, Oct 07, 2009 at 07:54:49AM -0300, Luiz Henrique de Figueiredo wrote:
> > luacov does a trick with gc and a temporary file to get its save_stats  
> > called on exit:
> ...
> > This doesn't seem to happen on os.exit() - I guess os.exit() forces  
> > shutdown without gc?
> 
> This will be addressed in Lua 5.2: os.exit will have an option to
> close the state (thus calling gc).

Can I ask how this is implemented? I tried writing a C replacement for
os.exit like this:

/* based on loslib.c */
static int os_exit (lua_State *L) {
  int ret = luaL_optint(L, 1, EXIT_SUCCESS);
  /* if optional arg[2] is true, close this lua_State before exiting */
  if (lua_toboolean(L, 2)) {
	  printf("get ready\n");
	  lua_close(L);
	  printf("ok so far\n");
  }
  exit(ret);
}

However, if I then run:
$ lua -l os_exit_replacement_library -e "os.exit(1,true)"

I get:

get ready
Segmentation fault

Is it not possible to call lua_close in such a context? Or is the segfault coming because once L is closed it's no longer possible to return to my os_exit function? (Why should that be, it's just an ordinary C return, isn't it?)

-- 
Profjim
profjim@jimpryor.net