summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md16
-rw-r--r--ReiLua_API.lua21
-rw-r--r--changelog3
-rw-r--r--devnotes2
-rw-r--r--include/core.h3
-rw-r--r--src/core.c68
-rw-r--r--src/lua_core.c3
7 files changed, 76 insertions, 40 deletions
diff --git a/API.md b/API.md
index f280f7a..7bb138c 100644
--- a/API.md
+++ b/API.md
@@ -4978,6 +4978,15 @@ Load Buffer. Type should be one of the Buffer types. Empty buffer will set data
---
+> buffer = RL.LoadBufferFromFile( string path, type int )
+
+Read buffer data from binary file
+
+- Failure return nil
+- Success return Buffer
+
+---
+
> RL.UnloadBuffer( Buffer buffer )
Unload buffer data
@@ -5014,12 +5023,11 @@ Write buffer data to binary file
---
-> buffer = RL.LoadBufferFromFile( string path, type int )
+> success = RL.ExportBufferAsCode( Buffer buffer, string fileName )
-Read buffer data from binary file
+Export buffer data to code (.h), returns true on success
-- Failure return nil
-- Success return Buffer
+- Success return bool
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 98d656a..b1b6500 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -2366,6 +2366,14 @@ function RL.UpdateCamera3DPro( camera, movement, rotation, zoom ) end
---@return any buffer
function RL.LoadBuffer( buffer, type ) end
+---Read buffer data from binary file
+---- Failure return nil
+---- Success return Buffer
+---@param path string
+---@param int any
+---@return any buffer
+function RL.LoadBufferFromFile( path, int ) end
+
---Unload buffer data
---@param buffer any
---@return any RL.UnloadBuffer
@@ -2395,13 +2403,12 @@ function RL.GetBufferSize( buffer ) end
---@return any RL.ExportBuffer
function RL.ExportBuffer( buffer, path ) end
----Read buffer data from binary file
----- Failure return nil
----- Success return Buffer
----@param path string
----@param int any
----@return any buffer
-function RL.LoadBufferFromFile( path, int ) end
+---Export buffer data to code (.h), returns true on success
+---- Success return bool
+---@param buffer any
+---@param fileName string
+---@return any success
+function RL.ExportBufferAsCode( buffer, fileName ) end
-- Shapes - Basic shapes drawing functions
diff --git a/changelog b/changelog
index 091b45b..ab43683 100644
--- a/changelog
+++ b/changelog
@@ -30,7 +30,8 @@ DETAILED CHANGES:
- CHANGE: Moved glfw headers to GLFW folder.
- CHANGE: Term globals changed to defines in documentation.
- CHANGE: Event documentation is now described in c files.
-
+ - ADDED: ExportBufferAsCode.
+
------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5
------------------------------------------------------------------------
diff --git a/devnotes b/devnotes
index 23714d3..af49542 100644
--- a/devnotes
+++ b/devnotes
@@ -17,6 +17,8 @@ Backlog {
* More Model management functions. Get mesh and material etc.
* BoneInfo.
* LoadMaterialsFromModel (Could then for example edit and set back to model).
+ * Core
+ * Automation events functionality.
* Examples
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
diff --git a/include/core.h b/include/core.h
index 3d8d3c0..ff657e6 100644
--- a/include/core.h
+++ b/include/core.h
@@ -214,9 +214,10 @@ int lcoreUpdateCamera3D( lua_State *L );
int lcoreUpdateCamera3DPro( lua_State *L );
/* Buffer management functions. */
int lcoreLoadBuffer( lua_State *L );
+int lcoreLoadBufferFromFile( lua_State *L );
int lcoreUnloadBuffer( lua_State *L );
int lcoreGetBufferData( lua_State *L );
int lcoreGetBufferType( lua_State *L );
int lcoreGetBufferSize( lua_State *L );
int lcoreExportBuffer( lua_State *L );
-int lcoreLoadBufferFromFile( lua_State *L );
+int lcoreExportBufferAsCode( lua_State *L );
diff --git a/src/core.c b/src/core.c
index 2f4b96b..2d7d7a1 100644
--- a/src/core.c
+++ b/src/core.c
@@ -2943,6 +2943,41 @@ int lcoreLoadBuffer( lua_State *L ) {
}
/*
+> buffer = RL.LoadBufferFromFile( string path, type int )
+
+Read buffer data from binary file
+
+- Failure return nil
+- Success return Buffer
+*/
+int lcoreLoadBufferFromFile( lua_State *L ) {
+ int type = luaL_checkinteger( L, 2 );
+ const char *path = luaL_checkstring( L, 1 );
+
+ int fileLen = GetFileLength( path );
+ Buffer buffer = {
+ .type = type,
+ .size = fileLen,
+ .data = malloc( fileLen )
+ };
+ size_t elementSize = getBufferElementSize( &buffer );
+ FILE *file;
+ file = fopen( path, "rb" );
+
+ if ( file == NULL ) {
+ TraceLog( LOG_WARNING, "Invalid file %s\n", path );
+ lua_pushnil( L );
+ return 1;
+ }
+ fread( buffer.data, elementSize, buffer.size / elementSize, file );
+ fclose( file );
+
+ uluaPushBuffer( L, buffer );
+
+ return 1;
+}
+
+/*
> RL.UnloadBuffer( Buffer buffer )
Unload buffer data
@@ -3107,36 +3142,17 @@ int lcoreExportBuffer( lua_State *L ) {
}
/*
-> buffer = RL.LoadBufferFromFile( string path, type int )
+> success = RL.ExportBufferAsCode( Buffer buffer, string fileName )
-Read buffer data from binary file
+Export buffer data to code (.h), returns true on success
-- Failure return nil
-- Success return Buffer
+- Success return bool
*/
-int lcoreLoadBufferFromFile( lua_State *L ) {
- int type = luaL_checkinteger( L, 2 );
- const char *path = luaL_checkstring( L, 1 );
-
- int fileLen = GetFileLength( path );
- Buffer buffer = {
- .type = type,
- .size = fileLen,
- .data = malloc( fileLen )
- };
- size_t elementSize = getBufferElementSize( &buffer );
- FILE *file;
- file = fopen( path, "rb" );
-
- if ( file == NULL ) {
- TraceLog( LOG_WARNING, "Invalid file %s\n", path );
- lua_pushnil( L );
- return 1;
- }
- fread( buffer.data, elementSize, buffer.size / elementSize, file );
- fclose( file );
+int lcoreExportBufferAsCode( lua_State *L ) {
+ Buffer *buffer = uluaGetBuffer( L, 1 );
+ const char *fileName = luaL_checkstring( L, 2 );
- uluaPushBuffer( L, buffer );
+ lua_pushboolean( L, ExportDataAsCode( buffer->data, buffer->size, fileName ) );
return 1;
}
diff --git a/src/lua_core.c b/src/lua_core.c
index 0874613..a777bc4 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1354,12 +1354,13 @@ void luaRegister() {
assingGlobalFunction( "UpdateCamera3DPro", lcoreUpdateCamera3DPro );
/* Buffer management functions. */
assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer );
+ assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile );
assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer );
assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize );
assingGlobalFunction( "ExportBuffer", lcoreExportBuffer );
- assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile );
+ assingGlobalFunction( "ExportBufferAsCode", lcoreExportBufferAsCode );
/* Shapes. */
/* Basic shapes drawing functions. */