diff --git a/common/luaclass.c b/common/luaclass.c index 6214c2625..53f6e85e3 100644 --- a/common/luaclass.c +++ b/common/luaclass.c @@ -174,6 +174,7 @@ luaA_class_gc(lua_State *L) signal_array_wipe(&item->signals); /* Get the object class */ lua_class_t *class = luaA_class_get(L, 1); + class->instances--; /* Call the collector function of the class, and all its parent classes */ for(; class; class = class->parent) if(class->collector) @@ -243,6 +244,7 @@ luaA_class_setup(lua_State *L, lua_class_t *class, class->newindex_miss_property = newindex_miss_property; class->checker = checker; class->parent = parent; + class->instances = 0; signal_add(&class->signals, "new"); diff --git a/common/luaclass.h b/common/luaclass.h index db1f2cf26..3186416e9 100644 --- a/common/luaclass.h +++ b/common/luaclass.h @@ -67,6 +67,8 @@ struct lua_class_t lua_class_propfunc_t newindex_miss_property; /** Function to call to check if an object is valid */ lua_class_checker_t checker; + /** Number of instances of this class in lua */ + unsigned int instances; }; const char * luaA_typename(lua_State *, int); @@ -133,13 +135,21 @@ luaA_checkudataornil(lua_State *L, int udx, lua_class_t *class) luaA_class_emit_signal(L, &(lua_class), luaL_checkstring(L, 1), \ lua_gettop(L) - 1); \ return 0; \ + } \ + \ + static inline int \ + luaA_##prefix##_class_instances(lua_State *L) \ + { \ + lua_pushnumber(L, (lua_class).instances); \ + return 1; \ } #define LUA_CLASS_METHODS(class) \ { "add_signal", luaA_##class##_class_add_signal }, \ { "connect_signal", luaA_##class##_class_connect_signal }, \ { "disconnect_signal", luaA_##class##_class_disconnect_signal }, \ - { "emit_signal", luaA_##class##_class_emit_signal }, + { "emit_signal", luaA_##class##_class_emit_signal }, \ + { "instances", luaA_##class##_class_instances }, \ #define LUA_CLASS_META \ { "__index", luaA_class_index }, \ diff --git a/common/luaobject.h b/common/luaobject.h index 26ed2c92c..3761e12b0 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -167,6 +167,7 @@ int luaA_object_emit_signal_simple(lua_State *); { \ type *p = lua_newuserdata(L, sizeof(type)); \ p_clear(p, 1); \ + (lua_class).instances++; \ luaA_settype(L, &(lua_class)); \ lua_newtable(L); \ lua_newtable(L); \ diff --git a/luadoc/button.lua b/luadoc/button.lua index 20103e0a9..124dc84d0 100644 --- a/luadoc/button.lua +++ b/luadoc/button.lua @@ -27,3 +27,8 @@ module("button") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of button objects alive. +-- @name instances +-- @class function diff --git a/luadoc/client.lua b/luadoc/client.lua index ba0586a74..788d0de12 100644 --- a/luadoc/client.lua +++ b/luadoc/client.lua @@ -128,3 +128,8 @@ module("client") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of client objects alive. +-- @name instances +-- @class function diff --git a/luadoc/image.lua b/luadoc/image.lua index 6e1edf6ce..7e24a8d2a 100644 --- a/luadoc/image.lua +++ b/luadoc/image.lua @@ -128,3 +128,8 @@ module("image") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of image objects alive. +-- @name instances +-- @class function diff --git a/luadoc/key.lua b/luadoc/key.lua index 810f6e23b..c4a6a4e30 100644 --- a/luadoc/key.lua +++ b/luadoc/key.lua @@ -30,3 +30,8 @@ module("key") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of key objects alive. +-- @name instances +-- @class function diff --git a/luadoc/tag.lua b/luadoc/tag.lua index 349d3f62e..69b4046e8 100644 --- a/luadoc/tag.lua +++ b/luadoc/tag.lua @@ -33,3 +33,8 @@ module("tag") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of tag objects alive. +-- @name instances +-- @class function diff --git a/luadoc/timer.lua b/luadoc/timer.lua index 019b11138..0a8b42c36 100644 --- a/luadoc/timer.lua +++ b/luadoc/timer.lua @@ -38,3 +38,8 @@ module("timer") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of timer objects alive. +-- @name instances +-- @class function diff --git a/luadoc/wibox.lua b/luadoc/wibox.lua index a60b5fddb..fa574aa9e 100644 --- a/luadoc/wibox.lua +++ b/luadoc/wibox.lua @@ -58,3 +58,8 @@ module("wibox") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of wibox objects alive. +-- @name instances +-- @class function diff --git a/luadoc/widget.lua b/luadoc/widget.lua index 3aea44ee8..b945fc1aa 100644 --- a/luadoc/widget.lua +++ b/luadoc/widget.lua @@ -66,3 +66,8 @@ module("widget") -- @param ... Various arguments, optional. -- @name emit_signal -- @class function + +--- Get the number of instances. +-- @return The number of widget objects alive. +-- @name instances +-- @class function