From d74a505d406faf276a265beaf8925d6e8ff9cec0 Mon Sep 17 00:00:00 2001 From: jussi Date: Fri, 3 Nov 2023 23:12:55 +0200 Subject: Compress/decompress and Encode/Decode DataBase64. --- examples/compress_data/main.lua | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/compress_data/main.lua (limited to 'examples/compress_data/main.lua') diff --git a/examples/compress_data/main.lua b/examples/compress_data/main.lua new file mode 100644 index 0000000..bf6c162 --- /dev/null +++ b/examples/compress_data/main.lua @@ -0,0 +1,43 @@ +local textColor = RL.BLACK +local text = "Put data here" +local deCompressedText = "" +local editMode = false + +function RL.init() + RL.SetWindowTitle( "Buffer" ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) +end + +local function compressDecompressData() + local strT = {} + + for i = 1, #text do + table.insert( strT, string.byte( text:sub( i, i ) ) ) + end + + local strBuffer = RL.LoadBuffer( strT, RL.BUFFER_UNSIGNED_CHAR ) + local compBuffer = RL.CompressData( strBuffer ) + local deCompBuffer = RL.DecompressData( compBuffer ) + + deCompressedText = "" + + for _, c in ipairs( RL.GetBufferData( deCompBuffer ) ) do + deCompressedText = deCompressedText..string.char( c ) + end +end + +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) + RL.DrawText( "Decompressed text: "..deCompressedText, { 20, 200 }, 20, textColor ) + + if RL.GuiButton( { 20, 20, 168, 32 }, "Compress/Decompress Data" ) then + compressDecompressData() + end + + local pressed = false + pressed, text = RL.GuiTextBox( { 220, 20, 400, 32 }, text, 64, editMode ) + + if pressed then + editMode = not editMode + end +end -- cgit v1.2.3