Skip to content

Commit d5e8109

Browse files
THE-FYPNorthn
authored andcommitted
Use main luastate when registering events handlers
By default, when addEventHandler gets called, it passes a coroutine state, which is inacceptible and may get broken in future, this will lead to infinity call of main(). To avoid this problem, we have to use a main luastate instead. Thank you, FYP
1 parent 80b28dd commit d5e8109

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/RakLua.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ void RakLua::postRakClientInitialization(uintptr_t rakClientIntf)
4343
mState = eInitState::OK;
4444
}
4545

46-
bool RakLua::addEventHandler(sol::this_state& ts, eEventType type, sol::function detour)
46+
bool RakLua::addEventHandler(sol::this_state& ts, eEventType type, sol::function &detour_f)
4747
{
4848
sol::state_view lua{ ts };
4949
int id = lua["script"]["this"]["id"];
50+
auto main_thread = sol::main_thread(ts);
51+
sol::protected_function detour(main_thread, detour_f);
5052

5153
switch (type)
5254
{

src/RakLua.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RakLua
3030

3131
void postRakClientInitialization(uintptr_t rakClientIntf);
3232

33-
bool addEventHandler(sol::this_state& ts, eEventType type, sol::function detour);
33+
bool addEventHandler(sol::this_state& ts, eEventType type, sol::function &detour_f);
3434
void destroyHandlers(sol::this_state& ts);
3535

3636
inline bool isInitialized() { return mState == eInitState::OK; }

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ sol::table open(sol::this_state ts)
234234
gRakLua.initialize();
235235

236236
sol::table module = lua.create_table();
237-
module["VERSION"] = 2.11;
237+
module["VERSION"] = 2.12;
238238
module.set_function("getState", &getState);
239239

240240
module.set_function("registerHandler", &registerHandler);

0 commit comments

Comments
 (0)