Search code examples
windowssocketsluairc

Taking inputs while a lua script is running on command prompt on windows


I have this IRC bot that allows you to enter commands for the bot while it is running. The bot is in lua, and uses socket to allow the bot to take commands, here is the script for that:

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

The problem is in command prompt on windows you can not enter anything while something is running in it. So I was wondering if there is any way to still be able to enter commands.


Solution

  • I got it working, turned out I had other bits of code preventing the bot from connecting if it was running on windows