GetBufferData extra arguments. GetBufferElementSize and GetBufferLength.
This commit is contained in:
20
API.md
20
API.md
@@ -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
|
Get buffer data as table in the format it was stored
|
||||||
|
|
||||||
@@ -5094,7 +5094,23 @@ Get buffer type
|
|||||||
|
|
||||||
> size = RL.GetBufferSize( Buffer buffer )
|
> 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
|
- Success return int
|
||||||
|
|
||||||
|
|||||||
@@ -2430,8 +2430,10 @@ function RL.UnloadBuffer( buffer ) end
|
|||||||
---Get buffer data as table in the format it was stored
|
---Get buffer data as table in the format it was stored
|
||||||
---- Success return data{}
|
---- Success return data{}
|
||||||
---@param buffer any
|
---@param buffer any
|
||||||
|
---@param position integer
|
||||||
|
---@param length integer
|
||||||
---@return any data
|
---@return any data
|
||||||
function RL.GetBufferData( buffer ) end
|
function RL.GetBufferData( buffer, position, length ) end
|
||||||
|
|
||||||
---Get buffer type
|
---Get buffer type
|
||||||
---- Success return int
|
---- Success return int
|
||||||
@@ -2439,12 +2441,24 @@ function RL.GetBufferData( buffer ) end
|
|||||||
---@return any type
|
---@return any type
|
||||||
function RL.GetBufferType( buffer ) end
|
function RL.GetBufferType( buffer ) end
|
||||||
|
|
||||||
---Get buffer size
|
---Get buffer size in bytes
|
||||||
---- Success return int
|
---- Success return int
|
||||||
---@param buffer any
|
---@param buffer any
|
||||||
---@return any size
|
---@return any size
|
||||||
function RL.GetBufferSize( buffer ) end
|
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
|
---Write buffer data to binary file
|
||||||
---@param buffer any
|
---@param buffer any
|
||||||
---@param path string
|
---@param path string
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
|
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
KEY CHANGES:
|
KEY CHANGES:
|
||||||
|
- CHANGE: GetBufferData takes also position and length arguments.
|
||||||
|
|
||||||
DETAILED CHANGES:
|
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
|
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ local function compressDecompressData()
|
|||||||
|
|
||||||
deCompressedText = ""
|
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 )
|
deCompressedText = deCompressedText..string.char( c )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -30,14 +30,14 @@ function RL.draw()
|
|||||||
RL.ClearBackground( RL.RAYWHITE )
|
RL.ClearBackground( RL.RAYWHITE )
|
||||||
RL.DrawText( "Decompressed text: "..deCompressedText, { 20, 200 }, 20, textColor )
|
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()
|
compressDecompressData()
|
||||||
end
|
end
|
||||||
|
|
||||||
local pressed = false
|
local pressed = false
|
||||||
pressed, text = RL.GuiTextBox( { 220, 20, 400, 32 }, text, 64, editMode )
|
pressed, text = RL.GuiTextBox( { 220, 20, 400, 32 }, text, 64, editMode )
|
||||||
|
|
||||||
if pressed then
|
if 0 < pressed then
|
||||||
editMode = not editMode
|
editMode = not editMode
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -227,4 +227,6 @@ int lcoreUnloadBuffer( lua_State *L );
|
|||||||
int lcoreGetBufferData( lua_State *L );
|
int lcoreGetBufferData( lua_State *L );
|
||||||
int lcoreGetBufferType( lua_State *L );
|
int lcoreGetBufferType( lua_State *L );
|
||||||
int lcoreGetBufferSize( lua_State *L );
|
int lcoreGetBufferSize( lua_State *L );
|
||||||
|
int lcoreGetBufferElementSize( lua_State *L );
|
||||||
|
int lcoreGetBufferLength( lua_State *L );
|
||||||
int lcoreExportBuffer( lua_State *L );
|
int lcoreExportBuffer( lua_State *L );
|
||||||
|
|||||||
77
src/core.c
77
src/core.c
@@ -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
|
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 ) {
|
int lcoreGetBufferData( lua_State *L ) {
|
||||||
Buffer *buffer = uluaGetBuffer( L, 1 );
|
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 ) {
|
if ( buffer->type == BUFFER_UNSIGNED_CHAR ) {
|
||||||
unsigned char *p = buffer->data;
|
unsigned char *p = buffer->data + position * sizeof( unsigned char );
|
||||||
size_t count = buffer->size / 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 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3140,8 +3143,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_UNSIGNED_SHORT ) {
|
else if ( buffer->type == BUFFER_UNSIGNED_SHORT ) {
|
||||||
unsigned short *p = buffer->data;
|
unsigned short *p = buffer->data + position * sizeof( unsigned short );
|
||||||
size_t count = buffer->size / 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 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3151,8 +3155,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_UNSIGNED_INT ) {
|
else if ( buffer->type == BUFFER_UNSIGNED_INT ) {
|
||||||
unsigned int *p = buffer->data;
|
unsigned int *p = buffer->data + position * sizeof( unsigned int );
|
||||||
size_t count = buffer->size / 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 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3162,8 +3167,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_CHAR ) {
|
else if ( buffer->type == BUFFER_CHAR ) {
|
||||||
char *p = buffer->data;
|
char *p = buffer->data + position * sizeof( char );
|
||||||
size_t count = buffer->size / sizeof( char );
|
size_t bufLen = buffer->size / sizeof( char );
|
||||||
|
size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length;
|
||||||
lua_createtable( L, count, 0 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3173,8 +3179,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_SHORT ) {
|
else if ( buffer->type == BUFFER_SHORT ) {
|
||||||
short *p = buffer->data;
|
short *p = buffer->data + position * sizeof( short );
|
||||||
size_t count = buffer->size / sizeof( short );
|
size_t bufLen = buffer->size / sizeof( short );
|
||||||
|
size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length;
|
||||||
lua_createtable( L, count, 0 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3184,8 +3191,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_INT ) {
|
else if ( buffer->type == BUFFER_INT ) {
|
||||||
int *p = buffer->data;
|
int *p = buffer->data + position * sizeof( int );
|
||||||
size_t count = buffer->size / sizeof( int );
|
size_t bufLen = buffer->size / sizeof( int );
|
||||||
|
size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length;
|
||||||
lua_createtable( L, count, 0 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3195,8 +3203,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_FLOAT ) {
|
else if ( buffer->type == BUFFER_FLOAT ) {
|
||||||
float *p = buffer->data;
|
float *p = buffer->data + position * sizeof( float );
|
||||||
size_t count = buffer->size / sizeof( float );
|
size_t bufLen = buffer->size / sizeof( float );
|
||||||
|
size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length;
|
||||||
lua_createtable( L, count, 0 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3206,8 +3215,9 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( buffer->type == BUFFER_DOUBLE ) {
|
else if ( buffer->type == BUFFER_DOUBLE ) {
|
||||||
double *p = buffer->data;
|
double *p = buffer->data + position * sizeof( double );
|
||||||
size_t count = buffer->size / sizeof( double );
|
size_t bufLen = buffer->size / sizeof( double );
|
||||||
|
size_t count = bufLen < ( position + length ) ? ( position + length ) - bufLen : length;
|
||||||
lua_createtable( L, count, 0 );
|
lua_createtable( L, count, 0 );
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
@@ -3216,7 +3226,6 @@ int lcoreGetBufferData( lua_State *L ) {
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3238,7 +3247,7 @@ int lcoreGetBufferType( lua_State *L ) {
|
|||||||
/*
|
/*
|
||||||
> size = RL.GetBufferSize( Buffer buffer )
|
> size = RL.GetBufferSize( Buffer buffer )
|
||||||
|
|
||||||
Get buffer size
|
Get buffer size in bytes
|
||||||
|
|
||||||
- Success return int
|
- Success return int
|
||||||
*/
|
*/
|
||||||
@@ -3250,6 +3259,36 @@ int lcoreGetBufferSize( lua_State *L ) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> 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 )
|
> RL.ExportBuffer( Buffer buffer, string path )
|
||||||
|
|
||||||
|
|||||||
@@ -1419,6 +1419,8 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
|
assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
|
||||||
assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
|
assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
|
||||||
assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize );
|
assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize );
|
||||||
|
assingGlobalFunction( "GetBufferElementSize", lcoreGetBufferElementSize );
|
||||||
|
assingGlobalFunction( "GetBufferLength", lcoreGetBufferLength );
|
||||||
assingGlobalFunction( "ExportBuffer", lcoreExportBuffer );
|
assingGlobalFunction( "ExportBuffer", lcoreExportBuffer );
|
||||||
|
|
||||||
/* Shapes. */
|
/* Shapes. */
|
||||||
|
|||||||
Reference in New Issue
Block a user