Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua Love程序没有像我预期的那样关闭设备_Lua_Love2d_Termination - Fatal编程技术网

Lua Love程序没有像我预期的那样关闭设备

Lua Love程序没有像我预期的那样关闭设备,lua,love2d,termination,Lua,Love2d,Termination,我有lua love计划: conf-nogui.lua(在conf.lua中调用以不显示GUI): 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.

我有lua love计划:

conf-nogui.lua(在conf.lua中调用以不显示GUI):

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
这里还包括一些其他的文件,但我认为对于这个问题没有必要

我在命令行上这样运行程序:
love--console
我在正确的目录中,因此“.”是当前目录

在我关闭它之前,这个小程序完全按照预期运行。它在windows命令行上运行,因此我使用ctrl+c终止程序(它没有运行GUI-请参阅conf文件)

当程序关闭时,我在命令提示符中看到:

AL-lib:(EE)alc\u清理:1个设备未关闭


所以我不明白的是为什么我的
函数love.quit()
没有被调用。我没有看到我的调试
正在关闭连接…
。是不是因为ctrl+C终止程序太“苛刻”?-是否有其他终止程序的方法?

在我看来,只有在引发
quit
事件时才会调用
love.event.quit()

当按下Ctrl+c时,cmd将被赋予一个SIGINT,这将导致实例中运行的当前程序停止

从技术上讲,当您按下Control-C时,当前终端(或虚拟终端)中前台运行的所有程序都会收到信号SIGINT

因此,我猜LOVE会捕捉到输入,不会选择引发
quit
事件,而是强制关闭


查看此文件以获得更多帮助。

hmm。。。。该死,这就是我害怕的。我希望爱情框架能以某种方式解决这个问题。你知道我如何处理lua中的SIGINT吗?好的,谢谢-我从你的第一篇文章中理解了,我想知道如何处理这个,或者如何“正确”结束程序-记住我没有GUI。。。。我试着读取标准输入,但这似乎是一个阻塞调用,我不想让我的程序阻塞。@code\u foeder据我所知,至少在不编辑LOVE的C文件和重写它们在遇到SIGINT时的行为的情况下,是没有办法的。这对我来说并不是什么大问题,因为它似乎被“垃圾收集”了:)谢谢你的信息。
-- 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