Search code examples
lualove2dtermination

Lua-Love program not closing devices as I expect it to


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?


Solution

  • 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.