diff options
| -rw-r--r-- | API.md | 16 | ||||
| -rw-r--r-- | ReiLua_API.lua | 21 | ||||
| -rw-r--r-- | changelog | 3 | ||||
| -rw-r--r-- | devnotes | 2 | ||||
| -rw-r--r-- | include/core.h | 3 | ||||
| -rw-r--r-- | src/core.c | 68 | ||||
| -rw-r--r-- | src/lua_core.c | 3 |
7 files changed, 76 insertions, 40 deletions
@@ -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 @@ -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 ------------------------------------------------------------------------ @@ -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 ); @@ -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. */ |
