|
16 | 16 | #include "ElunaUtility.h" |
17 | 17 | #include "ElunaCreatureAI.h" |
18 | 18 | #include "ElunaInstanceAI.h" |
| 19 | +#include "Hooks.h" |
19 | 20 |
|
20 | 21 | extern "C" |
21 | 22 | { |
@@ -126,6 +127,9 @@ void Eluna::OpenLua() |
126 | 127 | // Register methods and functions |
127 | 128 | RegisterMethods(this); |
128 | 129 |
|
| 130 | + // Register event ID lookup table |
| 131 | + RegisterHookGlobals(L); |
| 132 | + |
129 | 133 | // get require paths |
130 | 134 | const std::string& requirepath = sElunaLoader->GetRequirePath(); |
131 | 135 | const std::string& requirecpath = sElunaLoader->GetRequireCPath(); |
@@ -186,6 +190,25 @@ void Eluna::DestroyBindStores() |
186 | 190 | binding.reset(); |
187 | 191 | } |
188 | 192 |
|
| 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 | + |
189 | 212 | void Eluna::RunScripts() |
190 | 213 | { |
191 | 214 | int32 const boundMapId = GetBoundMapId(); |
|
0 commit comments