mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Cleaned up some Proxy-related code.
This commit is contained in:
+6
-10
@@ -52,8 +52,7 @@ static int w__gc(lua_State *L)
|
|||||||
|
|
||||||
thread::Lock lock(gcmutex);
|
thread::Lock lock(gcmutex);
|
||||||
|
|
||||||
if (p->own)
|
object->release();
|
||||||
object->release();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -218,7 +217,6 @@ int luax_register_module(lua_State *L, const WrappedModule &m)
|
|||||||
luax_insistregistry(L, REGISTRY_MODULES);
|
luax_insistregistry(L, REGISTRY_MODULES);
|
||||||
|
|
||||||
Proxy *p = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
|
Proxy *p = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
|
||||||
p->own = true;
|
|
||||||
p->data = m.module;
|
p->data = m.module;
|
||||||
p->flags = m.flags;
|
p->flags = m.flags;
|
||||||
|
|
||||||
@@ -384,22 +382,20 @@ int luax_register_searcher(lua_State *L, lua_CFunction f, int pos)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void luax_rawnewtype(lua_State *L, const char *name, bits flags, love::Object *object, bool own)
|
void luax_rawnewtype(lua_State *L, const char *name, bits flags, love::Object *object)
|
||||||
{
|
{
|
||||||
Proxy *u = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
|
Proxy *u = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
|
||||||
|
|
||||||
if (own)
|
object->retain();
|
||||||
object->retain();
|
|
||||||
|
|
||||||
u->data = (void *) object;
|
u->data = (void *) object;
|
||||||
u->flags = flags;
|
u->flags = flags;
|
||||||
u->own = own;
|
|
||||||
|
|
||||||
luaL_newmetatable(L, name);
|
luaL_newmetatable(L, name);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *object, bool own)
|
void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *object)
|
||||||
{
|
{
|
||||||
if (object == nullptr)
|
if (object == nullptr)
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@@ -411,7 +407,7 @@ void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *obj
|
|||||||
if (!lua_istable(L, -1))
|
if (!lua_istable(L, -1))
|
||||||
{
|
{
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return luax_rawnewtype(L, name, flags, object, own);
|
return luax_rawnewtype(L, name, flags, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the value of lovetypes[data] on the stack.
|
// Get the value of lovetypes[data] on the stack.
|
||||||
@@ -423,7 +419,7 @@ void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *obj
|
|||||||
{
|
{
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luax_rawnewtype(L, name, flags, object, own);
|
luax_rawnewtype(L, name, flags, object);
|
||||||
|
|
||||||
lua_pushlightuserdata(L, (void *) object);
|
lua_pushlightuserdata(L, (void *) object);
|
||||||
lua_pushvalue(L, -2);
|
lua_pushvalue(L, -2);
|
||||||
|
|||||||
+7
-11
@@ -67,9 +67,6 @@ struct Proxy
|
|||||||
|
|
||||||
// The light userdata (pointer to the love::Object).
|
// The light userdata (pointer to the love::Object).
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
// Whether release() should be called on GC.
|
|
||||||
bool own;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,6 +225,9 @@ void luax_setfuncs(lua_State *L, const luaL_Reg *l);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a module in the love table. The love table will be created if it does not exist.
|
* Register a module in the love table. The love table will be created if it does not exist.
|
||||||
|
* NOTE: The module-object is expected to have a +1 reference count before calling
|
||||||
|
* this function, as it doesn't retain the object itself but Lua will release it
|
||||||
|
* upon garbage collection.
|
||||||
* @param L The Lua state.
|
* @param L The Lua state.
|
||||||
**/
|
**/
|
||||||
int luax_register_module(lua_State *L, const WrappedModule &m);
|
int luax_register_module(lua_State *L, const WrappedModule &m);
|
||||||
@@ -268,15 +268,13 @@ int luax_register_searcher(lua_State *L, lua_CFunction f, int pos = -1);
|
|||||||
/**
|
/**
|
||||||
* Pushes a Lua representation of the given object onto the stack, creating and
|
* Pushes a Lua representation of the given object onto the stack, creating and
|
||||||
* storing the Lua representation in a weak table if it doesn't exist yet.
|
* storing the Lua representation in a weak table if it doesn't exist yet.
|
||||||
* NOTE: If own is true, the object will be retained by Lua.
|
* NOTE: The object will be retained by Lua and released upon garbage collection.
|
||||||
* @param L The Lua state.
|
* @param L The Lua state.
|
||||||
* @param name The name of the type. This must match the name used with luax_register_type.
|
* @param name The name of the type. This must match the name used with luax_register_type.
|
||||||
* @param flags The type information of the object.
|
* @param flags The type information of the object.
|
||||||
* @param object The pointer to the actual object.
|
* @param object The pointer to the actual object.
|
||||||
* @param own Set this to true (default) if the object should be retained by
|
|
||||||
* Lua and released upon garbage collection.
|
|
||||||
**/
|
**/
|
||||||
void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *object, bool own = true);
|
void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Lua representation of the given object *without* checking if it
|
* Creates a new Lua representation of the given object *without* checking if it
|
||||||
@@ -284,15 +282,13 @@ void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *obj
|
|||||||
* This should only be used when performance is an extreme concern and the
|
* This should only be used when performance is an extreme concern and the
|
||||||
* object is not ever expected to be pushed to Lua again, as it prevents the
|
* object is not ever expected to be pushed to Lua again, as it prevents the
|
||||||
* Lua-side objects from working in some cases when used as keys in tables.
|
* Lua-side objects from working in some cases when used as keys in tables.
|
||||||
* NOTE: if own is true, the object will be retained by Lua.
|
* NOTE: The object will be retained by Lua and released upon garbage collection.
|
||||||
* @param L The Lua state.
|
* @param L The Lua state.
|
||||||
* @param name The name of the type. This must match the name used with luax_register_type.
|
* @param name The name of the type. This must match the name used with luax_register_type.
|
||||||
* @param flags The type information of the object.
|
* @param flags The type information of the object.
|
||||||
* @param object The pointer to the actual object.
|
* @param object The pointer to the actual object.
|
||||||
* @param own Set this to true (default) if the object should be retained by
|
|
||||||
* Lua and released upon garbage collection.
|
|
||||||
**/
|
**/
|
||||||
void luax_rawnewtype(lua_State *L, const char *name, bits flags, love::Object *object, bool own = true);
|
void luax_rawnewtype(lua_State *L, const char *name, bits flags, love::Object *object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the value at idx is a certain type.
|
* Checks whether the value at idx is a certain type.
|
||||||
|
|||||||
@@ -282,8 +282,8 @@ int w_newImageFont(lua_State *L)
|
|||||||
filter = i->getFilter();
|
filter = i->getFilter();
|
||||||
love::image::ImageData *id = i->getImageData();
|
love::image::ImageData *id = i->getImageData();
|
||||||
if (!id)
|
if (!id)
|
||||||
return luaL_argerror(L, 1, "Image cannot be compressed.");
|
return luaL_argerror(L, 1, "Image must not be compressed.");
|
||||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, id, false);
|
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, id);
|
||||||
lua_replace(L, 1);
|
lua_replace(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user