squirrel_class.hpp

Go to the documentation of this file.
00001 /* $Id: squirrel_class.hpp 20632 2010-08-26 22:01:16Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef SQUIRREL_CLASS_HPP
00013 #define SQUIRREL_CLASS_HPP
00014 
00015 #include "squirrel_helper.hpp"
00016 
00022 template <class CL>
00023 class DefSQClass {
00024 private:
00025   const char *classname;
00026 
00027 public:
00028   DefSQClass(const char *_classname) :
00029     classname(_classname)
00030   {}
00031 
00035   template <typename Func>
00036   void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name)
00037   {
00038     using namespace SQConvert;
00039     engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
00040   }
00041 
00045   template <typename Func>
00046   void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, const char *function_name)
00047   {
00048     using namespace SQConvert;
00049     engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
00050   }
00051 
00058   template <typename Func>
00059   void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name, int nparam, const char *params)
00060   {
00061     using namespace SQConvert;
00062     engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
00063   }
00064 
00068   template <typename Func>
00069   void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name)
00070   {
00071     using namespace SQConvert;
00072     engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
00073   }
00074 
00081   template <typename Func>
00082   void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name, int nparam, const char *params)
00083   {
00084     using namespace SQConvert;
00085     engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
00086   }
00087 
00088   template <typename Var>
00089   void DefSQConst(Squirrel *engine, Var value, const char *var_name)
00090   {
00091     engine->AddConst(var_name, value);
00092   }
00093 
00094   void PreRegister(Squirrel *engine)
00095   {
00096     engine->AddClassBegin(this->classname);
00097   }
00098 
00099   void PreRegister(Squirrel *engine, const char *parent_class)
00100   {
00101     engine->AddClassBegin(this->classname, parent_class);
00102   }
00103 
00104   template <typename Func, int Tnparam>
00105   void AddConstructor(Squirrel *engine, const char *params)
00106   {
00107     using namespace SQConvert;
00108     engine->AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, Tnparam, params);
00109   }
00110 
00111   void PostRegister(Squirrel *engine)
00112   {
00113     engine->AddClassEnd();
00114   }
00115 };
00116 
00117 #endif /* SQUIRREL_CLASS_HPP */

Generated on Fri Dec 31 17:15:38 2010 for OpenTTD by  doxygen 1.6.1