diff options
| author | jussi | 2024-01-24 19:14:30 +0200 |
|---|---|---|
| committer | jussi | 2024-01-24 19:14:30 +0200 |
| commit | 3b3d0ad32e24c2ff0a13daf3e865054f63afaf86 (patch) | |
| tree | 192e9b69af4515c6e05978c83905636f693f011a | |
| parent | 7460a16cae15dfa7924d1d4df1aac166a6a6fd2c (diff) | |
| download | reilua-enhanced-3b3d0ad32e24c2ff0a13daf3e865054f63afaf86.tar.gz reilua-enhanced-3b3d0ad32e24c2ff0a13daf3e865054f63afaf86.tar.bz2 reilua-enhanced-3b3d0ad32e24c2ff0a13daf3e865054f63afaf86.zip | |
LoadBufferFromString, LoadWaveFromMemory and LoadMusicStreamFromMemory.
| -rw-r--r-- | API.md | 25 | ||||
| -rw-r--r-- | LICENSE | 2 | ||||
| -rw-r--r-- | ReiLua_API.lua | 21 | ||||
| -rw-r--r-- | changelog | 1 | ||||
| -rw-r--r-- | examples/ray/main.lua | 2 | ||||
| -rw-r--r-- | examples/raygui_extensions/main.lua | 1 | ||||
| -rw-r--r-- | examples/raygui_extensions/property_list.lua | 2 | ||||
| -rw-r--r-- | include/audio.h | 2 | ||||
| -rw-r--r-- | include/core.h | 1 | ||||
| -rw-r--r-- | src/audio.c | 32 | ||||
| -rw-r--r-- | src/core.c | 24 | ||||
| -rw-r--r-- | src/lua_core.c | 3 |
12 files changed, 113 insertions, 3 deletions
@@ -5061,6 +5061,15 @@ Read buffer data from binary file --- +> buffer = RL.LoadBufferFromString( string buffer ) + +Read buffer data from string + +- Failure return nil +- Success return Buffer + +--- + > RL.UnloadBuffer( Buffer buffer ) Unload buffer data @@ -7434,6 +7443,14 @@ Load wave data from file --- +> wave = RL.LoadWaveFromMemory( string fileType, Buffer data ) + +Load wave from memory buffer, fileType refers to extension: i.e. '.wav' + +- Success return Wave + +--- + > isReady = RL.IsWaveReady( Wave wave ) Checks if wave data is ready @@ -7586,6 +7603,14 @@ Load music stream from file --- +> music = RL.LoadMusicStreamFromMemory( string fileType, Buffer data ) + +Load music stream from data + +- Success return Music + +--- + > isReady = RL.IsMusicReady( Music music ) Checks if a music stream is ready @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Jussi Viitala +Copyright (c) 2022-2024 Jussi Viitala Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 9cb2d50..09f0bb3 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -2415,6 +2415,13 @@ function RL.LoadBuffer( buffer, type ) end ---@return any buffer function RL.LoadBufferFromFile( path, int ) end +---Read buffer data from string +---- Failure return nil +---- Success return Buffer +---@param buffer string +---@return any buffer +function RL.LoadBufferFromString( buffer ) end + ---Unload buffer data ---@param buffer any ---@return any RL.UnloadBuffer @@ -4761,6 +4768,13 @@ function RL.LoadSound( fileName ) end ---@return any wave function RL.LoadWave( fileName ) end +---Load wave from memory buffer, fileType refers to extension: i.e. '.wav' +---- Success return Wave +---@param fileType string +---@param data any +---@return any wave +function RL.LoadWaveFromMemory( fileType, data ) end + ---Checks if wave data is ready ---- Success return bool ---@param wave any @@ -4889,6 +4903,13 @@ function RL.WaveCrop( wave, initSample, finalSample ) end ---@return any music function RL.LoadMusicStream( fileName ) end +---Load music stream from data +---- Success return Music +---@param fileType string +---@param data any +---@return any music +function RL.LoadMusicStreamFromMemory( fileType, data ) end + ---Checks if a music stream is ready ---- Success return bool ---@param music any @@ -62,6 +62,7 @@ DETAILED CHANGES: - ADDED: Raygui lib extensions example. - CHANGE: Raygui.h returns textBounds for some controls. - CHANGE: Raygui lib changed term element to control to correspond raylib naming. + - ADDED: LoadBufferFromString, LoadWaveFromMemory and LoadMusicStreamFromMemory. ------------------------------------------------------------------------ Release: ReiLua version 0.6.0 Using Raylib 4.5 diff --git a/examples/ray/main.lua b/examples/ray/main.lua index 52924df..5ac2fcf 100644 --- a/examples/ray/main.lua +++ b/examples/ray/main.lua @@ -14,7 +14,7 @@ local function setupWindow() RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) end -function ray_collision() +local function ray_collision() rayCol = RL.GetRayCollisionMesh( ray, sphereMesh, RL.MatrixIdentity() ) if rayCol ~= nil and rayCol.hit then diff --git a/examples/raygui_extensions/main.lua b/examples/raygui_extensions/main.lua index f6b9dee..e52c96d 100644 --- a/examples/raygui_extensions/main.lua +++ b/examples/raygui_extensions/main.lua @@ -36,6 +36,7 @@ local function addButton( bounds, text, callback ) callback, { { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER }, + { RL.DEFAULT, RL.TEXT_SIZE, 32 }, { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) }, { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) }, { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) }, diff --git a/examples/raygui_extensions/property_list.lua b/examples/raygui_extensions/property_list.lua index 13446a9..04c2b78 100644 --- a/examples/raygui_extensions/property_list.lua +++ b/examples/raygui_extensions/property_list.lua @@ -101,7 +101,7 @@ function PropertyList:updateContent() self._forceCheckScroll = true end --- Leave control bounds size to 0 to use default. Optional group for parameter 2 +-- Leave control bounds size to 0 to use default. Optional group for parameter 2. function PropertyList:addControl( control, group, noYAdvance ) control._noYAdvance = noYAdvance diff --git a/include/audio.h b/include/audio.h index 7367de8..58afc7f 100644 --- a/include/audio.h +++ b/include/audio.h @@ -9,6 +9,7 @@ int laudioGetMasterVolume( lua_State *L ); /* Wave/Sound loading/unloading functions. */ int laudioLoadSound( lua_State *L ); int laudioLoadWave( lua_State *L ); +int laudioLoadWaveFromMemory( lua_State *L ); int laudioIsWaveReady( lua_State *L ); int laudioLoadSoundFromWave( lua_State *L ); int laudioLoadSoundAlias( lua_State *L ); @@ -32,6 +33,7 @@ int laudioWaveCopy( lua_State *L ); int laudioWaveCrop( lua_State *L ); /* Music management functions. */ int laudioLoadMusicStream( lua_State *L ); +int laudioLoadMusicStreamFromMemory( lua_State *L ); int laudioIsMusicReady( lua_State *L ); int laudioUnloadMusicStream( lua_State *L ); int laudioPlayMusicStream( lua_State *L ); diff --git a/include/core.h b/include/core.h index ddfefb1..a130692 100644 --- a/include/core.h +++ b/include/core.h @@ -222,6 +222,7 @@ int lcoreUpdateCamera3DPro( lua_State *L ); /* Buffer management functions. */ int lcoreLoadBuffer( lua_State *L ); int lcoreLoadBufferFromFile( lua_State *L ); +int lcoreLoadBufferFromString( lua_State *L ); int lcoreUnloadBuffer( lua_State *L ); int lcoreGetBufferData( lua_State *L ); int lcoreGetBufferType( lua_State *L ); diff --git a/src/audio.c b/src/audio.c index ef466cb..a02120a 100644 --- a/src/audio.c +++ b/src/audio.c @@ -113,6 +113,22 @@ int laudioLoadWave( lua_State *L ) { } /* +> wave = RL.LoadWaveFromMemory( string fileType, Buffer data ) + +Load wave from memory buffer, fileType refers to extension: i.e. '.wav' + +- Success return Wave +*/ +int laudioLoadWaveFromMemory( lua_State *L ) { + const char* fileType = luaL_checkstring( L, 1 ); + Buffer* buffer = uluaGetBuffer( L, 2 ); + + uluaPushWave( L, LoadWaveFromMemory( fileType, buffer->data, buffer->size ) ); + + return 1; +} + +/* > isReady = RL.IsWaveReady( Wave wave ) Checks if wave data is ready @@ -424,6 +440,22 @@ int laudioLoadMusicStream( lua_State *L ) { } /* +> music = RL.LoadMusicStreamFromMemory( string fileType, Buffer data ) + +Load music stream from data + +- Success return Music +*/ +int laudioLoadMusicStreamFromMemory( lua_State* L ) { + const char* fileType = luaL_checkstring( L, 1 ); + Buffer* buffer = uluaGetBuffer( L, 2 ); + + uluaPushMusic( L, LoadMusicStreamFromMemory( fileType, buffer->data, buffer->size ) ); + + return 1; +} + +/* > isReady = RL.IsMusicReady( Music music ) Checks if a music stream is ready @@ -3082,6 +3082,30 @@ int lcoreLoadBufferFromFile( lua_State *L ) { } /* +> buffer = RL.LoadBufferFromString( string buffer ) + +Read buffer data from string + +- Failure return nil +- Success return Buffer +*/ +int lcoreLoadBufferFromString( lua_State *L ) { + size_t len = 0; + const char *string = luaL_checklstring( L, 1, &len ); + + Buffer buffer = { + .type = BUFFER_UNSIGNED_CHAR, + .size = len, + .data = malloc( len * sizeof( unsigned char ) ) + }; + memcpy( buffer.data, string, len ); + + uluaPushBuffer( L, buffer ); + + return 1; +} + +/* > RL.UnloadBuffer( Buffer buffer ) Unload buffer data diff --git a/src/lua_core.c b/src/lua_core.c index 820cc20..3465fce 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1414,6 +1414,7 @@ void luaRegister() { /* Buffer management functions. */ assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer ); assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile ); + assingGlobalFunction( "LoadBufferFromString", lcoreLoadBufferFromString ); assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer ); assingGlobalFunction( "GetBufferData", lcoreGetBufferData ); assingGlobalFunction( "GetBufferType", lcoreGetBufferType ); @@ -1767,6 +1768,7 @@ void luaRegister() { /* Wave/Sound loading/unloading functions. */ assingGlobalFunction( "LoadSound", laudioLoadSound ); assingGlobalFunction( "LoadWave", laudioLoadWave ); + assingGlobalFunction( "LoadWaveFromMemory", laudioLoadWaveFromMemory ); assingGlobalFunction( "IsWaveReady", laudioIsWaveReady ); assingGlobalFunction( "LoadSoundFromWave", laudioLoadSoundFromWave ); assingGlobalFunction( "LoadSoundAlias", laudioLoadSoundAlias ); @@ -1790,6 +1792,7 @@ void luaRegister() { assingGlobalFunction( "WaveCrop", laudioWaveCrop ); /* Music management functions. */ assingGlobalFunction( "LoadMusicStream", laudioLoadMusicStream ); + assingGlobalFunction( "LoadMusicStreamFromMemory", laudioLoadMusicStreamFromMemory ); assingGlobalFunction( "IsMusicReady", laudioIsMusicReady ); assingGlobalFunction( "UnloadMusicStream", laudioUnloadMusicStream ); assingGlobalFunction( "PlayMusicStream", laudioPlayMusicStream ); |
