Jump to content
  • Advertisement
Sign in to follow this  

Interception of method call

This topic is 821 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


I have new question.

Is there an ability to intercept an object's arbitrary method call or access to object's properties?

In details:

I have a class 'selector' incapsulating mechanics of enumeration and selection of objects of different classes. I'm interesting in ability to

call same-named methods of group of objects by calling an fictitious method of selector. Selector must translate it to calls of methods of enumerated objects with actual arguments list.

Set of methods unknown at compile time and it's impossible to make needed selector's methods.

For example:


// selector

selector s=s();

// initialize 's' selector, bind it to some objects


// call all objects methods

s.foo("test",12); // foo methods of all enumerated object same signatures will be called


If there is a combination of Angel Script mechanics, overloaded operators etc, it would be very usefull for me. Best way is to intercept method's call with information of method's name, types and values of arguments and returning value.

Edited by VoidSpirit

Share this post

Link to post
Share on other sites

For this you'll need to implement some kind of reflection, i.e. provide a way for the script to find functions at run-time and then call them. This is perfectly possible to do, but I don't have anything already implemented for this.


Here's a couple of forum threads that have some implementations that you may use as a starting point:




Share this post

Link to post
Share on other sites

Thank you for answer!

But, as I understand, reflection does not solve this problem.

In example code above 'selector' is an application class that has neither method 'foo' no other methods linking it to other classes. Selector does not know about other classes. I want it can dynamically intersept any-named method call and translate it to call of methods of enumerated objects. Any linking must be realized at run-time.

Desired mechanics:


I write at script:

selector s=selector();




s.move(0,0); // example method call. selector has no method 'move', and not all objects have. But an application can get this call as information about the name of called method and actual parameters, take each binded object, find same method 'move' in it and try to call it.


At current time code 's.move(0,0)' of course cases a compile-time error.

Share this post

Link to post
Share on other sites

s.move(0,0) cannot be done as-is, since the script will only be able to call methods on the registered type that has been registered. However, you could provide something like this:


s.invoke('move', 0, 0);


Where the invoke method is implemented as a C++ method and takes the name of the method that should be called on all the bound objects and the arguments that should be used. You can make the invoke method support variable arguments through the use of the variable parameter type, combined with multiple overloads to support a variable number of arguments. Or you could use the dictionary type to pass the arguments to the invoke method, and the implementation extracts the arguments from the dictionary to pass them on to the bound object methods.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!