【问题标题】:Taking inputs while a lua script is running on command prompt on windows在 Windows 上的命令提示符下运行 lua 脚本时接受输入
【发布时间】:2016-06-15 18:36:40
【问题描述】:

我有这个 IRC 机器人,它允许您在机器人运行时输入命令。该机器人在 lua 中,并使用套接字来允许机器人接受命令,这里是它的脚本:

if IRC_RUNNING then error("Can't load that from here") end
print("Line input to IRC bot! ./chan to change who gets message")
local socket = require"socket"
local s = socket.bind("localhost",1337)
s:settimeout(30)
local client = s:accept()
if not client then print("Timeout") return end
print("Connected!")
s:settimeout(0)
client:settimeout(0)
while true do
    local line = io.read("*l")
    if line then
        local r,e = client:send(line.."\n")
        if not r then break end
    end
end

问题是在 Windows 上的命令提示符中,当其中运行某些内容时,您无法输入任何内容。所以我想知道是否有任何方法仍然可以输入命令。

【问题讨论】:

  • 在任何操作系统(包括 Windows)上,io.read("*l") 将等待用户按 Enter。
  • 但这似乎不起作用。运行“lua consolein.lua”只会冻结它,直到你终止它
  • 您的脚本等待传入连接出现(使用对s:accept() 的阻塞调用),然后(在显示“已连接!”字符串之后)它允许您从键盘发送字符串作为响应。某些软件必须连接到您的套接字(在端口 1337 上)。

标签: windows sockets lua irc


【解决方案1】:

我让它工作了,结果发现我有其他代码阻止机器人在 Windows 上运行时连接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    相关资源
    最近更新 更多