summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2024-08-29 13:01:21 +0300
committerjussi2024-08-29 13:01:21 +0300
commitd40bf3a393d968198dc30b7e7cd3f7b926f3a482 (patch)
tree9bd1d6d306518317466ebc27fd708d60a1a10f0b
parent366f8f5c92975ff6ac7e1643124d747ae54130be (diff)
downloadreilua-enhanced-d40bf3a393d968198dc30b7e7cd3f7b926f3a482.tar.gz
reilua-enhanced-d40bf3a393d968198dc30b7e7cd3f7b926f3a482.tar.bz2
reilua-enhanced-d40bf3a393d968198dc30b7e7cd3f7b926f3a482.zip
GetBufferAsString.
-rw-r--r--API.md8
-rw-r--r--ReiLua_API.lua6
-rw-r--r--changelog1
-rw-r--r--include/core.h1
-rw-r--r--src/core.c23
-rw-r--r--src/lua_core.c1
6 files changed, 40 insertions, 0 deletions
diff --git a/API.md b/API.md
index 468eb89..109b6c8 100644
--- a/API.md
+++ b/API.md
@@ -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 )
Get buffer type
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 5006d3a..604e6b8 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -2684,6 +2684,12 @@ function RL.SetBufferData( buffer, position, value ) end
---@return any data
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
---- Success return int
---@param buffer any
diff --git a/changelog b/changelog
index f341a5f..4b6d88a 100644
--- a/changelog
+++ b/changelog
@@ -70,6 +70,7 @@ DETAILED CHANGES:
- FIXED: GenImageColor color was also argument 1.
- CHANGE: GetPixelDataSize takes Vector2 instead of width and height.
- 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
diff --git a/include/core.h b/include/core.h
index 045a594..181de24 100644
--- a/include/core.h
+++ b/include/core.h
@@ -256,6 +256,7 @@ int lcoreUnloadBuffer( lua_State* L );
int lcoreCopyBufferData( lua_State* L );
int lcoreSetBufferData( lua_State* L );
int lcoreGetBufferData( lua_State* L );
+int lcoreGetBufferAsString( lua_State* L );
int lcoreGetBufferType( lua_State* L );
int lcoreGetBufferSize( lua_State* L );
int lcoreGetBufferElementSize( lua_State* L );
diff --git a/src/core.c b/src/core.c
index 4607ef6..0aa8559 100644
--- a/src/core.c
+++ b/src/core.c
@@ -3737,6 +3737,29 @@ int lcoreGetBufferData( lua_State* L ) {
}
/*
+> 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 )
Get buffer type
diff --git a/src/lua_core.c b/src/lua_core.c
index 50fdfda..7250cfc 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1519,6 +1519,7 @@ void luaRegister() {
assingGlobalFunction( "CopyBufferData", lcoreCopyBufferData );
assingGlobalFunction( "SetBufferData", lcoreSetBufferData );
assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
+ assingGlobalFunction( "GetBufferAsString", lcoreGetBufferAsString );
assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize );
assingGlobalFunction( "GetBufferElementSize", lcoreGetBufferElementSize );