Advertisement

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

Started by December 19, 2013 05:59 PM
2 comments, last by WitchLord 10 years, 10 months ago

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.

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.

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


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?

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.

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