The Proxy struct now stores an actual love::Object pointer (rather than void*), which makes code using Proxies a bit cleaner.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2015-02-21 20:52:29 -04:00
parent e26e170f78
commit 33d20620b5
5 changed files with 30 additions and 33 deletions
+2 -2
View File
@@ -102,8 +102,8 @@ Variant::Variant(love::Type udatatype, void *userdata)
{
Proxy *p = (Proxy *) userdata;
flags = p->flags;
data.userdata = p->data;
((love::Object *) data.userdata)->retain();
data.userdata = p->object;
p->object->retain();
}
else
data.userdata = userdata;
+4 -7
View File
@@ -42,10 +42,7 @@ namespace love
static int w__gc(lua_State *L)
{
Proxy *p = (Proxy *) lua_touserdata(L, 1);
Object *object = (Object *) p->data;
object->release();
p->object->release();
return 0;
}
@@ -67,7 +64,7 @@ static int w__eq(lua_State *L)
{
Proxy *p1 = (Proxy *)lua_touserdata(L, 1);
Proxy *p2 = (Proxy *)lua_touserdata(L, 2);
luax_pushboolean(L, p1->data == p2->data);
luax_pushboolean(L, p1->object == p2->object);
return 1;
}
@@ -209,7 +206,7 @@ int luax_register_module(lua_State *L, const WrappedModule &m)
luax_insistregistry(L, REGISTRY_MODULES);
Proxy *p = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
p->data = m.module;
p->object = m.module;
p->flags = m.flags;
luaL_newmetatable(L, m.module->getName());
@@ -383,7 +380,7 @@ void luax_rawnewtype(lua_State *L, const char *name, bits flags, love::Object *o
object->retain();
u->data = (void *) object;
u->object = object;
u->flags = flags;
luaL_newmetatable(L, name);
+6 -6
View File
@@ -65,8 +65,8 @@ struct Proxy
// Holds type information (see types.h).
bits flags;
// The light userdata (pointer to the love::Object).
void *data;
// Pointer to the actual object.
Object *object;
};
/**
@@ -409,7 +409,7 @@ T *luax_checktype(lua_State *L, int idx, const char *name, love::bits type)
if ((u->flags & type) != type)
luax_typerror(L, idx, name);
return (T *)u->data;
return (T *)u->object;
}
template <typename T>
@@ -428,7 +428,7 @@ T *luax_getmodule(lua_State *L, const char *k, love::bits type)
lua_pop(L, 2);
return (T *)u->data;
return (T *)u->object;
}
template <typename T>
@@ -450,7 +450,7 @@ T *luax_optmodule(lua_State *L, const char *k, love::bits type)
lua_pop(L, 2);
return (T *) u->data;
return (T *) u->object;
}
/**
@@ -465,7 +465,7 @@ T *luax_optmodule(lua_State *L, const char *k, love::bits type)
template <typename T>
T *luax_totype(lua_State *L, int idx, const char * /* name */, love::bits /* type */)
{
return (T *)(((Proxy *)lua_touserdata(L, idx))->data);
return (T *)(((Proxy *)lua_touserdata(L, idx))->object);
}
Type luax_type(lua_State *L, int idx);