Make the register functions optionally return a cancel callback.

It's now possible to have complete flexibility with cancelling bindings,
i.e. it's possible to re-implement all of the other ways to cancel bindings
using the callback.

This sytem has been designed with complete safety in mind:
 - It is safe to call the callback more than once (does nothing after the
   first call).
 - The callback does not expire, and can be stored for as long as
   necessary.
 - If a callback is returned, there is no other way to cancel the binding
   (again, due to safety).
This commit is contained in:
Patman64
2015-03-08 18:06:10 -04:00
parent b01d441dbd
commit 3490d21bcd
5 changed files with 673 additions and 77 deletions

View File

@@ -272,7 +272,7 @@ public:
bool ShouldReload() const { return reload; }
bool IsEnabled() const { return enabled && IsInitialized(); }
bool HasLuaState() const { return L != NULL; }
void Register(uint8 reg, uint32 id, uint64 guid, uint32 instanceId, uint32 evt, int func, uint32 shots);
int Register(lua_State* L, uint8 reg, uint32 id, uint64 guid, uint32 instanceId, uint32 evt, int func, uint32 shots, bool returnCallback);
// Non-static pushes, to be used in hooks.
// These just call the correct static version with the main thread's Lua state.