Created
June 28, 2010 02:16
-
-
Save jsimmons/455360 to your computer and use it in GitHub Desktop.
lua irc parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse(line) | |
local prefix | |
if line:sub(1,1) == ":" then | |
local space = line:find(" ") | |
prefix = line:sub(2, space-1) | |
line = line:sub(space) | |
end | |
local colonsplit = line:find(":") | |
local last | |
if colonsplit then | |
last = line:sub(colonsplit+1) | |
line = line:sub(1, colonsplit-2) | |
end | |
local params = {} | |
local cmd | |
for arg in line:gmatch("(%S+)") do | |
if not cmd then | |
cmd = arg | |
else | |
table.insert(params, arg) | |
end | |
end | |
table.insert(params, last) | |
return prefix, cmd, params | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment