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:
Alex Szpakowski
2014-06-03 19:27:00 -03:00
parent 724bdbd296
commit dfa319e01a
45 changed files with 315 additions and 227 deletions
+7 -4
View File
@@ -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();
+2 -2
View File
@@ -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;
}