mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Replaced the EXCEPT_GUARD macro for converting love exceptions into Lua errors with the new luax_catchexcept function, which takes lambda function arguments.
This commit is contained in:
@@ -43,7 +43,7 @@ int w_newSoundData(lua_State *L)
|
||||
int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
|
||||
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
|
||||
|
||||
EXCEPT_GUARD(t = instance->newSoundData(samples, sampleRate, bitDepth, channels);)
|
||||
luax_catchexcept(L, [&](){ t = instance->newSoundData(samples, sampleRate, bitDepth, channels); });
|
||||
}
|
||||
// Must be string or decoder.
|
||||
else
|
||||
@@ -55,7 +55,7 @@ int w_newSoundData(lua_State *L)
|
||||
lua_replace(L, 1);
|
||||
}
|
||||
|
||||
EXCEPT_GUARD(t = instance->newSoundData(luax_checkdecoder(L, 1));)
|
||||
luax_catchexcept(L, [&](){ t = instance->newSoundData(luax_checkdecoder(L, 1)); });
|
||||
}
|
||||
|
||||
luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, t);
|
||||
@@ -68,7 +68,10 @@ int w_newDecoder(lua_State *L)
|
||||
int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
|
||||
|
||||
Decoder *t = nullptr;
|
||||
EXCEPT_GUARD_FINALLY(t = instance->newDecoder(data, bufferSize);, data->release();)
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance->newDecoder(data, bufferSize); },
|
||||
[&]() { data->release(); }
|
||||
);
|
||||
|
||||
if (t == nullptr)
|
||||
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
|
||||
@@ -96,7 +99,7 @@ extern "C" int luaopen_love_sound(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new lullaby::Sound();)
|
||||
luax_catchexcept(L, [&](){ instance = new lullaby::Sound(); });
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
@@ -73,7 +73,7 @@ int w_SoundData_setSample(lua_State *L)
|
||||
int i = (int) luaL_checkinteger(L, 2);
|
||||
float sample = (float) luaL_checknumber(L, 3);
|
||||
|
||||
EXCEPT_GUARD(sd->setSample(i, sample);)
|
||||
luax_catchexcept(L, [&](){ sd->setSample(i, sample); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ int w_SoundData_getSample(lua_State *L)
|
||||
SoundData *sd = luax_checksounddata(L, 1);
|
||||
int i = (int) luaL_checkinteger(L, 2);
|
||||
|
||||
EXCEPT_GUARD(lua_pushnumber(L, sd->getSample(i));)
|
||||
luax_catchexcept(L, [&](){ lua_pushnumber(L, sd->getSample(i)); });
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user