gooブログはじめました!

写真付きで日記や趣味を書くならgooブログ

angelscript_array

2009-12-19 18:06:27 | インポート

// Main class declaration
class MyClass {
public:
    int variable[128];
};

// C++ class instance
MyClass mc;


// Getter proxy
int Proxy_getvariable(const MyClass * myclass, int index) {
    if ((index) > sizeof(myclass->variable) / sizeof(myclass->variable[0]))
        asGetActiveContext()->SetException("Index out of bounds!");
    return myclass->variable[index];
}

// Setter proxy
void Proxy_setvariable(MyClass * myclass, const int& newint, int index) {
    if ((index) > sizeof(myclass->variable) / sizeof(myclass->variable[0]))
        asGetActiveContext()->SetException("Index out of bounds!");
    myclass->variable[index] = newint;
}


// Angelscript class registration
r = engine->RegisterObjectType("MyClass", 0, asOBJ_REF | asOBJ_NOHANDLE); assert( r >= 0 );
r = engine->RegisterObjectMethod("MyClass", "int get_variable(int index)", asFUNCTION(Proxy_getvariable), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectMethod("MyClass", "void set_variable(const string &in, int index)", asFUNCTION(Proxy_setvariable), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterGlobalProperty("MyClass mc", &mc); assert( r >= 0 );

// Angelscript script example
void main() {
    mc.variable[10] = 33;
}


コメントを投稿