mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
love.graphics.newImage, love.image.newImageData, etc. no longer leave Lua-owned FileData objects floating around waiting to be GC'd when called with filename arguments, resulting in less memory use on startup (resolves issue #890.)
Moved love.filesystem Lua wrapper code from src/modules/filesystem/physfs/ to src/modules/filesystem/.
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include "font/wrap_GlyphData.h"
|
||||
#include "font/wrap_Rasterizer.h"
|
||||
|
||||
#include "filesystem/wrap_Filesystem.h"
|
||||
|
||||
#include "TrueTypeRasterizer.h"
|
||||
|
||||
namespace love
|
||||
@@ -34,31 +36,25 @@ namespace font
|
||||
namespace freetype
|
||||
{
|
||||
|
||||
static Font *instance = 0;
|
||||
static Font *instance = nullptr;
|
||||
|
||||
int w_newRasterizer(lua_State *L)
|
||||
{
|
||||
// Convert to FileData, if necessary.
|
||||
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
luax_convobj(L, 1, "filesystem", "newFileData");
|
||||
Rasterizer *t = nullptr;
|
||||
|
||||
Rasterizer *t = 0;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
|
||||
{
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
const char *g = luaL_checkstring(L, 2);
|
||||
std::string glyphs(g);
|
||||
t = instance->newRasterizer(d, glyphs);
|
||||
}
|
||||
else if (luax_istype(L, 1, DATA_T))
|
||||
{
|
||||
Data *d = luax_checkdata(L, 1);
|
||||
int size = luaL_checkint(L, 2);
|
||||
t = instance->newRasterizer(d, size);
|
||||
}
|
||||
)
|
||||
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
|
||||
{
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
const char *g = luaL_checkstring(L, 2);
|
||||
std::string glyphs(g);
|
||||
EXCEPT_GUARD(t = instance->newRasterizer(d, glyphs);)
|
||||
}
|
||||
else if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
||||
{
|
||||
love::filesystem::FileData *d = love::filesystem::luax_getFileData(L, 1);
|
||||
int size = luaL_checkint(L, 2);
|
||||
EXCEPT_GUARD_FINALLY(t = instance->newRasterizer(d, size);, d->release();)
|
||||
}
|
||||
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
return 1;
|
||||
@@ -67,13 +63,12 @@ int w_newRasterizer(lua_State *L)
|
||||
int w_newGlyphData(lua_State *L)
|
||||
{
|
||||
Rasterizer *r = luax_checkrasterizer(L, 1);
|
||||
GlyphData *t = 0;
|
||||
GlyphData *t = nullptr;
|
||||
|
||||
// newGlyphData accepts a unicode character or a codepoint number.
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
std::string glyph = luax_checkstring(L, 2);
|
||||
|
||||
EXCEPT_GUARD(t = instance->newGlyphData(r, glyph);)
|
||||
}
|
||||
else
|
||||
@@ -103,7 +98,7 @@ static const lua_CFunction types[] =
|
||||
|
||||
extern "C" int luaopen_love_font(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new Font();)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user