git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / lua / LUAScriptHook.h
blobe25f26544fe5e9b0872bf78dfa34f7fa32c1002e
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #if !defined(__INCLUDE_LUAScriptHook_INCLUDE__)
22 #define __INCLUDE_LUAScriptHook_INCLUDE__
24 #include <lua/LUAScriptFactory.h>
25 #include <lang/LangString.h>
26 #include <map>
27 #include <vector>
29 class LUAScriptHook
31 public:
32 class Param
34 public:
35 enum Type
37 eString,
38 eNumber,
39 eBoolean
42 Param(fixed innumber) :
43 number(innumber), type(eNumber) {};
44 Param(const char *instr) :
45 str(instr), type(eString) {};
46 Param(const std::string &instr) :
47 str(instr), type(eString) {};
48 Param(const LangString &instr) :
49 str(LangStringUtil::convertFromLang(instr)), type(eString) {};
50 Param(bool b) :
51 boolean(b), type(eBoolean) {};
53 Type type;
54 fixed number;
55 bool boolean;
56 std::string str;
59 LUAScriptHook(LUAScriptFactory *factory,
60 const std::string &hooksName,
61 const std::string &directoryName);
62 ~LUAScriptHook();
64 void addHookProvider(const std::string &hookName);
66 void callHook(const std::string &hookName);
67 void callHook(const std::string &hookName, const Param &param1);
68 void callHook(const std::string &hookName, const Param &param1, const Param &param2);
69 void callHook(const std::string &hookName, const Param &param1, const Param &param2, const Param &param3);
71 void clearHooks();
72 bool loadHooks();
73 void listHooks();
75 protected:
76 struct HookEntry
78 LUAScript *script;
79 std::string entryPoint;
82 std::string directoryName_, hooksName_;
83 LUAScriptFactory *factory_;
84 std::map<std::string, std::vector<HookEntry> > hookNames_;
85 bool loadHook(const std::string &directoryName, const std::string &fileName);
86 void reloadHooks() { loadHooks(); }
88 void callHookInternal(const std::string &hookName, const std::vector<Param> &params);
91 #endif // __INCLUDE_LUAScriptHook_INCLUDE__