From: Michael Tremer Date: Thu, 22 Feb 2024 14:16:29 +0000 (+0000) Subject: lua: network: Add a __close method X-Git-Tag: 0.9.18~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b296c60e4ca856416a975b77b1ec97ab2c860c7;p=location%2Flibloc.git lua: network: Add a __close method Signed-off-by: Michael Tremer --- diff --git a/src/lua/network.c b/src/lua/network.c index 5a6c68a..2a75f75 100644 --- a/src/lua/network.c +++ b/src/lua/network.c @@ -72,13 +72,24 @@ static int Network_new(lua_State* L) { return r; } -static int Network_gc(lua_State* L) { - Network* self = luaL_checknetwork(L, 0); +static int Network_close(lua_State* L) { + Network* self = luaL_checknetwork(L, 1); - if (self->network) + // Free the network + if (self->network) { loc_network_unref(self->network); + self->network = NULL; + } + + return 0; +} +static int Network_gc(lua_State* L) { + Network* self = luaL_checknetwork(L, 1); + + // Free the object free(self); + return 0; } @@ -139,6 +150,7 @@ static const struct luaL_Reg Network_functions[] = { { "get_asn", Network_get_asn }, { "get_family", Network_get_family }, { "get_country_code", Network_get_country_code }, + { "__close", Network_close }, { "__gc", Network_gc }, { "__tostring", Network_tostring }, { NULL, NULL },