Skip to content

Commit

Permalink
Use preprocessor functionality for addEventHandler()
Browse files Browse the repository at this point in the history
And return result of calling this function to scripts
  • Loading branch information
Northn committed Jun 4, 2021
1 parent d8667dc commit 59af0a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/RakLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,13 @@ bool RakLua::addEventHandler(sol::this_state& ts, eEventType type, sol::function
switch (type)
{
case INCOMING_RPC:
mHandlers.incomingRpc.push_back({ id, detour });
break;
ADD_EVENT_HANDLER(incomingRpc);
case OUTGOING_RPC:
mHandlers.outgoingRpc.push_back({ id, detour });
break;
ADD_EVENT_HANDLER(outgoingRpc);
case INCOMING_PACKET:
mHandlers.incomingPacket.push_back({ id, detour });
break;
ADD_EVENT_HANDLER(incomingPacket);
case OUTGOING_PACKET:
mHandlers.outgoingPacket.push_back({ id, detour });
break;
ADD_EVENT_HANDLER(outgoingPacket);
default:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/RakLua.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ inline PlayerID gPlayerId;
} \
else ptr++; \
}
#define ADD_EVENT_HANDLER(handlerList) mHandlers.handlerList.push_back({ id, detour }); break

bool __fastcall handleOutgoingPacket(void* ptr, void*, BitStream* bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel);
Packet* __fastcall handleIncomingPacket(void* ptr, void*);
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ void defineGlobals(sol::this_state ts)

#undef INIT_FUNCTION

void registerHandler(sol::this_state ts, RakLua::eEventType type, sol::function fs)
bool registerHandler(sol::this_state ts, RakLua::eEventType type, sol::function fs)
{
gRakLua.addEventHandler(ts, type, fs);
return gRakLua.addEventHandler(ts, type, fs);
}

void destroyHandlers(sol::this_state ts)
Expand Down

0 comments on commit 59af0a0

Please sign in to comment.