Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 iraxef   Members   -  Reputation: 300

Like
0Likes
Like

Posted 19 December 2013 - 11:59 AM

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.



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3221

Like
0Likes
Like

Posted 19 December 2013 - 12:50 PM

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

#3 iraxef   Members   -  Reputation: 300

Like
0Likes
Like

Posted 13 January 2014 - 09:12 PM


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?



#4 Andreas Jonsson   Moderators   -  Reputation: 3221

Like
0Likes
Like

Posted 14 January 2014 - 06:07 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS