GetBufferAsString.

This commit is contained in:
jussi
2024-08-29 13:01:21 +03:00
parent 366f8f5c92
commit d40bf3a393
6 changed files with 40 additions and 0 deletions

8
API.md
View File

@@ -5522,6 +5522,14 @@ Get buffer data as table in the format it was stored
--- ---
> string = RL.GetBufferAsString( Buffer buffer )
Get buffer as string
- Success return string
---
> type = RL.GetBufferType( Buffer buffer ) > type = RL.GetBufferType( Buffer buffer )
Get buffer type Get buffer type

View File

@@ -2684,6 +2684,12 @@ function RL.SetBufferData( buffer, position, value ) end
---@return any data ---@return any data
function RL.GetBufferData( buffer, position, length ) end function RL.GetBufferData( buffer, position, length ) end
---Get buffer as string
---- Success return string
---@param buffer any
---@return any string
function RL.GetBufferAsString( buffer ) end
---Get buffer type ---Get buffer type
---- Success return int ---- Success return int
---@param buffer any ---@param buffer any

View File

@@ -70,6 +70,7 @@ DETAILED CHANGES:
- FIXED: GenImageColor color was also argument 1. - FIXED: GenImageColor color was also argument 1.
- CHANGE: GetPixelDataSize takes Vector2 instead of width and height. - CHANGE: GetPixelDataSize takes Vector2 instead of width and height.
- ADDED: LoadBufferFormatted, SetBufferData and CopyBufferData. Compressed resource file example. - ADDED: LoadBufferFormatted, SetBufferData and CopyBufferData. Compressed resource file example.
- ADDED: GetBufferAsString.
------------------------------------------------------------------------ ------------------------------------------------------------------------
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

View File

@@ -256,6 +256,7 @@ int lcoreUnloadBuffer( lua_State* L );
int lcoreCopyBufferData( lua_State* L ); int lcoreCopyBufferData( lua_State* L );
int lcoreSetBufferData( lua_State* L ); int lcoreSetBufferData( lua_State* L );
int lcoreGetBufferData( lua_State* L ); int lcoreGetBufferData( lua_State* L );
int lcoreGetBufferAsString( 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 lcoreGetBufferElementSize( lua_State* L );

View File

@@ -3736,6 +3736,29 @@ int lcoreGetBufferData( lua_State* L ) {
return 1; return 1;
} }
/*
> string = RL.GetBufferAsString( Buffer buffer )
Get buffer as string
- Success return string
*/
int lcoreGetBufferAsString( lua_State* L ) {
Buffer* buffer = uluaGetBuffer( L, 1 );
size_t size = buffer->size * getBufferElementSize( buffer ) + 1;
char* str = malloc( size );
memset( str, 0, size );
memcpy( str, buffer->data, size - 1 );
lua_pushstring( L, buffer->data );
free( str );
return 1;
}
/* /*
> type = RL.GetBufferType( Buffer buffer ) > type = RL.GetBufferType( Buffer buffer )

View File

@@ -1519,6 +1519,7 @@ void luaRegister() {
assingGlobalFunction( "CopyBufferData", lcoreCopyBufferData ); assingGlobalFunction( "CopyBufferData", lcoreCopyBufferData );
assingGlobalFunction( "SetBufferData", lcoreSetBufferData ); assingGlobalFunction( "SetBufferData", lcoreSetBufferData );
assingGlobalFunction( "GetBufferData", lcoreGetBufferData ); assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
assingGlobalFunction( "GetBufferAsString", lcoreGetBufferAsString );
assingGlobalFunction( "GetBufferType", lcoreGetBufferType ); assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize ); assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize );
assingGlobalFunction( "GetBufferElementSize", lcoreGetBufferElementSize ); assingGlobalFunction( "GetBufferElementSize", lcoreGetBufferElementSize );