Sign in to follow this  

Bug with registered properties and property accessors

This topic is 825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It is possible to register a property, and a property accessor that both have the same name:

struct foo
{
	int bar = 0;

	static foo* create()
	{
		return new foo;
	}

	static int get_bar( foo* pThis ) { return pThis->bar; }
};

m_pScriptEngine->RegisterObjectType( "foo", 0, asOBJ_REF | asOBJ_NOCOUNT );

m_pScriptEngine->RegisterObjectBehaviour( "foo", asBEHAVE_FACTORY, "foo@ foo()", asFUNCTION( foo::create ), asCALL_CDECL );

m_pScriptEngine->RegisterObjectProperty( "foo", "int bar", asOFFSET( foo, bar ) );

m_pScriptEngine->RegisterObjectMethod( "foo", "int get_bar() const", asFUNCTION( foo::get_bar ), asCALL_CDECL_OBJLAST );

Where m_pScriptEngine is asIScriptEngine*.

 

It seems that the accessor is always used; when you try to assign a value to it, it will report an error saying no set accessor exist.

Share this post


Link to post
Share on other sites

The property accessors hides a real property of the same name. This is not really a bug, but I can see that it would be better to validate and give an error in case the application tries to register the interface like this.

 

I'll add an item on my to-do list to implement this validation.

Share this post


Link to post
Share on other sites

This topic is 825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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