ExportBufferAsCode.

This commit is contained in:
jussi
2023-11-29 17:20:54 +02:00
parent 21eb3f90c4
commit 4ff1b1dcb9
7 changed files with 76 additions and 40 deletions

16
API.md
View File

@@ -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 ) > RL.UnloadBuffer( Buffer buffer )
Unload buffer data 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 bool
- Success return Buffer
--- ---

View File

@@ -2366,6 +2366,14 @@ function RL.UpdateCamera3DPro( camera, movement, rotation, zoom ) end
---@return any buffer ---@return any buffer
function RL.LoadBuffer( buffer, type ) end 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 ---Unload buffer data
---@param buffer any ---@param buffer any
---@return any RL.UnloadBuffer ---@return any RL.UnloadBuffer
@@ -2395,13 +2403,12 @@ function RL.GetBufferSize( buffer ) end
---@return any RL.ExportBuffer ---@return any RL.ExportBuffer
function RL.ExportBuffer( buffer, path ) end function RL.ExportBuffer( buffer, path ) end
---Read buffer data from binary file ---Export buffer data to code (.h), returns true on success
---- Failure return nil ---- Success return bool
---- Success return Buffer ---@param buffer any
---@param path string ---@param fileName string
---@param int any ---@return any success
---@return any buffer function RL.ExportBufferAsCode( buffer, fileName ) end
function RL.LoadBufferFromFile( path, int ) end
-- Shapes - Basic shapes drawing functions -- Shapes - Basic shapes drawing functions

View File

@@ -30,6 +30,7 @@ DETAILED CHANGES:
- CHANGE: Moved glfw headers to GLFW folder. - CHANGE: Moved glfw headers to GLFW folder.
- CHANGE: Term globals changed to defines in documentation. - CHANGE: Term globals changed to defines in documentation.
- CHANGE: Event documentation is now described in c files. - CHANGE: Event documentation is now described in c files.
- ADDED: ExportBufferAsCode.
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5 Release: ReiLua version 0.6.0 Using Raylib 4.5

View File

@@ -17,6 +17,8 @@ Backlog {
* More Model management functions. Get mesh and material etc. * More Model management functions. Get mesh and material etc.
* BoneInfo. * BoneInfo.
* LoadMaterialsFromModel (Could then for example edit and set back to model). * LoadMaterialsFromModel (Could then for example edit and set back to model).
* Core
* Automation events functionality.
* Examples * Examples
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads. * Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.

View File

@@ -214,9 +214,10 @@ int lcoreUpdateCamera3D( lua_State *L );
int lcoreUpdateCamera3DPro( lua_State *L ); int lcoreUpdateCamera3DPro( lua_State *L );
/* Buffer management functions. */ /* Buffer management functions. */
int lcoreLoadBuffer( lua_State *L ); int lcoreLoadBuffer( lua_State *L );
int lcoreLoadBufferFromFile( lua_State *L );
int lcoreUnloadBuffer( lua_State *L ); 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 lcoreExportBuffer( lua_State *L ); int lcoreExportBuffer( lua_State *L );
int lcoreLoadBufferFromFile( lua_State *L ); int lcoreExportBufferAsCode( lua_State *L );

View File

@@ -2942,6 +2942,41 @@ int lcoreLoadBuffer( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > RL.UnloadBuffer( Buffer buffer )
@@ -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 bool
- Success return Buffer
*/ */
int lcoreLoadBufferFromFile( lua_State *L ) { int lcoreExportBufferAsCode( lua_State *L ) {
int type = luaL_checkinteger( L, 2 ); Buffer *buffer = uluaGetBuffer( L, 1 );
const char *path = luaL_checkstring( L, 1 ); const char *fileName = luaL_checkstring( L, 2 );
int fileLen = GetFileLength( path ); lua_pushboolean( L, ExportDataAsCode( buffer->data, buffer->size, fileName ) );
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; return 1;
} }

View File

@@ -1354,12 +1354,13 @@ void luaRegister() {
assingGlobalFunction( "UpdateCamera3DPro", lcoreUpdateCamera3DPro ); assingGlobalFunction( "UpdateCamera3DPro", lcoreUpdateCamera3DPro );
/* Buffer management functions. */ /* Buffer management functions. */
assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer ); assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer );
assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile );
assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer ); assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer );
assingGlobalFunction( "GetBufferData", lcoreGetBufferData ); assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
assingGlobalFunction( "GetBufferType", lcoreGetBufferType ); assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize ); assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize );
assingGlobalFunction( "ExportBuffer", lcoreExportBuffer ); assingGlobalFunction( "ExportBuffer", lcoreExportBuffer );
assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile ); assingGlobalFunction( "ExportBufferAsCode", lcoreExportBufferAsCode );
/* Shapes. */ /* Shapes. */
/* Basic shapes drawing functions. */ /* Basic shapes drawing functions. */