Jump to content
  • Advertisement
Sign in to follow this  
Miss

Suggestion: Callback for external functions

Recommended Posts

I would like to implement loading functions from external DLL's, in a syntax such as this:

[Dll file="Test.dll"]
external void DoSomething();

Currently, the external keyword requires that the function be defined in a module already before this declaration is compiled (since it's (implicitly?) a shared function), which breaks my ability to get the metadata from CScriptBuilder about the function.

My suggestion is to have a callback function for external functions where I can resolve the function manually, possibly referring it to some asCALL_GENERIC function that handles the dll call.

Perhaps this should be implemented in the CScriptBuilder addon rather than the library itself, since that holds the info on the metadata above the declaration.

Any tips/workarounds would be nice to hear as well.

Share this post


Link to post
Share on other sites
Advertisement

'external' is meant for shared functions from previously compiled script modules, and not for registered functions.

You can still use the syntax you want, but then you need to make modifications to CScriptBuilder to identify these in a pre-processing pass, register the functions, and then build the script module.

However, the '#pragma' directive is probably more suitable for this. The CScriptBuilder in the WIP version supports defining a callback for the pragma directive which is identified during the pre-processing pass. Your callback can then load the dll and register the desired function.

Example:

#pragma use 'void DoSomething()' from 'foo.dll'

I`m planning to do something similar in the asrun sample to support plugins. Currently I only use the pragma directive it to inform asrun that the script should be started in debug mode.

 

Share this post


Link to post
Share on other sites

And maybe we could load library in similar way just like:

#pragma library("foo.dll")

and suppose there is a function "void InitializeLibrary(asIScriptEngine* engine)" in the dll, so we can register types and functions in the function.

Share this post


Link to post
Share on other sites

That would be very nice too. I'd love to have such a thing as an addon if you end up putting it in asrun!

Share this post


Link to post
Share on other sites

I don't see it being generic enough to be useful as an add-on. However, the code for asrun is also part of the library so you will be free to reuse it as you see fit :)

Share this post


Link to post
Share on other sites
Posted (edited)

Hmm, the problem with the #pragma approach is that if you have multiple modules, registering a function will be available to each module rather than only 1 module. Is there anything that can be done about that?

Edited by Miss

Share this post


Link to post
Share on other sites

If you want different modules to have different application interfaces, then you can do one of the following:

1. use multiple engines

2. use configuration groups with different access masks. You'll need to use namespaces too to resolve conflicts if two modules happen to load the same plugin. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!