LUAScriptHook.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 &param1);
00068         void callHook(const std::string &hookName, const Param &param1, const Param &param2);
00069         void callHook(const std::string &hookName, const Param &param1, const Param &param2, const Param &param3);
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> &params);
00089 };
00090 
00091 #endif // __INCLUDE_LUAScriptHook_INCLUDE__

Generated on Mon Feb 16 15:14:51 2009 for Scorched3D by  doxygen 1.5.3