From 72603f1641bb400be6c9b0604273a4bd38932136 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 17 Nov 2022 13:47:16 -0500 Subject: ui-coord mouse interacts with world-coord entity --- src/script.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/script.hpp') diff --git a/src/script.hpp b/src/script.hpp index 24cc142..dadddfa 100644 --- a/src/script.hpp +++ b/src/script.hpp @@ -21,15 +21,19 @@ #ifndef SYSTEM_SCRIPT_HPP_ #define SYSTEM_SCRIPT_HPP_ +#include "world.hpp" + #include #include -#include "world.hpp" +#include /** * Utility for pairing class instances to their member function calls. * This is useful for adding functions to the Lua game namespace. * + * TODO I am certain that this can be done better. -clyne + * * @param func The member function to call * @param instance The instance to bind to * @return A function that calls the member function using the given instance @@ -37,7 +41,18 @@ template auto bindInstance(R (C::* func)(Args...), C *instance) { - return [instance, func](Args... args) { (instance->*func)(args...); }; + if constexpr (std::same_as) + return [instance, func](Args... args) { (instance->*func)(args...); }; + else + return [instance, func](Args... args) { return (instance->*func)(args...); }; +} +template +auto bindInstance(R (C::* func)(Args...) const, const C *instance) +{ + if constexpr (std::same_as) + return [instance, func](Args... args) { (instance->*func)(args...); }; + else + return [instance, func](Args... args) { return (instance->*func)(args...); }; } -- cgit v1.2.3