Could http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_handle.html be clarified regarding what happens when comparing two handles with == and != ? Is that functionally equivalent to is and !is?
Thanks
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Could http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_handle.html be clarified regarding what happens when comparing two handles with == and != ? Is that functionally equivalent to is and !is?
Thanks
Here's a brief explanation of the differences:
Foo@ a, b;
Foo c;
//These compare the value of the referenced instances, typically via opCmp()
a == b;
a == c;
c == b;
//These compare handles (pointers) for equality
@a == @b;
a is b;
a is c;
I'll update the manual to clarify how == and != works with handles, but the gist of it is that unless you prefix the expression with @ the comparison will be done by value on the object the handle refers to (i.e. call the opEquals method). (it is only necessary to prefix one of the expressions with @, and the compiler will automatically understand that the other must work on the address).
Thanks for the feedback, that's very helpful.
Similar questions regarding handles and dictionaries:
class Foo
{
Foo() { print("Foo"); }
Foo(const Foo &in other) { print("Foo(const Foo& other)"); }
Foo@ opAssign(const Foo &in other ) { print("opAssign(const Foo& other)"); return this; }
~Foo() { print("~Foo"); }
}
void main()
{
dictionary dict;
// Foo
// Foo
// opAssign(const Foo& other)
// ~Foo
dict['Foo'] = Foo();
// Foo
dict['Foo'] = @Foo();
// Foo
@dict['Foo'] = Foo();
// Foo
@dict['Foo'] = @Foo();
}
So the first variant takes a copy of Foo.
As soon as you use the handle-assignment syntax or take the handle of the instance of Foo, this is doing a handle assignment (storing a 'pointer' to the instance of Foo in the dictionary).. though technically the correct syntax is @dict['Foo'] = @Foo(); ?