【发布时间】: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 上)。