table.unpack = table.unpack or unpack string.pack = function(...) return love.data.pack("string", ...) end string.unpack = love.data.unpack string.packsize = string.packsize or love.data.getPackedSize -- Lua data types: nil, boolean, number, string, function, userdata, thread, and table. -- Not representable here: function, userdata, thread. format = { --[[ Poppy specific 0x81 = "remoteCall", -- lua specific 0x02 = "shortString", 0x03 = "longString", 0x04 = "nil", 0x05 = "true", 0x06 = "false", 0x07 = "number", -- love2d/poppy specific 0x48 = "colorAlpha", 0x49 = "color"]]-- } format.decodeFunction = function(encoded, index) local nameLength, index = string.unpack(" 255 then encoded = encoded .. "\x03" .. string.pack(":(" }, buildBlocks = { 32, 32, 64, 64, "longHashValueISwear" }, colorWorld = { {nwType = "color", 0.4, 0.4, 0.4 }, {nwType = "color", 0.4, 0.4, 0.4, 0.5}}, slangvariants = { "oy mate", "how ya doing", "sup brooo", "heya", "hey there ma dude" } } print("Running encoder tests...") for name, value in pairs(testCases) do local encoded = format.encodeFunction(name, 3, table.unpack(value)) local name, _, decodedArgs = format.decodeFunction(encoded) local sucess = true for iter= 1, #value do local var = value[iter] if var ~= decodedArgs[iter] and not type(var) == table then sucess = false end end if sucess then print(name .. " suceeded!") else print(name .. " failed.") end end end return format