Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- f3afq6kB
- local module = {}
- module.__index = module
- function module:new()
- local self = setmetatable({}, module)
- return self
- end
- function module:parsePacket(packetStr)
- local parsed = self:_split(packetStr,",")
- local args = {}
- local command = parsed[1]
- for i = 2, #parsed, 1 do
- table.insert(args,parsed[i])
- end
- return {
- cmd = command,
- args = args
- }
- end
- function module:compilePacket(cmd,...)
- local args = {...}
- local str = ""
- str = str..cmd
- for _,a in pairs(args) do
- str = str..","..tostring(a)
- end
- print("Str:",str)
- os.sleep(1)
- return str
- end
- function module:_split(str,pattern)
- local outResults = {}
- local theStart = 1
- local theSplitStart, theSplitEnd = string.find( str, pattern, theStart )
- while theSplitStart do
- table.insert( outResults, string.sub( str, theStart, theSplitStart-1 ) )
- theStart = theSplitEnd + 1
- theSplitStart, theSplitEnd = string.find( str, pattern, theStart )
- end
- table.insert( outResults, string.sub( str, theStart ) )
- return outResults
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement