From e840631388335c6f0dc365f1448a11ea30764485 Mon Sep 17 00:00:00 2001 From: Pablo Mayobre Date: Tue, 23 Oct 2018 00:17:19 +0000 Subject: [PATCH 1/2] Fix :setEffect("effect", true) and :getEffect("effect") when no filter is associated to the effect. Fixes #1449 --HG-- branch : PabloMayobre/fix-seteffecteffect-true-and-geteffectef-1540253791471 --- src/modules/audio/wrap_Source.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/modules/audio/wrap_Source.cpp b/src/modules/audio/wrap_Source.cpp index 273b48f09..40c2a420e 100644 --- a/src/modules/audio/wrap_Source.cpp +++ b/src/modules/audio/wrap_Source.cpp @@ -464,8 +464,10 @@ int w_Source_setEffect(lua_State *L) Source *t = luax_checksource(L, 1); const char *namestr = luaL_checkstring(L, 2); + const bool isBool = lua_gettop(L) == 3 && lua_isboolean(L, 3); + // :setEffect(effect, false) = clear effect - if (lua_gettop(L) == 3 && lua_isboolean(L, 3) && !lua_toboolean(L, 3)) + if (isBool && !lua_toboolean(L, 3)) { luax_catchexcept(L, [&]() { lua_pushboolean(L, t->unsetEffect(namestr)); }); return 1; @@ -473,10 +475,11 @@ int w_Source_setEffect(lua_State *L) std::map params; - if (setFilterReadFilter(L, 3, params) == 1) - luax_catchexcept(L, [&]() { lua_pushboolean(L, t->setEffect(namestr, params)); }); - else + // :setEffect(effect, [true]) = set effect without filter + if (isBool || setFilterReadFilter(L, 3, params) == 0) luax_catchexcept(L, [&]() { lua_pushboolean(L, t->setEffect(namestr)); }); + else + luax_catchexcept(L, [&]() { lua_pushboolean(L, t->setEffect(namestr, params)); }); return 1; } @@ -487,13 +490,20 @@ int w_Source_getEffect(lua_State *L) std::map params; if (!t->getEffect(namestr, params)) - return 0; + { + luax_pushboolean(L, false); + return 1; + } + luax_pushboolean(L, true); + + // No filter associated, return nil as second argument if (params.size() == 0) - return 0; + return 1; + // Return filter settings as second argument getFilterWriteFilter(L, 3, params); - return 1; + return 2; } int w_Source_getActiveEffects(lua_State *L) From 1670edf4babd2017f3df20c146d00ac88d163811 Mon Sep 17 00:00:00 2001 From: Pablo Mayobre Date: Fri, 30 Nov 2018 04:01:52 +0000 Subject: [PATCH 2/2] Fix Source:setEffect working incorrectly when a fourth or more arguments are passed --HG-- branch : PabloMayobre/fix-seteffecteffect-true-and-geteffectef-1540253791471 --- src/modules/audio/wrap_Source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/audio/wrap_Source.cpp b/src/modules/audio/wrap_Source.cpp index 40c2a420e..cde4f1767 100644 --- a/src/modules/audio/wrap_Source.cpp +++ b/src/modules/audio/wrap_Source.cpp @@ -464,7 +464,7 @@ int w_Source_setEffect(lua_State *L) Source *t = luax_checksource(L, 1); const char *namestr = luaL_checkstring(L, 2); - const bool isBool = lua_gettop(L) == 3 && lua_isboolean(L, 3); + const bool isBool = lua_gettop(L) >= 3 && lua_isboolean(L, 3); // :setEffect(effect, false) = clear effect if (isBool && !lua_toboolean(L, 3))