00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(__INCLUDE_LUAScriptHook_INCLUDE__)
00022 #define __INCLUDE_LUAScriptHook_INCLUDE__
00023
00024 #include <lua/LUAScriptFactory.h>
00025 #include <lang/LangString.h>
00026 #include <map>
00027 #include <vector>
00028
00029 class LUAScriptHook
00030 {
00031 public:
00032 class Param
00033 {
00034 public:
00035 enum Type
00036 {
00037 eString,
00038 eNumber,
00039 eBoolean
00040 };
00041
00042 Param(fixed innumber) :
00043 number(innumber), type(eNumber) {};
00044 Param(const char *instr) :
00045 str(instr), type(eString) {};
00046 Param(const std::string &instr) :
00047 str(instr), type(eString) {};
00048 Param(const LangString &instr) :
00049 str(LangStringUtil::convertFromLang(instr)), type(eString) {};
00050 Param(bool b) :
00051 boolean(b), type(eBoolean) {};
00052
00053 Type type;
00054 fixed number;
00055 bool boolean;
00056 std::string str;
00057 };
00058
00059 LUAScriptHook(LUAScriptFactory *factory,
00060 const std::string &hooksName,
00061 const std::string &directoryName);
00062 ~LUAScriptHook();
00063
00064 void addHookProvider(const std::string &hookName);
00065
00066 void callHook(const std::string &hookName);
00067 void callHook(const std::string &hookName, const Param ¶m1);
00068 void callHook(const std::string &hookName, const Param ¶m1, const Param ¶m2);
00069 void callHook(const std::string &hookName, const Param ¶m1, const Param ¶m2, const Param ¶m3);
00070
00071 void clearHooks();
00072 bool loadHooks();
00073 void listHooks();
00074
00075 protected:
00076 struct HookEntry
00077 {
00078 LUAScript *script;
00079 std::string entryPoint;
00080 };
00081
00082 std::string directoryName_, hooksName_;
00083 LUAScriptFactory *factory_;
00084 std::map<std::string, std::vector<HookEntry> > hookNames_;
00085 bool loadHook(const std::string &directoryName, const std::string &fileName);
00086 void reloadHooks() { loadHooks(); }
00087
00088 void callHookInternal(const std::string &hookName, const std::vector<Param> ¶ms);
00089 };
00090
00091 #endif // __INCLUDE_LUAScriptHook_INCLUDE__