Advertisement

Bug with registered properties and property accessors

Started by September 12, 2015 10:30 AM
0 comments, last by WitchLord 9 years, 2 months ago

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.

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.

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

This topic is closed to new replies.

Advertisement