Yep Your method works :)

But I did not give You my complete setup.

Here's a test that doesn't work

#include "utils.h"

#include <math.h>

#include <new>

#define TESTNAME "TestVector3"

#define asFUNCTION4(c,r,f,p) asFunctionPtr((asFUNCTION_t)( (r(*)p)c::f) )

class Vector3

{

public:

inline Vector3() {}

inline Vector3( float fX, float fY, float fZ ) : x( fX ), y( fY ), z( fZ ) {}

inline Vector3(const Vector3& other){ x=other.x; y=other.y; z=other.z; }

float x,y,z;

// asBEHAVE_CONSTRUCT

static void initVector3(Vector3* me);

// asBEHAVE_CONSTRUCT

static void initVector3(float x, float y, float z, Vector3* me);

// asBEHAVE_CONSTRUCT

static void initVector3(const Vector3& other, Vector3* me);

// asBEHAVE_DESTRUCT

static void destroyVector3(Vector3* me);

// asBEHAVE_ASSIGNMENT

static Vector3& copyVector3(Vector3& left, Vector3& right);

};

// asBEHAVE_CONSTRUCT

void Vector3::initVector3(Vector3* me)

{

new(me) Vector3(0,0,0);

}

// asBEHAVE_CONSTRUCT

void Vector3::initVector3(float x, float y, float z, Vector3* me)

{

new(me) Vector3(x,y,z);

}

// asBEHAVE_CONSTRUCT

void Vector3::initVector3(const Vector3& other, Vector3* me)

{

new(me) Vector3(other);

}

// asBEHAVE_DESTRUCT

void Vector3::destroyVector3(Vector3* me)

{

me->~Vector3();

}

// asBEHAVE_ASSIGNMENT

Vector3& Vector3::copyVector3(Vector3& other, Vector3& me)

{

me=other;

return me;

}

static char *script =

"Vector3 TestVector3() \n"

"{ \n"

" Vector3 v; \n"

" v.x=1; \n"

" v.y=2; \n"

" v.z=3; \n"

" return v; \n"

"} \n";

bool TestVector3()

{

bool fail = false;

int r;

asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

r = engine->RegisterObjectType("Vector3",sizeof(Vector3),asOBJ_CLASS_CDA);assert(r>=0);

r = engine->RegisterObjectProperty("Vector3","float x",offsetof(Vector3,x));assert(r>=0);

r = engine->RegisterObjectProperty("Vector3","float y",offsetof(Vector3,y));assert(r>=0);

r = engine->RegisterObjectProperty("Vector3","float z",offsetof(Vector3,z));assert(r>=0);

r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3()",asFUNCTION4( Vector3,void,initVector3,(Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 );

r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(float,float,float)",asFUNCTION4( Vector3,void,initVector3,(float,float,float,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 );

r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(const Vector3&)",asFUNCTION4( Vector3,void,initVector3,(const Vector3&,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 );

r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_DESTRUCT,"void destroyVector3()",asFUNCTION4( Vector3,void,destroyVector3,(Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 );

r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_ASSIGNMENT,"Vector3& copyVector3(Vector3& o)",asFUNCTION4( Vector3,Vector3,copyVector3,(Vector3&,Vector3&)),asCALL_CDECL_OBJLAST); assert( r >= 0 );

Vector3 v;

engine->RegisterGlobalProperty("Vector3 v", &v);

COutStream out;

engine->AddScriptSection(0, TESTNAME, script, strlen(script));

r = engine->Build(0, &out);

asIScriptContext *ctx = 0;

r = engine->CreateContext(&ctx);

int funcID = engine->GetFunctionIDByDecl(0,"Vector3 TestVector3()");

ctx->Prepare(funcID);

ctx->Execute();

r=ctx->GetReturnValue((asDWORD*)&v,int(ceil(sizeof(v)/4.0)));

engine->Release();

return fail;

}

It bails out when the constructor is called. So I guess I'm doing something complete wrong here. Btw the error does not occure if I use the ExecuteString method your using in the tests.

Maybe You see where my missconception is.

Thanks for Your time

Tom