Updated the Lua wrapper code for modules to account for cases where the module's instance is removed from memory completely and recreated during the program's lifetime.

This commit is contained in:
Alex Szpakowski
2014-07-21 14:52:01 -03:00
parent e87fbdcaaf
commit 014b9a46e5
45 changed files with 432 additions and 316 deletions
+6 -5
View File
@@ -30,7 +30,7 @@ namespace love
namespace sound
{
static Sound *instance = 0;
#define instance() (Module::getInstance<Sound>(Module::M_SOUND))
int w_newSoundData(lua_State *L)
{
@@ -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);
luax_catchexcept(L, [&](){ 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);
}
luax_catchexcept(L, [&](){ 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);
@@ -69,7 +69,7 @@ int w_newDecoder(lua_State *L)
Decoder *t = nullptr;
luax_catchexcept(L,
[&]() { t = instance->newDecoder(data, bufferSize); },
[&]() { t = instance()->newDecoder(data, bufferSize); },
[&]() { data->release(); }
);
@@ -97,7 +97,8 @@ static const lua_CFunction types[] =
extern "C" int luaopen_love_sound(lua_State *L)
{
if (instance == 0)
Sound *instance = instance();
if (instance == nullptr)
{
luax_catchexcept(L, [&](){ instance = new lullaby::Sound(); });
}