Hmk, so i derived ScriptEvent from my Event class in c++ and added a std::function to it.
i changed all the related handlers ,replaced bindings and added one for the std::function.
now i can assign chai-funcs to it and then call them no problem, even pass in the event the function belongs to as a parameter as i wanted.
now simple tests work, but actually using it for player’s events introduced a problem i do not quite understand.
i push events from players’ queues to a vector with events for the scriptsystem, like so:
players have Events, ScriptSystem has std::vector of ScriptEvent. this results in segfault as soon as ScriptEvent has a std::function member:
#0 0x00007fff00000000 in ?? ()
#1 0x00000000007bf574 in std::function<bool (ScriptEvent const&)>::function(std::function<bool (ScriptEvent const&)> const&) () at /usr/include/c++/4.9/functional:2410
#2 0x00000000007a2a02 in ScriptSystem::update(int const&, int const&) () at scriptsystem.hpp:6
which leads me to believe that the casting somehow calls function’s copy-constructor in a bad way, maybe trying to copy func from Event - which does not have such member. i’m not sure, probably i messed up somewhere because i would expect this to work. “Solved” it by adding a
void ScriptEvent::fromEvent(const Event& ev);
and use that to explicitly copy data from Events to ScriptEvents, as i copy them anyhow.
Works so far, thx.