Files
@ r11976:ae6aa97461b7
Branch filter:
Location: cpp/openttd-patchpack/source/src/script/squirrel_class.hpp - annotation
r11976:ae6aa97461b7
3.8 KiB
text/x-c++hdr
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 | /* $Id$ */
/** @file squirrel_class.cpp defines templates for converting C++ classes to Squirrel classes */
#ifndef SQUIRREL_CLASS_HPP
#define SQUIRREL_CLASS_HPP
#if (__GNUC__ == 2)
/* GCC 2.95 doesn't like to have SQConvert::DefSQStaticCallback inside a
* template (it gives an internal error 373). Above that, it doesn't listen
* to 'using namespace' inside a function of a template. So for GCC 2.95 we
* do it in the global space to avoid compiler errors. */
using namespace SQConvert;
#endif /* __GNUC__ == 2 */
/**
* The template to define classes in Squirrel. It takes care of the creation
* and calling of such classes, to make the AI Layer cleaner while having a
* powerful script as possible AI language.
*/
template <class CL>
class DefSQClass {
private:
const char *classname;
public:
DefSQClass(const char *_classname) :
classname(_classname)
{}
/**
* This defines a method inside a class for Squirrel.
*/
template <typename Func>
void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
}
/**
* This defines a method inside a class for Squirrel, which has access to the 'engine' (experts only!).
*/
template <typename Func>
void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, const char *function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
}
/**
* This defines a method inside a class for Squirrel with defined params.
* @note If you define nparam, make sure that he first param is always 'x',
* which is the 'this' inside the function. This is hidden from the rest
* of the code, but without it calling your function will fail!
*/
template <typename Func>
void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name, int nparam, const char *params)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
}
/**
* This defines a static method inside a class for Squirrel.
*/
template <typename Func>
void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc));
}
/**
* This defines a static method inside a class for Squirrel with defined params.
* @note If you define nparam, make sure that he first param is always 'x',
* which is the 'this' inside the function. This is hidden from the rest
* of the code, but without it calling your function will fail!
*/
template <typename Func>
void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name, int nparam, const char *params)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
}
template <typename Var>
void DefSQConst(Squirrel *engine, Var value, const char *var_name)
{
engine->AddConst(var_name, value);
}
void PreRegister(Squirrel *engine)
{
engine->AddClassBegin(this->classname);
}
void PreRegister(Squirrel *engine, const char *parent_class)
{
engine->AddClassBegin(this->classname, parent_class);
}
template <typename Func, int Tnparam>
void AddConstructor(Squirrel *engine, const char *params)
{
using namespace SQConvert;
engine->AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, Tnparam, params);
}
void PostRegister(Squirrel *engine)
{
engine->AddClassEnd();
}
};
#endif /* SQUIRREL_CLASS_HPP */
|