Advertisement Jump to content
Sign in to follow this  

Importing C++ functions from AS

This topic is 956 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 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.




Share this post

Link to post
Share on other sites

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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!