Fix callbacks for scripting
This commit is contained in:
parent
2eb8988d73
commit
8e3f2f83c4
@ -26,17 +26,16 @@ namespace game
|
|||||||
chai->add(chaiscript::fun(&entity::on_notify), "onNotify");
|
chai->add(chaiscript::fun(&entity::on_notify), "onNotify");
|
||||||
chai->add(chaiscript::fun([](const entity& ent, const std::string& event,
|
chai->add(chaiscript::fun([](const entity& ent, const std::string& event,
|
||||||
const std::function<void(
|
const std::function<void(
|
||||||
const std::vector<chaiscript::Boxed_Value>&)>&
|
std::vector<chaiscript::Boxed_Value>)>&
|
||||||
callback)
|
callback)
|
||||||
{
|
{
|
||||||
return ent.on_notify(event, callback, false);
|
return ent.on_notify(event, callback, false);
|
||||||
}), "onNotify");
|
}), "onNotify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun([context](const std::string& event,
|
chai->add(chaiscript::fun([context](const std::string& event,
|
||||||
const std::function<void(const entity&,
|
const std::function<void(
|
||||||
const std::vector<chaiscript::
|
entity, std::vector<chaiscript::Boxed_Value>)>&
|
||||||
Boxed_Value>&)>&
|
callback)
|
||||||
callback)
|
|
||||||
{
|
{
|
||||||
generic_event_listener listener;
|
generic_event_listener listener;
|
||||||
listener.event = event;
|
listener.event = event;
|
||||||
@ -47,10 +46,9 @@ namespace game
|
|||||||
}), "onNotify");
|
}), "onNotify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun([context](const std::string& event,
|
chai->add(chaiscript::fun([context](const std::string& event,
|
||||||
const std::function<void(const entity&,
|
const std::function<void(
|
||||||
const std::vector<chaiscript::
|
entity, std::vector<chaiscript::Boxed_Value>)>&
|
||||||
Boxed_Value>&)>&
|
callback, const bool is_volatile)
|
||||||
callback, const bool is_volatile)
|
|
||||||
{
|
{
|
||||||
generic_event_listener listener;
|
generic_event_listener listener;
|
||||||
listener.event = event;
|
listener.event = event;
|
||||||
@ -68,49 +66,49 @@ namespace game
|
|||||||
}), "notify");
|
}), "notify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& event,
|
[](const entity& ent, const std::string& event,
|
||||||
const chaiscript::Boxed_Value& a1)
|
const chaiscript::Boxed_Value& a1)
|
||||||
{
|
{
|
||||||
return ent.notify(event, {a1});
|
return ent.notify(event, {a1});
|
||||||
}), "notify");
|
}), "notify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& event,
|
[](const entity& ent, const std::string& event,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2)
|
const chaiscript::Boxed_Value& a2)
|
||||||
{
|
{
|
||||||
return ent.notify(event, {a1, a2});
|
return ent.notify(event, {a1, a2});
|
||||||
}), "notify");
|
}), "notify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& event,
|
[](const entity& ent, const std::string& event,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3)
|
const chaiscript::Boxed_Value& a3)
|
||||||
{
|
{
|
||||||
return ent.notify(event, {a1, a2, a3});
|
return ent.notify(event, {a1, a2, a3});
|
||||||
}), "notify");
|
}), "notify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& event,
|
[](const entity& ent, const std::string& event,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3,
|
const chaiscript::Boxed_Value& a3,
|
||||||
const chaiscript::Boxed_Value& a4)
|
const chaiscript::Boxed_Value& a4)
|
||||||
{
|
{
|
||||||
return ent.notify(event, {a1, a2, a3, a4});
|
return ent.notify(event, {a1, a2, a3, a4});
|
||||||
}), "notify");
|
}), "notify");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& event,
|
[](const entity& ent, const std::string& event,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3,
|
const chaiscript::Boxed_Value& a3,
|
||||||
const chaiscript::Boxed_Value& a4,
|
const chaiscript::Boxed_Value& a4,
|
||||||
const chaiscript::Boxed_Value& a5)
|
const chaiscript::Boxed_Value& a5)
|
||||||
{
|
{
|
||||||
return ent.notify(event, {a1, a2, a3, a4, a5});
|
return ent.notify(event, {a1, a2, a3, a4, a5});
|
||||||
}), "notify");
|
}), "notify");
|
||||||
|
|
||||||
// Instance call
|
// Instance call
|
||||||
chai->add(chaiscript::fun(&entity::call), "vectorCall");
|
chai->add(chaiscript::fun(&entity::call), "vectorCall");
|
||||||
@ -120,106 +118,106 @@ namespace game
|
|||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& function,
|
[](const entity& ent, const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1)
|
const chaiscript::Boxed_Value& a1)
|
||||||
{
|
{
|
||||||
return ent.call(function, {a1});
|
return ent.call(function, {a1});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& function,
|
[](const entity& ent, const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2)
|
const chaiscript::Boxed_Value& a2)
|
||||||
{
|
{
|
||||||
return ent.call(function, {a1, a2});
|
return ent.call(function, {a1, a2});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& function,
|
[](const entity& ent, const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3)
|
const chaiscript::Boxed_Value& a3)
|
||||||
{
|
{
|
||||||
return ent.call(function, {a1, a2, a3});
|
return ent.call(function, {a1, a2, a3});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& function,
|
[](const entity& ent, const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3,
|
const chaiscript::Boxed_Value& a3,
|
||||||
const chaiscript::Boxed_Value& a4)
|
const chaiscript::Boxed_Value& a4)
|
||||||
{
|
{
|
||||||
return ent.call(function, {a1, a2, a3, a4});
|
return ent.call(function, {a1, a2, a3, a4});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[](const entity& ent, const std::string& function,
|
[](const entity& ent, const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3,
|
const chaiscript::Boxed_Value& a3,
|
||||||
const chaiscript::Boxed_Value& a4,
|
const chaiscript::Boxed_Value& a4,
|
||||||
const chaiscript::Boxed_Value& a5)
|
const chaiscript::Boxed_Value& a5)
|
||||||
{
|
{
|
||||||
return ent.call(function, {a1, a2, a3, a4, a5});
|
return ent.call(function, {a1, a2, a3, a4, a5});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
// Global call
|
// Global call
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[context](const std::string& function,
|
[context](const std::string& function,
|
||||||
const std::vector<chaiscript::Boxed_Value>& arguments)
|
const std::vector<chaiscript::Boxed_Value>& arguments)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, arguments);
|
return context->get_executer()->call(function, 0, arguments);
|
||||||
}), "vectorCall");
|
}), "vectorCall");
|
||||||
chai->add(chaiscript::fun([context](const std::string& function)
|
chai->add(chaiscript::fun([context](const std::string& function)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, {});
|
return context->get_executer()->call(function, 0, {});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[context](const std::string& function,
|
[context](const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1)
|
const chaiscript::Boxed_Value& a1)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, {a1});
|
return context->get_executer()->call(function, 0, {a1});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[context](const std::string& function,
|
[context](const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2)
|
const chaiscript::Boxed_Value& a2)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, {a1, a2});
|
return context->get_executer()->call(function, 0, {a1, a2});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[context](const std::string& function,
|
[context](const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3)
|
const chaiscript::Boxed_Value& a3)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, {a1, a2, a3});
|
return context->get_executer()->call(function, 0, {a1, a2, a3});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[context](const std::string& function,
|
[context](const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3,
|
const chaiscript::Boxed_Value& a3,
|
||||||
const chaiscript::Boxed_Value& a4)
|
const chaiscript::Boxed_Value& a4)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, {a1, a2, a3, a4});
|
return context->get_executer()->call(function, 0, {a1, a2, a3, a4});
|
||||||
}), "call");
|
}), "call");
|
||||||
|
|
||||||
chai->add(chaiscript::fun(
|
chai->add(chaiscript::fun(
|
||||||
[context](const std::string& function,
|
[context](const std::string& function,
|
||||||
const chaiscript::Boxed_Value& a1,
|
const chaiscript::Boxed_Value& a1,
|
||||||
const chaiscript::Boxed_Value& a2,
|
const chaiscript::Boxed_Value& a2,
|
||||||
const chaiscript::Boxed_Value& a3,
|
const chaiscript::Boxed_Value& a3,
|
||||||
const chaiscript::Boxed_Value& a4,
|
const chaiscript::Boxed_Value& a4,
|
||||||
const chaiscript::Boxed_Value& a5)
|
const chaiscript::Boxed_Value& a5)
|
||||||
{
|
{
|
||||||
return context->get_executer()->call(function, 0, {a1, a2, a3, a4, a5});
|
return context->get_executer()->call(function, 0, {a1, a2, a3, a4, a5});
|
||||||
}), "call");
|
}), "call");
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize(context* context)
|
void initialize(context* context)
|
||||||
|
@ -66,7 +66,7 @@ namespace game
|
|||||||
}
|
}
|
||||||
|
|
||||||
event_listener_handle entity::on_notify(const std::string& event,
|
event_listener_handle entity::on_notify(const std::string& event,
|
||||||
const std::function<void(const std::vector<chaiscript::Boxed_Value>&)>&
|
const std::function<void(std::vector<chaiscript::Boxed_Value>)>&
|
||||||
callback,
|
callback,
|
||||||
const bool is_volatile)
|
const bool is_volatile)
|
||||||
const
|
const
|
||||||
|
@ -21,8 +21,8 @@ namespace game
|
|||||||
entity& operator=(entity&& other) noexcept;
|
entity& operator=(entity&& other) noexcept;
|
||||||
|
|
||||||
event_listener_handle on_notify(const std::string& event,
|
event_listener_handle on_notify(const std::string& event,
|
||||||
const std::function<void(const std::vector<chaiscript::Boxed_Value>&)>& callback,
|
const std::function<void(std::vector<chaiscript::Boxed_Value>)>& callback,
|
||||||
bool is_volatile) const;
|
bool is_volatile) const;
|
||||||
|
|
||||||
unsigned int get_entity_id() const;
|
unsigned int get_entity_id() const;
|
||||||
game::native::scr_entref_t get_entity_reference() const;
|
game::native::scr_entref_t get_entity_reference() const;
|
||||||
|
@ -11,12 +11,14 @@ namespace game
|
|||||||
|
|
||||||
chai->add(chaiscript::user_type<event_listener_handle>(), "_event_listener_handle");
|
chai->add(chaiscript::user_type<event_listener_handle>(), "_event_listener_handle");
|
||||||
chai->add(chaiscript::constructor<event_listener_handle()>(), "_event_listener_handle");
|
chai->add(chaiscript::constructor<event_listener_handle()>(), "_event_listener_handle");
|
||||||
chai->add(chaiscript::constructor<event_listener_handle(const event_listener_handle&)>(), "_event_listener_handle");
|
chai->add(chaiscript::constructor<event_listener_handle(const event_listener_handle&)>(),
|
||||||
|
"_event_listener_handle");
|
||||||
|
|
||||||
chai->add(chaiscript::fun([](event_listener_handle& lhs, const event_listener_handle& rhs) -> event_listener_handle&
|
chai->add(chaiscript::fun(
|
||||||
{
|
[](event_listener_handle& lhs, const event_listener_handle& rhs) -> event_listener_handle&
|
||||||
return lhs = rhs;
|
{
|
||||||
}), "=");
|
return lhs = rhs;
|
||||||
|
}), "=");
|
||||||
|
|
||||||
chai->add(chaiscript::fun([this](const event_listener_handle& handle)
|
chai->add(chaiscript::fun([this](const event_listener_handle& handle)
|
||||||
{
|
{
|
||||||
@ -82,14 +84,14 @@ namespace game
|
|||||||
{
|
{
|
||||||
listener.id = ++this->current_listener_id_;
|
listener.id = ++this->current_listener_id_;
|
||||||
this->event_listeners_.add(listener);
|
this->event_listeners_.add(listener);
|
||||||
return { listener.id };
|
return {listener.id};
|
||||||
}
|
}
|
||||||
|
|
||||||
event_listener_handle event_handler::add_event_listener(generic_event_listener listener)
|
event_listener_handle event_handler::add_event_listener(generic_event_listener listener)
|
||||||
{
|
{
|
||||||
listener.id = ++this->current_listener_id_;
|
listener.id = ++this->current_listener_id_;
|
||||||
this->generic_event_listeners_.add(listener);
|
this->generic_event_listeners_.add(listener);
|
||||||
return { listener.id };
|
return {listener.id};
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_handler::remove(const event_listener_handle& handle)
|
void event_handler::remove(const event_listener_handle& handle)
|
||||||
|
@ -20,7 +20,7 @@ namespace game
|
|||||||
public:
|
public:
|
||||||
std::string event = {};
|
std::string event = {};
|
||||||
unsigned int entity_id = 0;
|
unsigned int entity_id = 0;
|
||||||
std::function<void(const std::vector<chaiscript::Boxed_Value>&)> callback = {};
|
std::function<void(std::vector<chaiscript::Boxed_Value>)> callback = {};
|
||||||
bool is_volatile = false;
|
bool is_volatile = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ namespace game
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string event = {};
|
std::string event = {};
|
||||||
std::function<void(const entity&, const std::vector<chaiscript::Boxed_Value>&)> callback = {};
|
std::function<void(entity, std::vector<chaiscript::Boxed_Value>)> callback = {};
|
||||||
bool is_volatile = false;
|
bool is_volatile = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ namespace game
|
|||||||
context* context_;
|
context* context_;
|
||||||
std::atomic_int64_t current_listener_id_ = 0;
|
std::atomic_int64_t current_listener_id_ = 0;
|
||||||
|
|
||||||
utils::concurrent_list<event_listener> event_listeners_;
|
utils::concurrent_list<event_listener> event_listeners_;
|
||||||
utils::concurrent_list<generic_event_listener> generic_event_listeners_;
|
utils::concurrent_list<generic_event_listener> generic_event_listeners_;
|
||||||
|
|
||||||
void dispatch_to_specific_listeners(event* event, const std::vector<chaiscript::Boxed_Value>& arguments);
|
void dispatch_to_specific_listeners(event* event, const std::vector<chaiscript::Boxed_Value>& arguments);
|
||||||
|
@ -21,7 +21,7 @@ public:
|
|||||||
html_frame();
|
html_frame();
|
||||||
virtual ~html_frame();
|
virtual ~html_frame();
|
||||||
|
|
||||||
void initialize(const HWND window);
|
void initialize(HWND window);
|
||||||
|
|
||||||
void resize(DWORD width, DWORD height) const;
|
void resize(DWORD width, DWORD height) const;
|
||||||
bool load_url(const std::string& url) const;
|
bool load_url(const std::string& url) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user