Sign in to follow this  
iraxef

does a script function have to allow itself to be importable from another module?

Recommended Posts

Looking at http://www.angelcode.com/angelscript/sdk/docs/manual/doc_global_import.html, it's not clear whether the function I wish to import has to do anything (some special syntax?) to allow itself to be imported from another module. If not, does that mean that there's no way to prevent any module from importing (and calling) any function from any other module?

 

When you call a function that you imported from another module... is that running in your existing script context?

 

Are there any complete examples anywhere of using imports?

 

Thank you.

Share this post


Link to post
Share on other sites

The function that is imported doesn't have to be declared in any specific way. Any global function in the scripts is available for importing in another module.

 

It is up to the application to control which functions it wishes to allow or disallow for importing. If you wish to have this control at function level you'll need to manually bind the functions one-by-one instead of using the BindAllImportedFunctions.

 

When a script calls the imported function it will be executed by the current context. Remember the context is basically just a callstack. All global variables are stored in the module itself, so the imported function will have access to the global variables in the module it was imported from.

 

No, unfortunately I haven't written any examples of how to use the import functionality.

Share this post


Link to post
Share on other sites


When a script calls the imported function it will be executed by the current context. Remember the context is basically just a callstack. All global variables are stored in the module itself, so the imported function will have access to the global variables in the module it was imported from.

 

Just to clarify.. if script B calls a function which was imported from script A (different modules).. that function is executing in script B's context.. but since it can only access the global scope of script A's module.. it is just 'borrowing space' for its function scope from the active context (which was executing the script B function), but since it can't access script B's global scope.. it basically can't cause any side effects for script B?

Share this post


Link to post
Share on other sites
Correct. The function from script A cannot see the global variables in script B, hence it cannot modify them.

Of course, script A can import functions from script B too.

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