diff --git a/ElunaTemplate.h b/ElunaTemplate.h index 09b2613574..9ebab5f18f 100644 --- a/ElunaTemplate.h +++ b/ElunaTemplate.h @@ -417,19 +417,13 @@ class ElunaTemplate { ElunaRegister* l = static_cast*>(lua_touserdata(L, lua_upvalueindex(1))); Eluna* E = static_cast(lua_touserdata(L, lua_upvalueindex(2))); - T* obj; // determine if the method table functions are global or non-global - bool isGlobal = false; - std::visit([&](auto&& func) - { - using FuncType = std::decay_t; - if constexpr (std::is_same_v) - isGlobal = true; - }, l->mfunc); + constexpr bool isGlobal = std::is_same_v; // we only check self if the method is not a global - if (!isGlobal) + T* obj; + if constexpr (!isGlobal) { obj = E->CHECKOBJ(1); if (!obj) @@ -439,15 +433,18 @@ class ElunaTemplate int top = lua_gettop(L); int expected = 0; - std::visit([&](auto&& func) + if constexpr (isGlobal) { - using FuncType = std::decay_t; - if constexpr (std::is_same_v) // global method - expected = func(E); - else if constexpr (std::is_same_v) // non-global method - expected = func(E, obj); - - }, l->mfunc); + auto func = std::get_if(&l->mfunc); + if (func) + expected = (*func)(E); + } + else + { + auto func = std::get_if(&l->mfunc); + if (func) + expected = (*func)(E, obj); + } int args = lua_gettop(L) - top; if (args < 0 || args > expected)