Advertisement

External API Binding: to Wrap or not to Wrap?

Started by April 17, 2015 09:11 AM
2 comments, last by WitchLord 9 years, 7 months ago

Hi,

I am working on binding external C APIs (such as openGL) to my angelscript engine, and I am wondering if it is wise to directly bind the functions of the external API or if I should write function wrappers instead.

I ask this question because these APIs typically have different calling conventions on different platforms (all win32 APIs are stdcall for example), so I am wondering if it may cause issues. For example, would it break pre-compiled bytecode sharing between platforms?

By the way does anyone know a good binding generator script for C APIs (I have seen a few C++ binding tools that seem to be mostly prototypes for the moment, but C APIs should be much simpler)? It would be great if it could handle typedefs and literals #DEFINE directives.... :-)

The calling convention doesn't influence the pre-compiled bytecode. As long as the script function signature is the same the bytecode will be compatible.

To wrap or not to wrap mostly depends on your own preference, unless of course you're building the application for a platform that does not yet have support for native calling convention.

For application functions that are called with a very high frequency it may be beneficial to try both wrapped and native to see which performs best on that platform.

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

Thanks! I was not quite sure about the calling convention and bytecode.

Wouldn't it be surprising that a wrapped function performs better? This probably only adds overhead because of the additional function call.

The overhead of dynamically setting up the CPU registers that is necessary for calling the functions natively is quite similar to the overhead of the wrapper function.

Take a look at what goes on in the CallSystemFunction and you'll get a feeling of the overhead. :)

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement