Skip to content

Commit e23dfbc

Browse files
authored
Merge pull request #517 from ElunaLuaEngine/hooks_
Add native table to event ids to user readable strings.
2 parents a2258e8 + dd55307 commit e23dfbc

File tree

3 files changed

+277
-59
lines changed

3 files changed

+277
-59
lines changed

LuaEngine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ElunaUtility.h"
1717
#include "ElunaCreatureAI.h"
1818
#include "ElunaInstanceAI.h"
19+
#include "Hooks.h"
1920

2021
extern "C"
2122
{
@@ -126,6 +127,9 @@ void Eluna::OpenLua()
126127
// Register methods and functions
127128
RegisterMethods(this);
128129

130+
// Register event ID lookup table
131+
RegisterHookGlobals(L);
132+
129133
// get require paths
130134
const std::string& requirepath = sElunaLoader->GetRequirePath();
131135
const std::string& requirecpath = sElunaLoader->GetRequireCPath();
@@ -186,6 +190,25 @@ void Eluna::DestroyBindStores()
186190
binding.reset();
187191
}
188192

193+
void Eluna::RegisterHookGlobals(lua_State* _L)
194+
{
195+
lua_newtable(_L);
196+
auto [hookData, hookCount] = HookToReadableString::getHooks();
197+
for (size_t i = 0; i < hookCount; ++i) {
198+
const HookStorage& hs = hookData[i];
199+
200+
lua_newtable(_L); // subtable for category
201+
202+
for (size_t j = 0; j < hs.eventCount; ++j) {
203+
lua_pushinteger(_L, hs.events[j].id);
204+
lua_setfield(_L, -2, hs.events[j].name);
205+
}
206+
207+
lua_setfield(_L, -2, hs.category); // events[category] = subtable
208+
}
209+
lua_setglobal(_L, "events");
210+
}
211+
189212
void Eluna::RunScripts()
190213
{
191214
int32 const boundMapId = GetBoundMapId();

LuaEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class ELUNA_GAME_API Eluna
195195
void CloseLua();
196196
void DestroyBindStores();
197197
void CreateBindStores();
198+
void RegisterHookGlobals(lua_State* _L);
198199
#if !defined TRACKABLE_PTR_NAMESPACE
199200
void InvalidateObjects();
200201
#endif

0 commit comments

Comments
 (0)