   Angelcode script execution
  Hi users, I love angelscript and its simplicity, but one thing that i cant figure out is the calling of a script that has no functions in it. I only recently started using it again and i got confused by this - For example : void main(){   print("hello");}and BuildScriptFromFile()...->GetFunctionIdByDecl("void main()");mContext->Prepare(funcId);mContext->Execute();Works perfectly fine, all my functions work and everything is great. Now, what i wanted to do was a script like below : //script.as //does stuffprint("hello");<EOF>As in, there are no functions and i only call the script as is. This results in errors about the script saying <0 , 0> : ERR : Identifier expected. I tried many ways but i dont think its possible to have scripts with no main function and or, something being called without being called code side first? Does this mean every script i want to execute will require a function (unless its just a library of functions) to be called in order for it to be processed? I think what i mean is, can you call functions in the whitespace of a script :)   
  AngelScript currently doesn't support code in the global scope. Only declarations can be done in the global scope.You can easily wrap the code in a function though, just as is done for ExecuteString(). The only problem is that then the script writer can't declare his own classes and functions.Regards,Andreas   ;  Cool thanks Andreas, thats what i suspected :) I did write a wrapper function that first parsed all the function calls out of the file, and then load the rest of the string into the global scope. My approach was to at first, farm the functions that get called in the scope, and then with whats left compile them into the context for use. This seems to work fine for what i wanted, and it wasnt too much extra work but i do think its a cool feature for the engine to have. Keep up the awesome work, and support here in the community.[Edited by - FuzzYspo0N on May 28, 2009 11:34:54 AM];  Sorry for writing in foreign threads, but I think this question match in here.Quote:Original post by WitchLordYou can easily wrap the code in a function though, just as is done for ExecuteString(). The only problem is that then the script writer can't declare his own classes and functions.So there is no way to execute lines of code, which contains class defines, declarations of functions or global properies, and access to these kind of things, which were decared in earlier executed code, at the same call ?Like it is used in Lua or Python:doString(" int i = 3");doString("print(i)");doString(" int i2 = i*2;");;  Those examples would work as neither of them declare any classes or functions.What happens in ExecuteString is that it creates a dummy function that wraps your code. Ie doString(" int i = 3"), will turn into something likevoid dummy(){   int = 3;}and doString("print(i)") would turn intovoid dummy(){    print(i);}The problem is when you try to declare a function for example doString("void myFunction() { int i = 3; } myFunction()") as that would turn intovoid dummy(){    void myFunction() { int i = 3; } myFunction();}which is illegal syntax.Also, as the scope for each call to ExecuteString is different you must make sure the variables used are defined outside of it.   ;  I've been tinkering with trying to get REPL functionality for AngelScript. Currently my approach is to create a module and every step through the loop, add the code generated as a new script section to the module. If it doesn't compile, then try executing the section as part of a function body. If that also doesn't work, add it to a buffer and treat that buffer as a prefix for the next text entered. Unfortunately, it doesn't seem to work too well so far; code that I think should be valid is dying strangely. Admittedly, I haven't put a lot of time into this project.   ;  Oh noooo.I was just starting to like AngelScript, but this fact ought to make me using Lua, although angelscript has many advantages Lua misses. :( :( :(   ;Quote:Original post by SiCraneUnfortunately, it doesn't seem to work too well so far; code that I think should be valid is dying strangely.It seems like script sections don't work how I thought they worked, so it seems like this approach is doomed. Darn it.;  While i agree it would nice to have this, is it so bad to just require your users to have a void main() or void execute() function?   ;Quote:Original post by _matthias_So there is no way to execute lines of code, which contains class defines, declarations of functions or global properies, and access to these kind of things, which were decared in earlier executed code, at the same call ?Currently, no.I am however working on making the modules more dynamic. It will be possible to add new global variables, functions, etc to an already existing module without recompiling the whole thing. It will also be possible to remove them one by one, without compilation. Once that is done, you will be able to do what you want.With this dynamic capabilities it should also be possible to 'hot load' scripts, i.e. recompile individual scripts, without loosing current instances of classes, etc.I also need this dynamic modules, to support self modifying code, and dynamic function pointers.Quote:Original post by _matthias_Oh noooo.I was just starting to like AngelScript, but this fact ought to make me using Lua, although angelscript has many advantages Lua misses. :( :( :(Do you need it right away? I'll hopefully have this working with the next 2 or 3 releases.   