lua-users home
lua-l archive

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

> 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

It is implemented exaclty like this, except that it does not have the
printfs. (But it works with the printfs too.) The segmentation fault
probably is being caused by something else. (Maybe some finalizer?)

Hint: the module finalizer for the dynamic library unloads it. So the
problem may be the return to the C code, because it is not there anymore.
(The standard libraries are not loaded through loadlib, so they are
not unloaded by finalizers.)

-- Roberto