Skip to content

Commit 35209fe

Browse files
authored
Merge pull request #75 from NuiCpp/devel
Bug Fixes and More Tests
2 parents 1e1ee1a + 81b96ac commit 35209fe

File tree

14 files changed

+1011
-64
lines changed

14 files changed

+1011
-64
lines changed

nui/include/nui/backend/rpc_hub.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <nui/data_structures/selectables_registry.hpp>
55
#include <nui/utility/meta/function_traits.hpp>
66
#include <nui/utility/meta/pick_first.hpp>
7+
#include <nui/shared/on_destroy.hpp>
78
#include <nlohmann/json.hpp>
89
#include <fmt/format.h>
910

@@ -96,6 +97,22 @@ namespace Nui
9697
}})();
9798
)";
9899

100+
struct AutoUnregister : public OnDestroy
101+
{
102+
AutoUnregister(RpcHub const* hub, std::string name)
103+
: OnDestroy{[hub, name = std::move(name)]() {
104+
hub->unregisterFunction(name);
105+
}}
106+
{}
107+
};
108+
109+
template <typename T>
110+
AutoUnregister autoRegisterFunction(std::string const& name, T&& func) const
111+
{
112+
registerFunction(name, std::forward<T>(func));
113+
return AutoUnregister{this, name};
114+
}
115+
99116
template <typename T>
100117
void registerFunction(std::string const& name, T&& func) const
101118
{

0 commit comments

Comments
 (0)