LoadBufferFromString, LoadWaveFromMemory and LoadMusicStreamFromMemory.

This commit is contained in:
jussi
2024-01-24 19:14:30 +02:00
parent 7460a16cae
commit 3b3d0ad32e
12 changed files with 113 additions and 3 deletions

25
API.md
View File

@@ -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 ) > RL.UnloadBuffer( Buffer buffer )
Unload buffer data 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 ) > isReady = RL.IsWaveReady( Wave wave )
Checks if wave data is ready 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 ) > isReady = RL.IsMusicReady( Music music )
Checks if a music stream is ready Checks if a music stream is ready

View File

@@ -1,6 +1,6 @@
MIT License 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -2415,6 +2415,13 @@ function RL.LoadBuffer( buffer, type ) end
---@return any buffer ---@return any buffer
function RL.LoadBufferFromFile( path, int ) end 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 ---Unload buffer data
---@param buffer any ---@param buffer any
---@return any RL.UnloadBuffer ---@return any RL.UnloadBuffer
@@ -4761,6 +4768,13 @@ function RL.LoadSound( fileName ) end
---@return any wave ---@return any wave
function RL.LoadWave( fileName ) end 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 ---Checks if wave data is ready
---- Success return bool ---- Success return bool
---@param wave any ---@param wave any
@@ -4889,6 +4903,13 @@ function RL.WaveCrop( wave, initSample, finalSample ) end
---@return any music ---@return any music
function RL.LoadMusicStream( fileName ) end 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 ---Checks if a music stream is ready
---- Success return bool ---- Success return bool
---@param music any ---@param music any

View File

@@ -62,6 +62,7 @@ DETAILED CHANGES:
- ADDED: Raygui lib extensions example. - ADDED: Raygui lib extensions example.
- CHANGE: Raygui.h returns textBounds for some controls. - CHANGE: Raygui.h returns textBounds for some controls.
- CHANGE: Raygui lib changed term element to control to correspond raylib naming. - 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 Release: ReiLua version 0.6.0 Using Raylib 4.5

View File

@@ -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 } ) RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
end end
function ray_collision() local function ray_collision()
rayCol = RL.GetRayCollisionMesh( ray, sphereMesh, RL.MatrixIdentity() ) rayCol = RL.GetRayCollisionMesh( ray, sphereMesh, RL.MatrixIdentity() )
if rayCol ~= nil and rayCol.hit then if rayCol ~= nil and rayCol.hit then

View File

