ref: 7e690483be7c21cdd869f9686f9c2ff5ccc3c3fe
parent: 9b93e2f3b8bfb3010e224ae540c3d74e53f308c2
author: telephil9 <telephil9@gmail.com>
date: Tue Oct 27 09:48:19 EDT 2020
Implement Font __gc metamethod Fonts will now be freed as part of the garbage collection cycles
--- a/font.c
+++ b/font.c
@@ -40,8 +40,17 @@
static int
font__gc(lua_State *L)
{
- /* TODO */
- lua_pushboolean(L, 0);
+ LFont *l;
+
+ l = (LFont*)luaL_checkudata(L, 1, FONT);
+ luaL_argcheck(L, l != NULL, 1, "Font expected");
+ if(l->f == font){
+ lua_pushboolean(L, 0);
+ return 1;
+ }
+ freefont(l->f);
+ free(l);
+ lua_pushboolean(L, 1);
return 1;
}