1

I have the lua love program:

conf-nogui.lua (is called within the conf.lua to not display a GUI):

function love.conf(t)
  print("Switch GUI window off")
  t.window = nil
end

main.lua:

-- UDP Server
local socket = require("socket")
require("utils")
require("globals")

-- Module Scoped Variables (or as I like to call them local-globals)
local udp

-- Startup
function love.load()
  print("load")
  udp = socket.udp()
  udp:setsockname("*", SERVER_PORT)
  udp:settimeout(0)
  print("load done")
end

-- Scheduler 
function love.update()
  -- Check for Rx packets
  local rxDataPacket, ip, port = udp:receivefrom()
  if rxDataPacket then
    -- print the packet as hex
    printStringAsHex("Rx from " .. ip .. ":" .. port .. " ", rxDataPacket)    
    -- Turn string into an array for editing
    local rxByteArray = stringToArray(rxDataPacket)
    -- Edit values
    rxByteArray[5] = 0x66 
    -- Turn back into string
    local txDataPacket = arrayToString(rxByteArray)  
    -- Reply with the result
    udp:sendto(txDataPacket, ip, port)
  end
end

-- shutdown
function love.quit()
  print("Closing connection...")
  -- done with client, close the object
  udp:close()
  print("connection close done")
end

There are some other files that are included, but I don't think are necessary for this question.

I run the program on the command line like this: love . --console I am in the correct directory so "." is the current dir.

This little program runs exactly as expected until I close it. It is running on the windows command line, so I use ctrl+c to terminate the program (It is not running a GUI - see the conf file).

When the program closes this is what I see on in the command prompt:

AL lib: (EE) alc_cleanup: 1 device not closed

So what I don't understand is why my function love.quit() is not called. I don't see my debug Closing connection.... Is it because ctrl+C terminates the program too "harshly"? - is there another way to terminate the program?

code_fodder
  • 15,263
  • 17
  • 90
  • 167

1 Answers1

1

It appears to me that love.quit is only called when the quit event is raised (i.e. love.event.quit())

When Ctrl+c is pressed, cmd is given a SIGINT, which causes the current program(s) running in the instance to stop.

What technically happens when you press Control-C is that all programs running in the foreground in your current terminal (or virtual terminal) get the signal SIGINT sent.1

So, I guess LOVE catches that input, and doesn't choose to raise the quit event, but forcefully shuts down instead.

Check this question out for more help.

Community
  • 1
  • 1
Liam Mueller
  • 1,360
  • 2
  • 10
  • 17
  • hmm.... damn, that is what I feared. I hoped the love framework somehow handled that. Do you know how I can handle a SIGINT in lua? – code_fodder Aug 17 '16 at 14:06
  • ok, thanks - I understood that from your first post, what I want to know how to handle this, or how to end the program "correctly" - bearing in mind I have no GUI.... I tried reading the stdin, but that appears to be a blocking call, and I don't want my program to block.. – code_fodder Aug 17 '16 at 14:19
  • @code_fodder As far as I can tell, there isn't a way to, at least without editing LOVE's C files and rewriting their behavior when encountering SIGINT's. – Liam Mueller Aug 17 '16 at 14:30
  • ok fair enough. Its not a big issue for me since it appears to get "garbage collected" anyway : ) Thanks for the info. – code_fodder Aug 17 '16 at 14:44