urho3d/Urho3D — pull request #100 by alexparlett (2013-12-31 01:03:29+00:00)
Title: Add the ability to Listen to Events on pure Script Classes

The classes must inherit the ScriptObject interface. This adds an additional optional parameter to to SubscribeToEvent in the following manner:

SubscribeToEvent("Update","HandleUpdate");
SubscribeToEvent("Update","HandleUpdate",@this);
SubscribeToEvent("Update","HandleUpdate",@foo);

SubscribeToEvent(@object,"Update","HandleUpdate");
SubscribeToEvent(@object,"Update","HandleUpdate",@this);
SubscribeToEvent(@object,"Update","HandleUpdate",@foo);

This required a change to how we store the pointer to the ScriptInstance class, since the object user data pointer is lost when moving between script classes, the pointer to the listener for ScriptInstance was moved to asIScriptContext UserData instead.

This allowed another change that means a ScriptFile can now handle SubscribeToEvent from inside a pure script class to depend on whether that asIScriptContext UserData pointer is null or not. However a ScriptFile must specify this optional parameter or it will look for a method outside the object, whereas the ScriptInstance will still fall back on its original asIScriptObject.

-----

This seems to be completely working on my tests with both ScriptFile and ScriptInstance but I wouldn't be against some more rigorous testing (by myself and others) before merging, I just wanted to get the code up for inspection and suggestions on anything that might need further work.