Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

std::function to asSFuncPtr


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 B_old   Members   -  Reputation: 664

Like
0Likes
Like

Posted 25 October 2012 - 01:57 AM

I'm wondering if there is a practicable way of converting a std::function to an asSFuncPtr. I think it would be nice to have an interface/wrapper to the script engine that can be used without including angelscript.h. Can this or something similar be done?

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9597

Like
0Likes
Like

Posted 25 October 2012 - 09:58 AM

It's not possible to directly assign a std::function to an asSFuncPtr; however, it's possible to get that functionality with a little work. First create a class that contains a map of function IDs to std::function<void (asIScriptGeneric *)> and set a pointer to that class as the script engine's user data. Then every time you want to register a std::function, instead register a generic function that looks up the function ID in the map and calls the appropriate std::function. The registration function returns the function ID for the function you just registered so then stick a std::function<void (asIScriptGeneric *)> in the map with the appropriate ID. For the basic idea of how to convert an arbitrary function object to one using the script generic calling convention look at the autowrapper add-on.

#3 B_old   Members   -  Reputation: 664

Like
0Likes
Like

Posted 26 October 2012 - 05:41 AM

Ah, that is a good idea. I would prefer to get rid of the indirection at compile time, but if this is not feasible without including angescript.h I can always come back to your suggestion.
I could also register functions that come from inside the framework with the AS macros and use another interface for stuff that might be registered by the application.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS