From ad5a63db312d0029109e6ca0051feaa516419ad2 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 1 Oct 2019 08:37:05 -0400 Subject: cleaned up lua function bindings --- src/script.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/script.hpp') diff --git a/src/script.hpp b/src/script.hpp index 0ac9e63..24cc142 100644 --- a/src/script.hpp +++ b/src/script.hpp @@ -26,6 +26,21 @@ #include "world.hpp" +/** + * Utility for pairing class instances to their member function calls. + * This is useful for adding functions to the Lua game namespace. + * + * @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 + */ +template +auto bindInstance(R (C::* func)(Args...), C *instance) +{ + return [instance, func](Args... args) { (instance->*func)(args...); }; +} + + struct EntitySpawnEvent { sol::object ref; -- cgit v1.2.3