diff --git a/src/modules/audio/wrap_Source.cpp b/src/modules/audio/wrap_Source.cpp index e9b1b1e91..eaf8a6ff8 100644 --- a/src/modules/audio/wrap_Source.cpp +++ b/src/modules/audio/wrap_Source.cpp @@ -471,8 +471,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; @@ -480,10 +482,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; } @@ -494,13 +497,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)