diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index 0849b0b3..2c75a317 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -222,6 +222,7 @@ enum DrvAction { PLAY_NOTIFY_ACCEPT, PLAY_CALL_EVENT_UPDATE, PLAY_INVOKE_ENGIO, + PLAY_INVOKE_LUA_CALL, PLAY_INVOKE_LUA_SOURCE, PLAY_RELEASE, }; @@ -236,6 +237,7 @@ inline static const char *action_string(DrvAction act) { case PLAY_NOTIFY_ACCEPT: return "PLAY_NOTIFY_ACCEPT"; case PLAY_CALL_EVENT_UPDATE: return "PLAY_CALL_EVENT_UPDATE"; case PLAY_INVOKE_ENGIO: return "PLAY_INVOKE_ENGIO"; + case PLAY_INVOKE_LUA_CALL: return "PLAY_INVOKE_LUA_CALL"; case PLAY_INVOKE_LUA_SOURCE: return "PLAY_INVOKE_LUA_SOURCE"; case PLAY_RELEASE: return "PLAY_RELEASE"; default: return "unknown"; @@ -488,6 +490,11 @@ void DrivenEngine::drv_invoke_engio(int64_t place, uint32_t datapklen, const cha queued_invocations_.emplace_back(inv); } +void DrivenEngine::drv_invoke_lua_call(int64_t place, uint32_t datapklen, const char *datapk) { + Invocation *inv = new Invocation(Invocation::KIND_LUA_CALL, visible_actor_id_, place, std::string_view(datapk, datapklen)); + queued_invocations_.emplace_back(inv); +} + void DrivenEngine::drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk) { Invocation *inv = new Invocation(Invocation::KIND_LUA_SOURCE, visible_actor_id_, visible_actor_id_, std::string_view(srcpk, srcpklen)); queued_invocations_.emplace_back(inv); @@ -844,6 +851,31 @@ void replay_invoke_engio(EngineWrapper *w) { //////////////////////// +void play_invoke_lua_call(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) { + assert(w->rlog == nullptr); + if (w->wlog != nullptr) { + w->wlog->write_cmd_hash(PLAY_INVOKE_LUA_CALL, eng::memhash()); + w->wlog->write_int64(place); + w->wlog->write_string(std::string_view(datapk, datapklen)); + w->wlog->flush(); + } + + w->engine->drv_invoke_lua_call(place, datapklen, datapk); +} + +void replay_invoke_lua_call(EngineWrapper *w) { + int64_t place = w->rlog->read_int64(); + std::string srcpack = w->rlog->read_string(); + if (!w->rlog->good()) { + return reset_wrapper(w, "replay log corrupt in replay_invoke_lua_call"); + } + + w->engine->drv_invoke_lua_call(place, srcpack.size(), srcpack.c_str()); +} + +//////////////////////// + + void play_invoke_lua_source(EngineWrapper *w, uint32_t srcpklen, const char *srcpk) { assert(w->rlog == nullptr); if (w->wlog != nullptr) { @@ -933,6 +965,7 @@ static void replaycore_step(EngineWrapper *w) { case PLAY_NOTIFY_ACCEPT: replay_notify_accept(w); return; case PLAY_CALL_EVENT_UPDATE: replay_invoke_event_update(w); return; case PLAY_INVOKE_ENGIO: replay_invoke_engio(w); return; + case PLAY_INVOKE_LUA_CALL: replay_invoke_lua_call(w); return; case PLAY_INVOKE_LUA_SOURCE: replay_invoke_lua_source(w); return; case PLAY_RELEASE: release(w); return; default: return reset_wrapper(w, "Replay log corrupt in command dispatcher"); @@ -995,6 +1028,7 @@ static void init_engine_wrapper_helper(EngineWrapper *w) { w->play_notify_accept = play_notify_accept; w->play_invoke_event_update = play_invoke_event_update; w->play_invoke_engio = play_invoke_engio; + w->play_invoke_lua_call = play_invoke_lua_call; w->play_invoke_lua_source = play_invoke_lua_source; w->replay_initialize = replaycore_initialize; diff --git a/luprex/cpp/core/drivenengine.hpp b/luprex/cpp/core/drivenengine.hpp index 202b14f1..da21bfe6 100644 --- a/luprex/cpp/core/drivenengine.hpp +++ b/luprex/cpp/core/drivenengine.hpp @@ -294,6 +294,7 @@ public: uint32_t drv_notify_accept(uint32_t port); void drv_call_event_update(double clock); void drv_invoke_engio(int64_t place, uint32_t datapklen, const char *datapk); + void drv_invoke_lua_call(int64_t place, uint32_t datapklen, const char *datapk); void drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk); private: diff --git a/luprex/cpp/core/enginewrapper.hpp b/luprex/cpp/core/enginewrapper.hpp index 2b15cfe2..78bc26dd 100644 --- a/luprex/cpp/core/enginewrapper.hpp +++ b/luprex/cpp/core/enginewrapper.hpp @@ -204,6 +204,12 @@ struct EngineWrapper { // void (*play_invoke_engio)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk); + // Send an invoke/KIND_LUA_CALL + // + // This is the main pathway for blueprints to reach into lua. + // + void (*play_invoke_lua_call)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk); + // Send an invoke/KIND_LUA_SOURCE // // This is used to update the lua source at runtime, without stopping