我想知道命令行中的用户何时按下 control-c 以便我可以保存一些内容。
我该怎么做呢?我看过但还没有真正看到任何东西。
注意:我对lua有点熟悉,但不是专家。我主要使用 lua 来使用 Torch 库(http://torch.ch/ http://torch.ch/)
实施SIGINT https://en.wikipedia.org/wiki/Unix_signal#SIGINT使用优秀的处理程序很简单luaposix https://luarocks.org/modules/gvvaughan/luaposix图书馆:
local signal = require("posix.signal")
signal.signal(signal.SIGINT, function(signum)
io.write("\n")
-- put code to save some stuff here
os.exit(128 + signum)
end)
请参阅posix信号 https://luaposix.github.io/luaposix/modules/posix.signal.html模块的 API 文档以获取更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)