Jump to content
  • Advertisement
Sign in to follow this  
maximegriot

Importing C++ functions from AS

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

Hello,

 

I was thinking, is there a way to import a function from C++ and specify the signature from angelscript?

Like GetProcAddress returns a void* and we cast it to the correct function declaration in C++ to call the function correctly, is there a similar mechanism in AS ? 

 

All I could find was funcdefs but it appears to be a way to declare angelscript call conventions and not C++ call conventions.

 

Thanks,

Max

Share this post


Link to post
Share on other sites
Advertisement

What you can do is something like this:

 

Implement a C++ function with the following logic:

  • Get the desired funcdef signature from the output argument of variable type
  • Determine the address of the matching C++ function
  • Register the C++ function with the script engine
  • Get the asIScriptFunction pointer for the newly registered C++ function
  • Return the asIScriptFunction in the output argument

The most difficult part will be making sure the C++ function actually have the matching signature. Because if the signature is not matching and the script calls the function, you'll most like end up crashing the application due to stack corruption or memory invasions.

 

If you wish to register C++ functions dynamically like this, then I suggest you look into how to dynamically determine signatures of C++ functions. I've never done this myself, so I cannot give you much help in that direction, but perhaps it would be possible if the C++ function is accompanied with something like IDL that can be read at run time. Or perhaps you could look for some way of demangling the C++ symbols (though this is compiler specific).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!