v 0. Pasted by Anonymous as cpp at 2012-10-09 18:52:33 MSK and set expiration to never.

Paste will expire never.

  1. class CBytecodeStream : public asIBinaryStream
  2. {
  3. public:
  4.     CBytecodeStream() {wpointer = 0;rpointer = 0;}
  5.  
  6.     void Write(const void *ptr, asUINT size)
  7.     {
  8.         if( size == 0 )
  9.             return;
  10.         buffer.resize(buffer.size() + size);
  11.         memcpy(&buffer[wpointer], ptr, size);
  12.         wpointer += size;
  13.     }
  14.     void Read(void *ptr, asUINT size)
  15.     {
  16.         memcpy(ptr, &buffer[rpointer], size);
  17.         rpointer += size;
  18.     }
  19.  
  20.     int rpointer;
  21.     int wpointer;
  22.     std::vector<asBYTE> buffer;
  23. } script_stream;
  24.  
  25.  
  26. int des_count = 0, const_count = 0;
  27.  
  28. struct TestClass
  29. {
  30.     TestClass(){
  31.         std::cout << "const_count: " << ++const_count << "\n";
  32.     }
  33.     TestClass( const TestClass &from ){
  34.         std::cout << "const_copy_count: " << ++const_count << "\n";
  35.     }
  36.     ~TestClass(){ 
  37.         std::cout << "des_count: " << ++des_count << "\n";
  38.     }
  39. };
  40.  
  41. static void ConstructTestClass(TestClass *thisPointer)
  42. {
  43.     new(thisPointer) TestClass();
  44. }
  45. static void CopyConstructTestClass(const TestClass &other, TestClass *thisPointer)
  46. {
  47.     new(thisPointer) TestClass(other);
  48. }
  49. static void DestructTestClass(TestClass *thisPointer)
  50. {
  51.     thisPointer->~TestClass();
  52. }
  53.  
  54.  
  55. void FuckEEEEaaaa()
  56. {
  57.         asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
  58.  
  59.         engine->RegisterObjectType("TestLink", sizeof(TestClass), asOBJ_VALUE | asOBJ_APP_CLASS_CDK);
  60.         engine->RegisterObjectBehaviour("TestLink", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructTestClass), asCALL_CDECL_OBJLAST);
  61.         engine->RegisterObjectBehaviour("TestLink", asBEHAVE_CONSTRUCT, "void f(const TestLink &in)", asFUNCTION(CopyConstructTestClass), asCALL_CDECL_OBJLAST);
  62.         engine->RegisterObjectBehaviour("TestLink", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructTestClass), asCALL_CDECL_OBJLAST);
  63.         asIScriptModule *mod = engine->GetModule("mod", asGM_ALWAYS_CREATE);
  64.         mod->AddScriptSection("test",
  65.             "class Object3 \n"
  66.             "{ \n"
  67.             "    Object3( TestLink str ) \n"
  68.             "    { \n"
  69.             "        Object3 @null_object = null; \n"
  70.             "        null_object.Do(); \n"
  71.             "    } \n"
  72.             "    void Do() {} \n"
  73.             "} \n"
  74.             "void Main() \n"
  75.             "{ \n"
  76.             "   Object3 @oo = Object3( TestLink() ); \n"
  77.             "} \n" );
  78.        
  79.         mod->Build();
  80.  
  81.         script_stream.wpointer = 0;
  82.         mod->SaveByteCode( &script_stream );
  83.  
  84.  
  85.         script_stream.rpointer = 0;
  86.         mod->LoadByteCode( &script_stream );
  87.  
  88.         asIScriptContext *ctx = engine->CreateContext();
  89.  
  90.         ctx->Prepare( mod->GetFunctionByDecl( "void Main()" ) );
  91.         ctx->Execute();
  92.         ctx->Release();
  93.     }