-2

I have been doing research on how to detect when the user has closed/terminated a program. Example: when the user clicks the button to close the program or presses ^C or ^Z, can I (quickly) do something like write contents to a file.

ntnick17
  • 3
  • 2
  • http://stackoverflow.com/questions/3912296/lua-shutdown-end-of-the-program-execution-callback – PeterMmm Sep 08 '14 at 06:04
  • 1
    [Don't ask the same question](http://stackoverflow.com/questions/25713724/detect-when-program-is-closed-in-lua) again. Instead, improve your previous question. – Yu Hao Sep 08 '14 at 06:11

1 Answers1

0

Unfortunately Lua does not contain this type of functionality by default, meaning you would have to use an additional C module to hook up with your Lua engine in order to deliver this.

That said, there was another question similar to this. I suggest you search on your preferred search engine before you ask such question on Stack Overflow.

Lua is predicated on extreme portability. As such it's based on supplying, essentially, only that which is available in ANSI C in terms of capabilities. (I think the sole exception to that is dynamic linking which is a non-ANSI feature not available on all platforms, but is so useful that they've put it in for many.)

ANSI C doesn't provide keypress functionality so the default Lua library doesn't either.

That being said, the LuaRocks repository might lead you to a library with this capability. For example it could be that ltermbox, found on the LuaRocks page there, has the functionality you need. (You'll probably have to remove the bits you don't want, mind.) There may be other libraries available. Go digging.

Failing that, the whole point of Lua is extensibility. It's an extensible extension language. It's not actually all that hard to hand-roll your own extension that provides the functionality you want.

Source: https://stackoverflow.com/a/5690847/3264799

Community
  • 1
  • 1
ascx
  • 473
  • 2
  • 13
  • @ntnick17 Make sure you accept the answer which helped you the most, this way other people know the question has been answered and no longer requires an answer, unless there is something radical to change. Of course, if there are no answers that yet satisfy you, you may keep the question open. (http://stackoverflow.com/help/someone-answers) – ascx Sep 08 '14 at 07:31