Advertisement

Pointers to member functions

Started by July 16, 2012 01:16 AM
1 comment, last by TechRogue 12 years, 4 months ago
I can't seem to find any mention of whether this is possible or not. I'll explain what I'd like to do, and if it's impossible feel free to shoot me down. smile.png

I have a keyboard class registered as a singleton in my game engine, so my scripts can access key state. The interface looks like this:


if (keyboard.space)
{
doStuff();
}


The keys (in this case 'space') are implemented as property accessors that return a bool.

I'd like to be able to do something like this:


bind(@keyboard.space, @doStuff);


In this case, a pointer to the accessor would be stored along with a pointer to another function. The first function would be called continually, and if it returns true the second function would be called. I understand I could get the function object by declaration and set the calling object in the application, but I'd like to be able to do this with function and funcdefs.

So I'm wondering two things, actually:

  1. Are pointers to member functions possible currently, or might they be in a future version?
  2. If they are possible, would pointers to accessors need to be declared in long-form (@obj.get_prop), or would the short-form work as well (@obj.prop)?
It's currently not possible to take pointers to class methods.

I have plans to implement something similar to c# / java delegates, though I don't know when I'll get to it.

Getting the pointer to a virtual property accessor will have to be done through the full name, e.g get_property, otherwise it would not be known which method it is.

Regards,
Andreas

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
Alright, thanks for the info. I look forward to the feature if/when you implement it, but it's not a blocking issue until then. :)

This topic is closed to new replies.

Advertisement