mirror of
https://github.com/love2d/love.git
synced 2026-08-17 02:58:31 +02:00
Merged in PabloMayobre/love/PabloMayobre/fix-seteffecteffect-true-and-geteffectef-1540253791471 (pull request #114)
Fix Source:setEffect and Source:getEffect.
This commit is contained in:
@@ -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<Filter::Parameter, float> 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<Filter::Parameter, float> 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)
|
||||
|
||||
Reference in New Issue
Block a user