Advertisement

Registering same method twice

Started by August 12, 2012 02:37 PM
2 comments, last by WitchLord 12 years, 4 months ago
Hi,


class Base
{
virtual void Foo() {}
};
class Child : public Base
{
virtual void Foo() {}
}


when i register both base and child
like this

RegisterBase<Child>("Child");
r = engine->RegisterObjectMethod("Child", "void Foo()", asMETHOD(Child, Foo), asCALL_THISCALL);
assert(r >= 0);


same method registered twice,
i expect second registration to overwrite the first one.
but they both exist in script. giving me multiple matches error when called.

shouldnt second method overwrite the first since they are the same?

thanks.
No, it shouldn't overwrite it.

It should give you an error that the method has already been registered though, but that is not implemented yet.



I assume the method you're registering twice is virtual, right? In that case it is not necessary to register the derived class' method.

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

Advertisement

No, it shouldn't overwrite it.

It should give you an error that the method has already been registered though, but that is not implemented yet.



I assume the method you're registering twice is virtual, right? In that case it is not necessary to register the derived class' method.


for some children it is virtual, for some it isnt virtual.

this creates additional work and attention when registering child classes.

like so:

if(name == "Child1")
{
// dont register certain functions
}
else if(name == "Child2")
{
// dont register certain functions
}


it is counter intuitive to add these to base register function.

and impossible to catch if i missed something since it doesnt give an error until it is used in script.

edit:
i should note that, this is not a much problem when working with small classes.
i have been registering http://www.ogre3d.org/docs/api/html/classOgre_1_1MovableObject.html class.
wrote about 1200 lines of registration. then realized that registering methods more than once does not override previous one.
now i gotta trace my steps back and find all those methods and place guards around them.
just wanted to know if this was a bug or an oversight.
Just overwriting what was registered before is dangerous too, because it might mean the application was registering something incorrectly.

I'll see if I can implement the check for duplicate methods for version 2.25.0.

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