Refactor so that make_method_bindable also accepts free functions now

This commit is contained in:
King_DuckZ 2022-05-19 01:06:09 +02:00
commit addb48822f
7 changed files with 96 additions and 37 deletions

View file

@ -59,16 +59,22 @@ namespace wren {
CallbackManager::CallbackManager() = default;
CallbackManager::~CallbackManager() noexcept = default;
CallbackManager& CallbackManager::add_callback (bool is_static, std::string_view module_name, std::string_view class_name, std::string_view signature, foreign_method_t cb) {
CallbackManager& CallbackManager::add_callback (
bool is_static,
std::string_view module_name,
std::string_view class_name,
std::string_view signature,
std::function<foreign_method_t()> make_cb
) {
using detail::FullSignatureOwning;
using detail::TempFullSignature;
MethodMap& map = *method_map(is_static);
auto it_found = map.find(TempFullSignature{module_name, class_name, signature});
if (map.cend() == it_found)
map.insert(it_found, std::make_pair(FullSignatureOwning{module_name, class_name, signature}, cb));
map.insert(it_found, std::make_pair(FullSignatureOwning{module_name, class_name, signature}, make_cb()));
else
it_found->second = cb;
it_found->second = make_cb();
return *this;
}