00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asDataStack.h"
00018
00019 #ifdef __COMPILE_WITH_ANGELSCRIPT__
00020
00021 #include "../ScriptHelper.h"
00022
00023 #include "../../core/DataStack.h"
00024
00025
00027 DataStack* createDataStack(const std::string &name)
00028 {
00029 return new DataStack(name);
00030 }
00031
00033 template<typename T>
00034 void bindSetGetVar(asIScriptEngine *engine, const std::string &asType)
00035 {
00036
00037 int r;
00038 std::stringstream ss;
00039
00040
00041 ss.str("");
00042 ss << "bool set_" << asType << "(const string &in, const " << asType << ")";
00043 r = engine->RegisterObjectMethod("DataStack", ss.str().c_str(),
00044 asMETHODPR(DataStack, setVar<T>, (const std::string&, const T&), bool),
00045 asCALL_THISCALL);
00046
00047
00048 ss.str("");
00049 ss << asType << " get_" << asType << "(const string &in)";
00050 r = engine->RegisterObjectMethod("DataStack", ss.str().c_str(),
00051 asMETHODPR(DataStack, getVar<T>, (const std::string&), T),
00052 asCALL_THISCALL); assert(r >= 0);
00053 }
00054
00056 void bindDataStack(asIScriptEngine *engine)
00057 {
00058
00059 int r;
00060
00061
00062 r = engine->RegisterObjectType("DataStack", sizeof(DataStack), asOBJ_REF); assert(r >= 0);
00063
00064
00065 r = engine->RegisterObjectBehaviour("DataStack", asBEHAVE_FACTORY, "DataStack@ f(const string &in)",
00066 asFUNCTION(createDataStack), asCALL_CDECL); assert(r >= 0);
00067 r = engine->RegisterObjectBehaviour("DataStack", asBEHAVE_ADDREF, "void f()",
00068 asMETHOD(DataStack, grab), asCALL_THISCALL); assert(r >= 0);
00069 r = engine->RegisterObjectBehaviour("DataStack", asBEHAVE_RELEASE, "void f()",
00070 asMETHOD(DataStack, drop), asCALL_THISCALL); assert(r >= 0);
00071
00072 r = engine->RegisterObjectMethod("DataStack", "DataStack& opAssign(const DataStack &in)",
00073 asFUNCTION(assignT<DataStack>), asCALL_CDECL_OBJFIRST); assert(r >= 0);
00074
00075
00076 r = engine->RegisterObjectMethod("DataStack", "void init()",
00077 asMETHOD(DataStack, init), asCALL_THISCALL); assert(r >= 0);
00078 r = engine->RegisterObjectMethod("DataStack", "void clear()",
00079 asMETHOD(DataStack, clear), asCALL_THISCALL); assert(r >= 0);
00080
00081 r = engine->RegisterObjectMethod("DataStack", "u32 getID()",
00082 asMETHOD(DataStack, getID), asCALL_THISCALL); assert(r >= 0);
00083 r = engine->RegisterObjectMethod("DataStack", "const string& getName()",
00084 asMETHOD(DataStack, getName), asCALL_THISCALL); assert(r >= 0);
00085
00086
00087 bindSetGetVar<c8>(engine, "c8");
00088 bindSetGetVar<f32>(engine, "f32");
00089 bindSetGetVar<f64>(engine, "f64");
00090 bindSetGetVar<s16>(engine, "s16");
00091 bindSetGetVar<s32>(engine, "s32");
00092 bindSetGetVar<u16>(engine, "u16");
00093 bindSetGetVar<u32>(engine, "u32");
00094 bindSetGetVar<u8>(engine, "u8");
00095 bindSetGetVar<std::string>(engine, "string");
00096
00097 r = engine->RegisterObjectMethod("DataStack", "void removeVars()",
00098 asMETHOD(DataStack, removeVars), asCALL_THISCALL); assert(r >= 0);
00099 r = engine->RegisterObjectMethod("DataStack", "bool removeVar(const string &in)",
00100 asMETHOD(DataStack, removeVar), asCALL_THISCALL); assert(r >= 0);
00101
00102 r = engine->RegisterObjectMethod("DataStack", "bool saveBencode(const string &in)",
00103 asMETHOD(DataStack, saveBencode), asCALL_THISCALL);assert(r >= 0);
00104 r = engine->RegisterObjectMethod("DataStack", "bool loadBencode(const string &in)",
00105 asMETHOD(DataStack, loadBencode), asCALL_THISCALL);assert(r >= 0);
00106
00107 r = engine->RegisterObjectMethod("DataStack", "bool saveXML(const string &in)",
00108 asMETHOD(DataStack, saveXML), asCALL_THISCALL);assert(r >= 0);
00109 r = engine->RegisterObjectMethod("DataStack", "bool loadXML(const string &in)",
00110 asMETHOD(DataStack, loadXML), asCALL_THISCALL);assert(r >= 0);
00111 }
00112
00113 #endif // __COMPILE_WITH_ANGELSCRIPT__
00114
00115