Sign in to follow this  
Takayuki

bug? setter with string

Recommended Posts

Because it might be a bug, it reports. The following error occurs and the setter doesn't operate correctly. "The property 'FileName' has mismatching types for the get and set accessors" ////////// CMyClass ////////// // static void CMyClass::set_FileName_Generic(asIScriptGeneric *gen) { ..... } void CMyClass::set_FileName(const std::string &strText) { ..... } ////////// Register type1 ////////// r = engine->RegisterObjectMethod("CMyClass", "void set_FileName(const string &in)", asFUNCTION(CMyClass::set_FileName_Generic), asCALL_GENERIC); assert(r>=0); ////////// Registertype2 ////////// r = engine->RegisterObjectMethod("CMyClass", "void set_FileName(const string &in)", asMETHODPR(CMyClass, set_FileName, (const std::string &), void), asCALL_THISCALL); assert(r>=0); ////////// Script typeA ////////// // Register type1 OK // Register type2 OK CMyClass my; my.set_FileName("c:\\test.txt"); ////////// Script typeB ////////// // Register type1 Error // Register type2 Error CMyClass my; my.FileName = "c:\\test.txt";

Share this post


Link to post
Share on other sites
I'm sorry, did you mean that you didn't register the 'get_FileName'?

I tried reproducing this problem, but I'm not getting the compile error you mentioned.

That error should only happen if both the set and get property accessors are there, but they have a different type, e.g. 'int get_FileName()' and 'void set_FileName(const string &in)'.

Regards,
Andreas

Share this post


Link to post
Share on other sites
My get_FileName was registered like this.

////////// CMyClass //////////
CScriptString *get_FileName()
{
/* */CScriptString *pstr = new CScriptString();
.....
/* */return pstr;
}


////////// Register type //////////
r = engine->RegisterObjectMethod("CMyClass", "string@ get_FileName()", asMETHOD(CMyClass, get_FileName), asCALL_THISCALL);

Share this post


Link to post
Share on other sites
OK. Then I know why you get the error:

void set_FileName(const string &in) and string@ get_FileName() is not using the same type. One is using 'string' and the other is using 'string@', that's why the compiler is giving the error.

Since you can't change the get_FileName to return a reference, without getting a memory leak, I suggest you change set_FileName to take a string handle instead, i.e. void set_FileName(string@).



From my side, I will also look into changing the compiler to allow this difference in types, since both are really the same base object.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Hmm. I'll have to think how this should best be solved.

What's happening is this. The compiler sees that you're attempting to do a value assignment, but it understands that the property is a handle. Thus the code is rewritten as follows:


string @tmp = @my.get_FileName();
tmp = "c:\\test.txt";


If the script was written as @my.FileName = @"c:\\test.txt"; then the compiler would call set_FileName instead. But I understand that you do not want to force the script to do a handle assignment.

I need to change AngelScript so that the application can inform that the property is not a handle, yet still allow the get accessor to return a handle instead of a reference in order to avoid memory leaks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this