Is it possible to handle POSIX signals in Love2D? Such as SIGSTOP, SIGCONT, SIGTERM, etc?
I've seen a luaposix library, but I'm still not sure how I'd incorporate it into Love2D's callbacks.
Handling POSIX Signals
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Handling POSIX Signals
You can install and require luaposix, then just call its functions. Distribution is going to be a problem, though, as binary libraries need to be included for all POSIX platforms you intend to support. But if it's for your own use, no problem.
Re: Handling POSIX Signals
Technically, the POSIX requirement is only for one platform, so I'd only need to build one binary library. How does one include and distribute those compiled libraries in the love project?
I'm also not clear on how I would get the game to receive the signal or register the handle. I try the code below and send the STOP signal with the kill command, but nothing happens. It just... well, stops just like it would when pressing ctrl-z.
Code: Select all
function pause(signo)
print("Pause")
end
function love.load()
M = require 'posix.signal'
M.signal(SIGSTOP, pause)
end
Re: Handling POSIX Signals
For which platform? Linux? Android? MacOS? iOS? All four can handle POSIX signals. Basically, all the platforms Löve supports except Windows.
For Linux, they need to be available somewhere in package.cpath, and if they are inside a .love file, be copied to the save directory then loaded from there. For the other systems, I don't know.
From signal(7): "The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored". If I trap SIGCONT and interrupt, then resume, it prints "Pause".
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Handling POSIX Signals
What do you plan to use it for? Does the love.quit callback at least partially cover your use case?
Re: Handling POSIX Signals
I'm under NDA and not sure if I can go into detail other than to say that it has been recommended, though not explicitly required, that my project be able to handle SIGSTOP, SIGCONT and SIGTERM.
However, I think in my case I may be able to go without handling those.
Thanks for the help folks!
However, I think in my case I may be able to go without handling those.
This is a Linux platform.
By save directory, you mean what would normally be ~/.love/game_id/ ?
Are you saying you tried the code sample with SIGCONT and it worked for you? I'll give that a try. Even though I may not need to worry abou this now, I'm still pretty curious.
Thanks for the help folks!
Re: Handling POSIX Signals
I mean whatever love.filesystem.getSaveDirectory() returns, or any subdirectory inside that. I think it defaults to ~/.local/share/love/game_id/ on Linux.
Note I haven't tried this, I've just seen it mentioned in this forum at some point.
Indeed, just changing your example to use SIGCONT instead of SIGSTOP:
Code: Select all
$ love11 .
^Z
[1]+ Stopped love11 .
$ fg
love11 .
Pause
$
Note SIGTSTP can also be handled, and that's the one received when you issue a ^Z. I've also tried handling it and it works.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests