From 9e1e35ff3916850d67e2271922ffef5cb17393d0 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Sat, 28 May 2022 19:17:50 +0800 Subject: [PATCH] Fixed love.audio.newSource(SoundData) variant. --- src/modules/audio/wrap_Audio.cpp | 45 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index 957b11abd..32f8c24bf 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -48,32 +48,35 @@ int w_newSource(lua_State *L) { Source::Type stype = Source::TYPE_STREAM; - if (!luax_istype(L, 1, love::sound::SoundData::type) && !luax_istype(L, 1, love::sound::Decoder::type)) + if (!luax_istype(L, 1, love::sound::SoundData::type)) { - const char *stypestr = luaL_checkstring(L, 2); - if (stypestr && !Source::getConstant(stypestr, stype)) - return luax_enumerror(L, "source type", Source::getConstants(stype), stypestr); + if (!luax_istype(L, 1, love::sound::Decoder::type)) + { + const char *stypestr = luaL_checkstring(L, 2); + if (stypestr && !Source::getConstant(stypestr, stype)) + return luax_enumerror(L, "source type", Source::getConstants(stype), stypestr); - if (stype == Source::TYPE_QUEUE) - return luaL_error(L, "Cannot create queueable sources using newSource. Use newQueueableSource instead."); - } + if (stype == Source::TYPE_QUEUE) + return luaL_error(L, "Cannot create queueable sources using newSource. Use newQueueableSource instead."); + } - if (love::filesystem::luax_cangetdata(L, 1)) - { - // stream type - if (stype == Source::TYPE_STATIC) - lua_pushstring(L, "memory"); - else if (!lua_isnone(L, 3)) - lua_pushvalue(L, 3); - else + if (love::filesystem::luax_cangetdata(L, 1)) + { + // stream type + if (stype == Source::TYPE_STATIC) + lua_pushstring(L, "memory"); + else if (!lua_isnone(L, 3)) + lua_pushvalue(L, 3); + else + lua_pushnil(L); + + // buffer size lua_pushnil(L); - // buffer size - lua_pushnil(L); - - // (file, buffer size, stream type) - int idxs[] = { 1, lua_gettop(L), lua_gettop(L) - 1 }; - luax_convobj(L, idxs, 3, "sound", "newDecoder"); + // (file, buffer size, stream type) + int idxs[] = { 1, lua_gettop(L), lua_gettop(L) - 1 }; + luax_convobj(L, idxs, 3, "sound", "newDecoder"); + } } if (stype == Source::TYPE_STATIC && luax_istype(L, 1, love::sound::Decoder::type))