在windows上的命令提示符上运行lua脚本时输入输入
问题描述:
我有这个IRC bot,允许您在机器人运行时输入机器人命令。该机器人是在卢阿,并使用插座,使机器人采取的命令,这里是该脚本:在windows上的命令提示符上运行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”只是冻结它,直到你终止它 – Alexwall
你的脚本等待一个传入的连接出现(使用阻塞调用接受()()'),然后(在“连接!”字符串显示后)它允许您从键盘发送字符串作为响应。某些软件必须连接到您的套接字(在端口1337上)。 –