diff options
| -rw-r--r-- | API.md | 20 | ||||
| -rw-r--r-- | ReiLua_API.lua | 18 | ||||
| -rw-r--r-- | changelog | 3 | ||||
| -rw-r--r-- | examples/compress_data/main.lua | 6 | ||||
| -rw-r--r-- | include/core.h | 2 | ||||
| -rw-r--r-- | src/core.c | 77 | ||||
| -rw-r--r-- | src/lua_core.c | 2 |
7 files changed, 102 insertions, 26 deletions
@@ -5076,7 +5076,7 @@ Unload buffer data --- -> data = RL.GetBufferData( Buffer buffer ) +> data = RL.GetBufferData( Buffer buffer, int position, int length ) Get buffer data as table in the format it was stored @@ -5094,7 +5094,23 @@ Get buffer type > size = RL.GetBufferSize( Buffer buffer ) -Get buffer size +Get buffer size in bytes + +- Success return int + +--- + +> size = RL.GetBufferElementSize( Buffer buffer ) + +Get buffer element size in bytes + +- Success return int + +--- + +> length = RL.GetBufferLength( Buffer buffer ) + +Get buffer element count - Success return int diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 1db9119..8da57ed 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -2430,8 +2430,10 @@ function RL.UnloadBuffer( buffer ) end ---Get buffer data as table in the format it was stored ---- Success return data{} ---@param buffer any +---@param position integer +---@param length integer ---@return any data -function RL.GetBufferData( buffer ) end +function RL.GetBufferData( buffer, position, length ) end ---Get buffer type ---- Success return int @@ -2439,12 +2441,24 @@ function RL.GetBufferData( buffer ) end ---@return any type function RL.GetBufferType( buffer ) end ----Get buffer size +---Get buffer size in bytes ---- Success return int ---@param buffer any ---@return any size function RL.GetBufferSize( buffer ) end +---Get buffer element size in bytes +---- Success return int +---@param buffer any +---@return any size +function RL.GetBufferElementSize( buffer ) end + +---Get buffer element count +---- Success return int +---@param buffer any +---@return any length +function RL.GetBufferLength( buffer ) end + ---Write buffer data to binary file ---@param buffer any ---@param path string @@ -2,8 +2,11 @@ Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0 ------------------------------------------------------------------------ KEY CHANGES: + - CHANGE: GetBufferData takes also position and length arguments. DETAILED CHANGES: + - ADDED: GetBufferElementSize and GetBufferLength. + - FIXED: Compress_data example. ------------------------------------------------------------------------ Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0 diff --git a/examples/compress_data/main.lua b/examples/compress_data/main.lua index bf6c162..3ee724c 100644 --- a/examples/compress_data/main.lua +++ b/examples/compress_data/main.lua @@ -21,7 +21,7 @@ local function compressDecompressData() deCompressedText = "" - for _, c in ipairs( RL.GetBufferData( deCompBuffer ) ) do + for _, c in ipairs( RL.GetBufferData( deCompBuffer, 0, RL.GetBufferLength( deCompBuffer ) ) ) do deCompressedText = deCompressedText..string.char( c ) end end @@ -30,14 +30,14 @@ 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 + if 0 < 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 + if 0 < pressed then editMode = not editMode end end diff --git a/include/core.h b/include/core.h index a130692..8e163a8 100644 --- a/include/core.h +++ b/include/core.h @@ -227,4 +227,6 @@ int lcoreUnloadBuffer( lua_State *L ); int lcoreGetBufferData( lua_State *L ); int lcoreGetBufferType( lua_State *L ); int lcoreGetBufferSize( lua_State *L ); +int lcoreGetBufferElementSize( lua_State *L ); +int lcoreGetBufferLength( lua_State *L ); int lcoreExportBuffer( lua_State *L ); @@ -3119,7 +3119,7 @@ int lcoreUnloadBuffer( lua_State *L ) { } /* -> data = RL.GetBufferData( Buffer buffer ) +> data = RL.GetBufferData( Buffer buffer, int position, int length ) Get buffer data as table in the format it was stored @@ -3127,10 +3127,13 @@ Get buffer data as table in the format it was stored */ int lcoreGetBufferData( lua_State *L ) { Buffer *buffer = uluaGetBuffer( L, 1 ); + size_t position = luaL_checkinteger( L, 2 ); + size_t length = luaL_checkinteger( L, 3 ); if ( buffer->type == BUFFER_UNSIGNED_CHAR ) { - unsigned char *p = buffer->data; - size_t count = buffer->size / sizeof( unsigned char ); + unsigned char *p = buffer->data + position * sizeof( unsigned char ); + size_t bufLen = buffer->size / sizeof( unsigned char ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3140,8 +3143,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_UNSIGNED_SHORT ) { - unsigned short *p = buffer->data; - size_t count = buffer->size / sizeof( unsigned short ); + unsigned short *p = buffer->data + position * sizeof( unsigned short ); + size_t bufLen = buffer->size / sizeof( unsigned short ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3151,8 +3155,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_UNSIGNED_INT ) { - unsigned int *p = buffer->data; - size_t count = buffer->size / sizeof( unsigned int ); + unsigned int *p = buffer->data + position * sizeof( unsigned int ); + size_t bufLen = buffer->size / sizeof( unsigned int ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3162,8 +3167,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_CHAR ) { - char *p = buffer->data; - size_t count = buffer->size / sizeof( char ); + char *p = buffer->data + position * sizeof( char ); + size_t bufLen = buffer->size / sizeof( char ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3173,8 +3179,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_SHORT ) { - short *p = buffer->data; - size_t count = buffer->size / sizeof( short ); + short *p = buffer->data + position * sizeof( short ); + size_t bufLen = buffer->size / sizeof( short ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3184,8 +3191,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_INT ) { - int *p = buffer->data; - size_t count = buffer->size / sizeof( int ); + int *p = buffer->data + position * sizeof( int ); + size_t bufLen = buffer->size / sizeof( int ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3195,8 +3203,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_FLOAT ) { - float *p = buffer->data; - size_t count = buffer->size / sizeof( float ); + float *p = buffer->data + position * sizeof( float ); + size_t bufLen = buffer->size / sizeof( float ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3206,8 +3215,9 @@ int lcoreGetBufferData( lua_State *L ) { } } else if ( buffer->type == BUFFER_DOUBLE ) { - double *p = buffer->data; - size_t count = buffer->size / sizeof( double ); + double *p = buffer->data + position * sizeof( double ); + size_t bufLen = buffer->size / sizeof( double ); + size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length; lua_createtable( L, count, 0 ); for ( int i = 0; i < count; i++ ) { @@ -3216,7 +3226,6 @@ int lcoreGetBufferData( lua_State *L ) { p++; } } - return 1; } @@ -3238,7 +3247,7 @@ int lcoreGetBufferType( lua_State *L ) { /* > size = RL.GetBufferSize( Buffer buffer ) -Get buffer size +Get buffer size in bytes - Success return int */ @@ -3251,6 +3260,36 @@ int lcoreGetBufferSize( lua_State *L ) { } /* +> size = RL.GetBufferElementSize( Buffer buffer ) + +Get buffer element size in bytes + +- Success return int +*/ +int lcoreGetBufferElementSize( lua_State *L ) { + Buffer *buffer = uluaGetBuffer( L, 1 ); + + lua_pushinteger( L, getBufferElementSize( buffer ) ); + + return 1; +} + +/* +> length = RL.GetBufferLength( Buffer buffer ) + +Get buffer element count + +- Success return int +*/ +int lcoreGetBufferLength( lua_State *L ) { + Buffer *buffer = uluaGetBuffer( L, 1 ); + + lua_pushinteger( L, buffer->size / getBufferElementSize( buffer ) ); + + return 1; +} + +/* > RL.ExportBuffer( Buffer buffer, string path ) Write buffer data to binary file diff --git a/src/lua_core.c b/src/lua_core.c index 3ce5474..9577a0e 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1419,6 +1419,8 @@ void luaRegister() { assingGlobalFunction( "GetBufferData", lcoreGetBufferData ); assingGlobalFunction( "GetBufferType", lcoreGetBufferType ); assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize ); + assingGlobalFunction( "GetBufferElementSize", lcoreGetBufferElementSize ); + assingGlobalFunction( "GetBufferLength", lcoreGetBufferLength ); assingGlobalFunction( "ExportBuffer", lcoreExportBuffer ); /* Shapes. */ |
