# squirrel_class.hpp

    00001 /* $Id: squirrel_class.hpp 15060 2009-01-13 15:44:36Z smatz $ */
    00002
    00005 #ifndef SQUIRREL_CLASS_HPP
    00006 #define SQUIRREL_CLASS_HPP
    00007
    00008 #if (__GNUC__ == 2)
    00009 /* GCC 2.95 doesn't like to have SQConvert::DefSQStaticCallback inside a
    00010  *  template (it gives an internal error 373). Above that, it doesn't listen
    00011  *  to 'using namespace' inside a function of a template. So for GCC 2.95 we
    00012  *  do it in the global space to avoid compiler errors. */
    00013 using namespace SQConvert;
    00014 #endif /* __GNUC__ == 2 */
    00015
    00021 template <class CL>
    00022 class DefSQClass {
    00023 private:
    00024   const char *classname;
    00025
    00026 public:
    00027   DefSQClass(const char *_classname) :
    00028     classname(_classname)
    00029   {}
    00030
    00034   template <typename Func>
    00035   void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name)
    00036   {
    00037     using namespace SQConvert;
    00038     engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
    00039   }
    00040
    00044   template <typename Func>
    00045   void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, const char *function_name)
    00046   {
    00047     using namespace SQConvert;
    00048     engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
    00049   }
    00050
    00057   template <typename Func>
    00058   void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name, int nparam, const char *params)
    00059   {
    00060     using namespace SQConvert;
    00061     engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
    00062   }
    00063
    00067   template <typename Func>
    00068   void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name)
    00069   {
    00070     using namespace SQConvert;
    00071     engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
    00072   }
    00073
    00080   template <typename Func>
    00081   void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name, int nparam, const char *params)
    00082   {
    00083     using namespace SQConvert;
    00084     engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
    00085   }
    00086
    00087   template <typename Var>
    00088   void DefSQConst(Squirrel *engine, Var value, const char *var_name)
    00089   {
    00090     engine->AddConst(var_name, value);
    00091   }
    00092
    00093   void PreRegister(Squirrel *engine)
    00094   {
    00095     engine->AddClassBegin(this->classname);
    00096   }
    00097
    00098   void PreRegister(Squirrel *engine, const char *parent_class)
    00099   {
    00100     engine->AddClassBegin(this->classname, parent_class);
    00101   }
    00102
    00103   template <typename Func, int Tnparam>
    00104   void AddConstructor(Squirrel *engine, const char *params)
    00105   {
    00106     using namespace SQConvert;
    00107     engine->AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, Tnparam, params);
    00108   }
    00109
    00110   void PostRegister(Squirrel *engine)
    00111   {
    00112     engine->AddClassEnd();
    00113   }
    00114 };
    00115
    00116 #endif /* SQUIRREL_CLASS_HPP */