diff --git a/sol/function_types.hpp b/sol/function_types.hpp index e28733e7..d121c8c6 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -247,7 +247,7 @@ struct base_function { return base_gc(L, *pudata); } - template + template struct userdata { static int call(lua_State* L) { // Zero-based template parameter, but upvalues start at 1 @@ -258,14 +258,25 @@ struct base_function { return ref_base_call(L, stack::get(L, I + 1)); } - static int gc(lua_State* L) { - for(int i = 0; i < I; ++i) { + template + static void func_gc (std::true_type, lua_State* L) { + + } + + template + static void func_gc (std::false_type, lua_State* L) { + // Shut up clang tautological error without throwing out std::size_t + for(std::size_t i = 0; i < limit; ++i) { upvalue_t up = stack::get(L, i + 1); base_function* obj = static_cast(up.value); std::allocator alloc{}; alloc.destroy(obj); alloc.deallocate(obj, 1); } + } + + static int gc(lua_State* L) { + func_gc(std::integral_constant(), L); return 0; } };