Enhancement - Hooks

- First fully functioning Lua hooks.  Woohoo.
This commit is contained in:
Paul Beckingham 2010-01-18 18:03:31 -05:00
parent eeefc8a992
commit 69cae7731f
6 changed files with 252 additions and 72 deletions

View file

@ -32,31 +32,67 @@
#include "API.h"
#include "auto.h"
// Hook class representing a single hook.
class Hook
{
public:
Hook ()
: event ("")
, file ("")
, function ("")
{
}
Hook (const std::string& e, const std::string& f, const std::string& fn)
: event (e)
, file (f)
, function (fn)
{
}
Hook (const Hook& other)
{
event = other.event;
file = other.file;
function = other.function;
}
Hook& operator= (const Hook& other)
{
if (this != &other)
{
event = other.event;
file = other.file;
function = other.function;
}
return *this;
}
public:
std::string event;
std::string file;
std::string function;
};
// Hooks class for managing the loading and calling of hook functions.
class Hooks
{
public:
Hooks (); // Default constructor
~Hooks (); // Destructor
Hooks (const Hooks&); // Deliberately unimplemented
Hooks& operator= (const Hooks&); // Deliberately unimplemented
Hooks (); // Default constructor
~Hooks (); // Destructor
Hooks (const Hooks&); // Deliberately unimplemented
Hooks& operator= (const Hooks&); // Deliberately unimplemented
void initialize ();
bool trigger (const std::string&);
bool eventType (const std::string&, std::string&);
private:
#ifdef HAVE_LIBLUA
bool triggerProgramEvent (const std::string&);
bool triggerListEvent (const std::string&);
bool triggerTaskEvent (const std::string&);
bool triggerFieldEvent (const std::string&);
#endif
private:
#ifdef HAVE_LIBLUA
API api;
#endif
std::vector <std::string> scripts;
std::vector <Hook> all; // All current hooks.
};
#endif