math and data module instances are now deleted when they have no more Lua references (matches the behaviour of other modules.) Fixes the deprecation system not fully restarting when love.event.quit("restart") is called.

Resolves issue #1462.
This commit is contained in:
Alex Szpakowski
2018-12-17 16:44:13 -04:00
parent d4762b4612
commit 5d5c2f9a96
6 changed files with 38 additions and 41 deletions
+15 -7
View File
@@ -44,9 +44,11 @@ namespace love
namespace math
{
#define instance() (Module::getInstance<Math>(Module::M_MATH))
int w__getRandomGenerator(lua_State *L)
{
RandomGenerator *t = Math::instance.getRandomGenerator();
RandomGenerator *t = instance()->getRandomGenerator();
luax_pushtype(L, t);
return 1;
}
@@ -57,7 +59,7 @@ int w_newRandomGenerator(lua_State *L)
if (lua_gettop(L) > 0)
s = luax_checkrandomseed(L, 1);
RandomGenerator *t = Math::instance.newRandomGenerator();
RandomGenerator *t = instance()->newRandomGenerator();
if (lua_gettop(L) > 0)
{
@@ -116,7 +118,7 @@ int w_newBezierCurve(lua_State *L)
}
}
BezierCurve *curve = Math::instance.newBezierCurve(points);
BezierCurve *curve = instance()->newBezierCurve(points);
luax_pushtype(L, curve);
curve->release();
return 1;
@@ -127,7 +129,7 @@ int w_newTransform(lua_State *L)
Transform *t = nullptr;
if (lua_isnoneornil(L, 1))
t = Math::instance.newTransform();
t = instance()->newTransform();
else
{
float x = (float) luaL_checknumber(L, 1);
@@ -139,7 +141,7 @@ int w_newTransform(lua_State *L)
float oy = (float) luaL_optnumber(L, 7, 0.0);
float kx = (float) luaL_optnumber(L, 8, 0.0);
float ky = (float) luaL_optnumber(L, 9, 0.0);
t = Math::instance.newTransform(x, y, a, sx, sy, ox, oy, kx, ky);
t = instance()->newTransform(x, y, a, sx, sy, ox, oy, kx, ky);
}
luax_pushtype(L, t);
@@ -478,10 +480,16 @@ static const lua_CFunction types[] =
extern "C" int luaopen_love_math(lua_State *L)
{
Math::instance.retain();
Math *instance = instance();
if (instance == nullptr)
{
luax_catchexcept(L, [&](){ instance = new Math(); });
}
else
instance->retain();
WrappedModule w;
w.module = &Math::instance;
w.module = instance;
w.name = "math";
w.type = &Module::type;
w.functions = functions;