Reference is read-only, error

Started by
4 comments, last by behc 16 years, 10 months ago
hi i have got some confusing error messages about read-only references when calling behaviors (or regular functions)

//as
(...)
CCamera@ pCam = wp.GetCamera();
vec3 end = pCam.Pos + pCam.Dir*1000;


//cpp (some important functions)
r = engine->RegisterGlobalBehaviour(asBEHAVE_ADD,"vec3 f(const vec3 &in, const vec3 &in)",asFUNCTION(vec3add),asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalBehaviour(asBEHAVE_SUBTRACT,"vec3 f(const vec3 &in, const vec3 &in)",asFUNCTION(vec3sub),asCALL_CDECL); assert(r >= 0);

r = engine->RegisterGlobalBehaviour(asBEHAVE_MULTIPLY,"vec3 f(const float, const vec3 &in)",asFUNCTION(vec3mul1),asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalBehaviour(asBEHAVE_MULTIPLY,"vec3 f(const vec3 &in, const float)",asFUNCTION(vec3mul2),asCALL_CDECL); assert(r >= 0);

//and camera class props
r = pSE->RegisterObjectProperty(pClassName,"const vec3 Pos",offsetof(CGRCamera,Pos)); assert(r>=0);
r = pSE->RegisterObjectProperty(pClassName,"const vec3 Dir",offsetof(CGRCamera,Dir)); assert(r>=0);
when i remove 'const' from camera's RegisterObjectProperty everything works fine and when i compile script below, everything is ok too (which is the most confusing)

//as
const vec3 v1(0,2,0);
const vec3 v2(1,1,0);
vec3 ple = v1 + v2*1000;
are object properties 'const' in different way than local variables? (or can i register behaviors to be more const? :) ) (i've tested that on wip and last stable version (2.7)) hans
Advertisement
Object properties cannot be registered as const. AngelScript don't know how to do that (at least not yet).

You can overload methods and behaviours to handle const objects. Just add const after the method declaration, i.e. "void f() const".

What message is confusing to you? I may need to change it.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

hm.. so if i can't register const object properties, the function below should fail? (the 'Pos' property is not const in cpp, but i want it to be read-only in as, (and vec3 is simple 3d vector class))
r = pSE->RegisterObjectProperty(pClassName,"const vec3 Pos",offsetof(CGRCamera,Pos)); assert(r>=0);

anyway that call seems to work, i can (inside script) copy 'Pos' to another variable and i can't change it directly (as gives me: "Reference is read-only" error, like it should be), but i can't pass it as 'const vec3 &in' to functions/behaviors because of the same error. (i would understand that error when trying to pass 'Pos' as 'vec3 &in')

if this is some unimplemented feature then it's ok, there are some easy workarounds i can use,
i just thought it might be a bug :)

hans
Now that you show me the error messages I do remember implementing support for registering properties as const.

I'll have to investigate why it gives an error when passing the property to a const &in parameter though. It could very well be a bug in AS.

Thanks,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'm sorry for taking so long, but I have finally fixed this bug. The fix is currently available in the latest version in the SVN: revision 137.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

thanks for the fix

hans

This topic is closed to new replies.

Advertisement