Advertisement
Le_JuiceBOX

[Module] netLib.lua

Jan 22nd, 2025 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. -- f3afq6kB
  2. local module = {}
  3. module.__index = module
  4.  
  5. function module:new()
  6.     local self = setmetatable({}, module)
  7.  
  8.     return self
  9. end
  10.  
  11. function module:parsePacket(packetStr)
  12.     local parsed = self:_split(packetStr,",")
  13.     local args = {}
  14.     local command = parsed[1]
  15.  
  16.     for i = 2, #parsed, 1 do
  17.         table.insert(args,parsed[i])
  18.     end
  19.     return {
  20.         cmd = command,
  21.         args = args
  22.     }
  23. end
  24.  
  25. function module:compilePacket(cmd,...)
  26.     local args = {...}
  27.     local str = ""
  28.     str = str..cmd
  29.     for _,a in pairs(args) do
  30.         str = str..","..tostring(a)
  31.     end
  32.     print("Str:",str)
  33.     os.sleep(1)
  34.     return str
  35. end
  36.  
  37. function module:_split(str,pattern)
  38.  
  39.     local outResults = {}
  40.     local theStart = 1
  41.     local theSplitStart, theSplitEnd = string.find( str, pattern, theStart )
  42.  
  43.     while theSplitStart do
  44.         table.insert( outResults, string.sub( str, theStart, theSplitStart-1 ) )
  45.         theStart = theSplitEnd + 1
  46.         theSplitStart, theSplitEnd = string.find( str, pattern, theStart )
  47.     end
  48.  
  49.     table.insert( outResults, string.sub( str, theStart ) )
  50.     return outResults
  51. end
  52.  
  53.  
  54. return module
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement