lua-users home
lua-l archive

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


On Wed, Jul 29, 2009 at 3:54 PM, King, Mike<MKing@klmicrowave.com> wrote:
> The script runs in a Windows console window.  What should happen when someone closes the window?  I don't believe Lua has a way to hook the TERM signal.  How can I call Close() or Quit()?

I would use the undocumented newproxy function to create a global
userdata and attach a __gc handler to be called when Lua closes:

C:\Users\Peter>lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> _X = newproxy(true)
> getmetatable(_X).__gc = function() print "Goodbye" end
>
Goodbye
^C