From 00a33785797a4777f1e68c1ace9de37cd25260e8 Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sun, 29 Oct 2023 20:48:45 +0400 Subject: [PATCH] Add LoadMusicStreamFromMemory function --- src/audio.h | 14 ++++++++++++++ src/text.h | 10 ---------- src/types.h | 10 ++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/audio.h b/src/audio.h index 8aa3f5d..9b6942f 100644 --- a/src/audio.h +++ b/src/audio.h @@ -178,6 +178,16 @@ static Janet cfun_LoadMusicStream(int32_t argc, Janet *argv) { return janet_wrap_abstract(music); } +static Janet cfun_LoadMusicStreamFromMemory(int32_t argc, Janet *argv) { + janet_fixarity(argc, 3); + const char *fileType = janet_getcstring(argv, 0); + const unsigned char *data = jaylib_getunsignedcstring(argv, 1); + int dataSize = janet_getinteger(argv, 2); + Music *music = janet_abstract(&AT_Music, sizeof(Music)); + *music = LoadMusicStreamFromMemory(fileType, data, dataSize); + return janet_wrap_abstract(music); +} + static Janet cfun_IsMusicReady(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); Music music = *jaylib_getmusic(argv, 0); @@ -446,6 +456,10 @@ static JanetReg audio_cfuns[] = { "(load-music-stream file-name)\n\n" "Load music stream from file" }, + {"load-music-stream-from-memory", cfun_LoadMusicStreamFromMemory, + "(load-music-stream-from-memory file-type data data-size)\n\n" + "Load music stream from data" + }, {"music-ready?", cfun_IsMusicReady, "(music-ready? wave)\n\n" "Checks if a music stream is ready" diff --git a/src/text.h b/src/text.h index 7812f00..c9712df 100644 --- a/src/text.h +++ b/src/text.h @@ -15,16 +15,6 @@ static const char *jaylib_getcstring(const Janet *argv, int32_t n) { return janet_getcstring(argv, n); } -static const unsigned char *jaylib_getunsignedcstring(const Janet *argv, int32_t n) { - if (janet_checktype(argv[n], JANET_BUFFER)) { - JanetBuffer *buf = janet_unwrap_buffer(argv[n]); - janet_buffer_push_u8(buf, 0); - buf->count--; - return (const unsigned char *)buf->data; - } - return (const unsigned char *)janet_getcstring(argv, n); -} - static Janet cfun_GetFontDefault(int32_t argc, Janet *argv) { (void) argv; janet_fixarity(argc, 0); diff --git a/src/types.h b/src/types.h index dbc989a..46bda33 100644 --- a/src/types.h +++ b/src/types.h @@ -700,3 +700,13 @@ static Janet jaylib_wrap_raycollision(RayCollision rayCollision) { janet_table_put(table, janet_wrap_keyword("normal"), jaylib_wrap_vec3(rayCollision.normal)); return janet_wrap_table(table); } + +static const unsigned char *jaylib_getunsignedcstring(const Janet *argv, int32_t n) { + if (janet_checktype(argv[n], JANET_BUFFER)) { + JanetBuffer *buf = janet_unwrap_buffer(argv[n]); + janet_buffer_push_u8(buf, 0); + buf->count--; + return (const unsigned char *)buf->data; + } + return (const unsigned char *)janet_getcstring(argv, n); +}