--- Pack a table
-- Does what you'd expect
-- @param t Table to pack
function lube.bin:pack(t)
local result = ""
for i, v in pairs(t) do
result = result .. self:packvalue(i, v)
end
return result
end
--- Pack a single value
-- Internal, do not use
-- @see lube.bin:pack
function lube.bin:packvalue(i, v)
local id = ""
local typev = type(v)
if typev == "string" then id = "S"
elseif typev == "number" then id = "N"
elseif typev == "boolean" then id = "B"
elseif typev == "userdata" then id = "U"
elseif typev == "function" then
id = "F"
v = string.dump(v)
elseif typev == "nil" then id = "0"
else error("Type " .. typev .. " is not supported by lube.bin") return
end
return tostring(id .. lube.bin.one .. i .. lube.bin.one .. tostring(v) .. lube.bin.null)
end
Please tell me you aren't seriously transmitting commands as strings.