Calling one script from another ?

Topics: Questions
Jan 18, 2008 at 6:14 PM
Is there a way to bind more than one script file (CSR) to each other ? I'm trying to achieve two things :

1. I should be able to call one script from another (without having to drop to Process.Start())
2. When debugging in scaffold, all scripts can show up in the project so debugging into a sub-script is easy..

TIA,
Vajrang.
Coordinator
Jan 27, 2008 at 10:22 PM

vajrang wrote:
Is there a way to bind more than one script file (CSR) to each other ? I'm trying to achieve two things :

1. I should be able to call one script from another (without having to drop to Process.Start())
2. When debugging in scaffold, all scripts can show up in the project so debugging into a sub-script is easy..

TIA,
Vajrang.



I tend to use Command.Run to run another script like this:

Command.Run("csr " + scriptName + scriptArguments, out output);

I don't have anything cleverer than that at the moment I'm afraid. It has the downside that another process is spun up for the called script. It would of course be possible to simply load and compile the script in the same appdomain and invoke it. Because calling the script would require some API support like say ScriptEnvironment.CallScript(), Scaffold support could be trickier. One possibility is to allow you to specify multiple scripts on the command line and load them all into Scaffold.

What is your reason for having multiple scripts? If the other scripts are just shared functionality then you could use a regular .NET assembly.
Jan 28, 2008 at 9:18 PM
Edited Jan 28, 2008 at 9:20 PM

jlyonsmith wrote:
[snip]
What is your reason for having multiple scripts? If the other scripts are just shared functionality then you could use a regular .NET assembly.


The other scripts are indeed shared functionality, but of course, the whole reason I don't want to make it a .NET assembly is so I avoid the "is the bin out of sync with the source or not" issue.

Also, I want to put multiple callable "functions" into one script file so others can reuse them. Creating a separate CSR file for each function seems overkill...
Coordinator
Jan 29, 2008 at 2:40 AM


vajrang wrote:

jlyonsmith wrote:
[snip]
What is your reason for having multiple scripts? If the other scripts are just shared functionality then you could use a regular .NET assembly.


The other scripts are indeed shared functionality, but of course, the whole reason I don't want to make it a .NET assembly is so I avoid the "is the bin out of sync with the source or not" issue.

Also, I want to put multiple callable "functions" into one script file so others can reuse them. Creating a separate CSR file for each function seems overkill...



You are absolutely correct of course. It would be great to have a low overhead way to call functionality in another script. That's a quintessential scripting language feature.

Does something like the CallScript method above seem like it would do the trick? Of course you could create a CallScriptMethod to call something other than Main. I'm pretty sure that it would be possible to add functionality to Scaffold to allow debugging of multiple scripts at a time by compiling them into one assembly and doing some Reflection magic in the CallScript method. I'll add it to the backlog. Further thoughts and comments welcome.