From 8e3f2f83c42b187a482cab24251606666bf61d16 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 23 Jan 2019 22:27:14 +0100 Subject: [PATCH] Fix callbacks for scripting --- src/game/scripting/context_initializer.cpp | 236 ++++++++++----------- src/game/scripting/entity.cpp | 2 +- src/game/scripting/entity.hpp | 4 +- src/game/scripting/event_handler.cpp | 16 +- src/game/scripting/event_handler.hpp | 6 +- src/launcher/html/html_frame.hpp | 2 +- 6 files changed, 133 insertions(+), 133 deletions(-) diff --git a/src/game/scripting/context_initializer.cpp b/src/game/scripting/context_initializer.cpp index 77f6b98..7c2b140 100644 --- a/src/game/scripting/context_initializer.cpp +++ b/src/game/scripting/context_initializer.cpp @@ -26,17 +26,16 @@ namespace game chai->add(chaiscript::fun(&entity::on_notify), "onNotify"); chai->add(chaiscript::fun([](const entity& ent, const std::string& event, const std::function&)>& + std::vector)>& callback) { return ent.on_notify(event, callback, false); }), "onNotify"); chai->add(chaiscript::fun([context](const std::string& event, - const std::function&)>& - callback) + const std::function)>& + callback) { generic_event_listener listener; listener.event = event; @@ -47,10 +46,9 @@ namespace game }), "onNotify"); chai->add(chaiscript::fun([context](const std::string& event, - const std::function&)>& - callback, const bool is_volatile) + const std::function)>& + callback, const bool is_volatile) { generic_event_listener listener; listener.event = event; @@ -68,49 +66,49 @@ namespace game }), "notify"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& event, - const chaiscript::Boxed_Value& a1) - { - return ent.notify(event, {a1}); - }), "notify"); + [](const entity& ent, const std::string& event, + const chaiscript::Boxed_Value& a1) + { + return ent.notify(event, {a1}); + }), "notify"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& event, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2) - { - return ent.notify(event, {a1, a2}); - }), "notify"); + [](const entity& ent, const std::string& event, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2) + { + return ent.notify(event, {a1, a2}); + }), "notify"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& event, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3) - { - return ent.notify(event, {a1, a2, a3}); - }), "notify"); + [](const entity& ent, const std::string& event, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3) + { + return ent.notify(event, {a1, a2, a3}); + }), "notify"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& event, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3, - const chaiscript::Boxed_Value& a4) - { - return ent.notify(event, {a1, a2, a3, a4}); - }), "notify"); + [](const entity& ent, const std::string& event, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3, + const chaiscript::Boxed_Value& a4) + { + return ent.notify(event, {a1, a2, a3, a4}); + }), "notify"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& event, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3, - const chaiscript::Boxed_Value& a4, - const chaiscript::Boxed_Value& a5) - { - return ent.notify(event, {a1, a2, a3, a4, a5}); - }), "notify"); + [](const entity& ent, const std::string& event, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3, + const chaiscript::Boxed_Value& a4, + const chaiscript::Boxed_Value& a5) + { + return ent.notify(event, {a1, a2, a3, a4, a5}); + }), "notify"); // Instance call chai->add(chaiscript::fun(&entity::call), "vectorCall"); @@ -120,106 +118,106 @@ namespace game }), "call"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& function, - const chaiscript::Boxed_Value& a1) - { - return ent.call(function, {a1}); - }), "call"); + [](const entity& ent, const std::string& function, + const chaiscript::Boxed_Value& a1) + { + return ent.call(function, {a1}); + }), "call"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2) - { - return ent.call(function, {a1, a2}); - }), "call"); + [](const entity& ent, const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2) + { + return ent.call(function, {a1, a2}); + }), "call"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3) - { - return ent.call(function, {a1, a2, a3}); - }), "call"); + [](const entity& ent, const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3) + { + return ent.call(function, {a1, a2, a3}); + }), "call"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3, - const chaiscript::Boxed_Value& a4) - { - return ent.call(function, {a1, a2, a3, a4}); - }), "call"); + [](const entity& ent, const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3, + const chaiscript::Boxed_Value& a4) + { + return ent.call(function, {a1, a2, a3, a4}); + }), "call"); chai->add(chaiscript::fun( - [](const entity& ent, const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3, - const chaiscript::Boxed_Value& a4, - const chaiscript::Boxed_Value& a5) - { - return ent.call(function, {a1, a2, a3, a4, a5}); - }), "call"); + [](const entity& ent, const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3, + const chaiscript::Boxed_Value& a4, + const chaiscript::Boxed_Value& a5) + { + return ent.call(function, {a1, a2, a3, a4, a5}); + }), "call"); // Global call chai->add(chaiscript::fun( - [context](const std::string& function, - const std::vector& arguments) - { - return context->get_executer()->call(function, 0, arguments); - }), "vectorCall"); + [context](const std::string& function, + const std::vector& arguments) + { + return context->get_executer()->call(function, 0, arguments); + }), "vectorCall"); chai->add(chaiscript::fun([context](const std::string& function) { return context->get_executer()->call(function, 0, {}); }), "call"); chai->add(chaiscript::fun( - [context](const std::string& function, - const chaiscript::Boxed_Value& a1) - { - return context->get_executer()->call(function, 0, {a1}); - }), "call"); + [context](const std::string& function, + const chaiscript::Boxed_Value& a1) + { + return context->get_executer()->call(function, 0, {a1}); + }), "call"); chai->add(chaiscript::fun( - [context](const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2) - { - return context->get_executer()->call(function, 0, {a1, a2}); - }), "call"); + [context](const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2) + { + return context->get_executer()->call(function, 0, {a1, a2}); + }), "call"); chai->add(chaiscript::fun( - [context](const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3) - { - return context->get_executer()->call(function, 0, {a1, a2, a3}); - }), "call"); + [context](const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3) + { + return context->get_executer()->call(function, 0, {a1, a2, a3}); + }), "call"); chai->add(chaiscript::fun( - [context](const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3, - const chaiscript::Boxed_Value& a4) - { - return context->get_executer()->call(function, 0, {a1, a2, a3, a4}); - }), "call"); + [context](const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3, + const chaiscript::Boxed_Value& a4) + { + return context->get_executer()->call(function, 0, {a1, a2, a3, a4}); + }), "call"); chai->add(chaiscript::fun( - [context](const std::string& function, - const chaiscript::Boxed_Value& a1, - const chaiscript::Boxed_Value& a2, - const chaiscript::Boxed_Value& a3, - const chaiscript::Boxed_Value& a4, - const chaiscript::Boxed_Value& a5) - { - return context->get_executer()->call(function, 0, {a1, a2, a3, a4, a5}); - }), "call"); + [context](const std::string& function, + const chaiscript::Boxed_Value& a1, + const chaiscript::Boxed_Value& a2, + const chaiscript::Boxed_Value& a3, + const chaiscript::Boxed_Value& a4, + const chaiscript::Boxed_Value& a5) + { + return context->get_executer()->call(function, 0, {a1, a2, a3, a4, a5}); + }), "call"); } void initialize(context* context) diff --git a/src/game/scripting/entity.cpp b/src/game/scripting/entity.cpp index a1c875a..f171676 100644 --- a/src/game/scripting/entity.cpp +++ b/src/game/scripting/entity.cpp @@ -66,7 +66,7 @@ namespace game } event_listener_handle entity::on_notify(const std::string& event, - const std::function&)>& + const std::function)>& callback, const bool is_volatile) const diff --git a/src/game/scripting/entity.hpp b/src/game/scripting/entity.hpp index e636ad6..ced3201 100644 --- a/src/game/scripting/entity.hpp +++ b/src/game/scripting/entity.hpp @@ -21,8 +21,8 @@ namespace game entity& operator=(entity&& other) noexcept; event_listener_handle on_notify(const std::string& event, - const std::function&)>& callback, - bool is_volatile) const; + const std::function)>& callback, + bool is_volatile) const; unsigned int get_entity_id() const; game::native::scr_entref_t get_entity_reference() const; diff --git a/src/game/scripting/event_handler.cpp b/src/game/scripting/event_handler.cpp index cc3b97f..6fd8411 100644 --- a/src/game/scripting/event_handler.cpp +++ b/src/game/scripting/event_handler.cpp @@ -11,12 +11,14 @@ namespace game chai->add(chaiscript::user_type(), "_event_listener_handle"); chai->add(chaiscript::constructor(), "_event_listener_handle"); - chai->add(chaiscript::constructor(), "_event_listener_handle"); + chai->add(chaiscript::constructor(), + "_event_listener_handle"); - chai->add(chaiscript::fun([](event_listener_handle& lhs, const event_listener_handle& rhs) -> event_listener_handle& - { - return lhs = rhs; - }), "="); + chai->add(chaiscript::fun( + [](event_listener_handle& lhs, const event_listener_handle& rhs) -> event_listener_handle& + { + return lhs = rhs; + }), "="); chai->add(chaiscript::fun([this](const event_listener_handle& handle) { @@ -82,14 +84,14 @@ namespace game { listener.id = ++this->current_listener_id_; this->event_listeners_.add(listener); - return { listener.id }; + return {listener.id}; } event_listener_handle event_handler::add_event_listener(generic_event_listener listener) { listener.id = ++this->current_listener_id_; this->generic_event_listeners_.add(listener); - return { listener.id }; + return {listener.id}; } void event_handler::remove(const event_listener_handle& handle) diff --git a/src/game/scripting/event_handler.hpp b/src/game/scripting/event_handler.hpp index 4377fe7..d8f6c5e 100644 --- a/src/game/scripting/event_handler.hpp +++ b/src/game/scripting/event_handler.hpp @@ -20,7 +20,7 @@ namespace game public: std::string event = {}; unsigned int entity_id = 0; - std::function&)> callback = {}; + std::function)> callback = {}; bool is_volatile = false; }; @@ -28,7 +28,7 @@ namespace game { public: std::string event = {}; - std::function&)> callback = {}; + std::function)> callback = {}; bool is_volatile = false; }; @@ -46,7 +46,7 @@ namespace game context* context_; std::atomic_int64_t current_listener_id_ = 0; -utils::concurrent_list event_listeners_; + utils::concurrent_list event_listeners_; utils::concurrent_list generic_event_listeners_; void dispatch_to_specific_listeners(event* event, const std::vector& arguments); diff --git a/src/launcher/html/html_frame.hpp b/src/launcher/html/html_frame.hpp index 893954e..35eac17 100644 --- a/src/launcher/html/html_frame.hpp +++ b/src/launcher/html/html_frame.hpp @@ -21,7 +21,7 @@ public: html_frame(); virtual ~html_frame(); - void initialize(const HWND window); + void initialize(HWND window); void resize(DWORD width, DWORD height) const; bool load_url(const std::string& url) const;