mirror of
https://github.com/love2d/love.git
synced 2026-08-13 17:10:54 +02:00
Changed luax_pushtype to retain the pushed object itself, but only if the object isn't in the Lua state already.
Previously, calling e.g. love.graphics.getFont() 10,000 times would retain the object 10,000 times (and release it 10,000 times when the Font object was garbage-collected in the Lua state.) Now it will only retain it once and release it once.
This commit is contained in:
@@ -145,6 +145,7 @@ int w_newFile(lua_State *L)
|
||||
}
|
||||
|
||||
luax_pushtype(L, "File", FILESYSTEM_FILE_T, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -210,6 +211,7 @@ int w_newFileData(lua_State *L)
|
||||
return luax_ioError(L, "%s", e.what());
|
||||
}
|
||||
luax_pushtype(L, "FileData", FILESYSTEM_FILE_DATA_T, data);
|
||||
data->release();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -241,6 +243,7 @@ int w_newFileData(lua_State *L)
|
||||
}
|
||||
|
||||
luax_pushtype(L, "FileData", FILESYSTEM_FILE_DATA_T, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -403,9 +406,13 @@ int w_lines(lua_State *L)
|
||||
luax_catchexcept(L, [&](){ success = file->open(File::READ); });
|
||||
|
||||
if (!success)
|
||||
{
|
||||
file->release();
|
||||
return luaL_error(L, "Could not open file.");
|
||||
|
||||
}
|
||||
|
||||
luax_pushtype(L, "File", FILESYSTEM_FILE_T, file);
|
||||
file->release();
|
||||
}
|
||||
else
|
||||
return luaL_argerror(L, 1, "expected filename.");
|
||||
|
||||
Reference in New Issue
Block a user