mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user