@@ -36,6 +36,7 @@ local function addButton( bounds, text, callback )
callback, callback,
{ {
{ RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER }, { 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_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_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
{ RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) }, { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },

View File

@@ -101,7 +101,7 @@ function PropertyList:updateContent()
self._forceCheckScroll = true self._forceCheckScroll = true
end 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 ) function PropertyList:addControl( control, group, noYAdvance )
control._noYAdvance = noYAdvance control._noYAdvance = noYAdvance

View File

@@ -9,6 +9,7 @@ int laudioGetMasterVolume( lua_State *L );
/* Wave/Sound loading/unloading functions. */ /* Wave/Sound loading/unloading functions. */
int laudioLoadSound( lua_State *L ); int laudioLoadSound( lua_State *L );
int laudioLoadWave( lua_State *L ); int laudioLoadWave( lua_State *L );
int laudioLoadWaveFromMemory( lua_State *L );
int laudioIsWaveReady( lua_State *L ); int laudioIsWaveReady( lua_State *L );
int laudioLoadSoundFromWave( lua_State *L ); int laudioLoadSoundFromWave( lua_State *L );
int laudioLoadSoundAlias( lua_State *L ); int laudioLoadSoundAlias( lua_State *L );
@@ -32,6 +33,7 @@ int laudioWaveCopy( lua_State *L );
int laudioWaveCrop( lua_State *L ); int laudioWaveCrop( lua_State *L );
/* Music management functions. */ /* Music management functions. */
int laudioLoadMusicStream( lua_State *L ); int laudioLoadMusicStream( lua_State *L );
int laudioLoadMusicStreamFromMemory( lua_State *L );
int laudioIsMusicReady( lua_State *L ); int laudioIsMusicReady( lua_State *L );
int laudioUnloadMusicStream( lua_State *L ); int laudioUnloadMusicStream( lua_State *L );
int laudioPlayMusicStream( lua_State *L ); int laudioPlayMusicStream( lua_State *L );

View File

@@ -222,6 +222,7 @@ 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 lcoreLoadBufferFromFile( lua_State *L );
int lcoreLoadBufferFromString( 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 );

View File

@@ -112,6 +112,22 @@ int laudioLoadWave( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > isReady = RL.IsWaveReady( Wave wave )
@@ -423,6 +439,22 @@ int laudioLoadMusicStream( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > isReady = RL.IsMusicReady( Music music )

View File

@@ -3081,6 +3081,30 @@ int lcoreLoadBufferFromFile( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > RL.UnloadBuffer( Buffer buffer )

View File

@@ -1414,6 +1414,7 @@ void luaRegister() {
/* Buffer management functions. */ /* Buffer management functions. */
assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer ); assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer );
assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile ); assingGlobalFunction( "LoadBufferFromFile", lcoreLoadBufferFromFile );
assingGlobalFunction( "LoadBufferFromString", lcoreLoadBufferFromString );
assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer ); assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer );
assingGlobalFunction( "GetBufferData", lcoreGetBufferData ); assingGlobalFunction( "GetBufferData", lcoreGetBufferData );
assingGlobalFunction( "GetBufferType", lcoreGetBufferType ); assingGlobalFunction( "GetBufferType", lcoreGetBufferType );
@@ -1767,6 +1768,7 @@ void luaRegister() {
/* Wave/Sound loading/unloading functions. */ /* Wave/Sound loading/unloading functions. */
assingGlobalFunction( "LoadSound", laudioLoadSound ); assingGlobalFunction( "LoadSound", laudioLoadSound );
assingGlobalFunction( "LoadWave", laudioLoadWave ); assingGlobalFunction( "LoadWave", laudioLoadWave );
assingGlobalFunction( "LoadWaveFromMemory", laudioLoadWaveFromMemory );
assingGlobalFunction( "IsWaveReady", laudioIsWaveReady ); assingGlobalFunction( "IsWaveReady", laudioIsWaveReady );
assingGlobalFunction( "LoadSoundFromWave", laudioLoadSoundFromWave ); assingGlobalFunction( "LoadSoundFromWave", laudioLoadSoundFromWave );
assingGlobalFunction( "LoadSoundAlias", laudioLoadSoundAlias ); assingGlobalFunction( "LoadSoundAlias", laudioLoadSoundAlias );
@@ -1790,6 +1792,7 @@ void luaRegister() {
assingGlobalFunction( "WaveCrop", laudioWaveCrop ); assingGlobalFunction( "WaveCrop", laudioWaveCrop );
/* Music management functions. */ /* Music management functions. */
assingGlobalFunction( "LoadMusicStream", laudioLoadMusicStream ); assingGlobalFunction( "LoadMusicStream", laudioLoadMusicStream );
assingGlobalFunction( "LoadMusicStreamFromMemory", laudioLoadMusicStreamFromMemory );
assingGlobalFunction( "IsMusicReady", laudioIsMusicReady ); assingGlobalFunction( "IsMusicReady", laudioIsMusicReady );
assingGlobalFunction( "UnloadMusicStream", laudioUnloadMusicStream ); assingGlobalFunction( "UnloadMusicStream", laudioUnloadMusicStream );
assingGlobalFunction( "PlayMusicStream", laudioPlayMusicStream ); assingGlobalFunction( "PlayMusicStream", laudioPlayMusicStream );