diff options
| author | jussi | 2023-11-03 23:12:55 +0200 |
|---|---|---|
| committer | jussi | 2023-11-03 23:12:55 +0200 |
| commit | d74a505d406faf276a265beaf8925d6e8ff9cec0 (patch) | |
| tree | 72de6e187e0e745f21a9190f5d02895fcecaf83c /examples/compress_data/main.lua | |
| parent | e61823b8bb69e258370503df7969e4e3c2089e2d (diff) | |
| download | reilua-enhanced-d74a505d406faf276a265beaf8925d6e8ff9cec0.tar.gz reilua-enhanced-d74a505d406faf276a265beaf8925d6e8ff9cec0.tar.bz2 reilua-enhanced-d74a505d406faf276a265beaf8925d6e8ff9cec0.zip | |
Compress/decompress and Encode/Decode DataBase64.
Diffstat (limited to 'examples/compress_data/main.lua')
| -rw-r--r-- | examples/compress_data/main.lua | 43 |
1 files changed, 43 insertions, 0 deletions
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 |
