Scripts

Scripts

C Sharp:

Is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented( class-based), and component-oriented programming disciplines.

C++:

Is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level<span style="color: rgb(0, 0, 0); font-family: sans-serif; font-style: normal; line-height: 19px; "> and low-level<span style="color: rgb(0, 0, 0); font-family: sans-serif; font-style: normal; line-height: 19px; "> language features.

<span style="color: rgb(0, 0, 0); font-family: sans-serif; font-style: normal; line-height: 19px; ">Boo Script:

<span style="color: rgb(0, 0, 0); font-family: verdana, tahoma, helvetica, sans-serif; font-style: normal; line-height: 16px; text-align: left; ">This is actually relatively simple; we only need a few of the Boo.Lang.Compiler classes to make it happen.

<p style="font-family: verdana, tahoma, helvetica, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em; color: rgb(0, 0, 0); font-style: normal; line-height: 16px; text-align: left;">The classes most important to us are: <p style="font-family: verdana, tahoma, helvetica, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em; color: rgb(0, 0, 0); font-style: normal; line-height: 16px; text-align: left;">Using these classes and reflection, we will be able compile Boo scripts to memory and run'em on inputted variables.
 * Boo.Lang.Compiler.BooCompiler - the class that handles compilation of Boo code.
 * Boo.Lang.Compiler.Pipelines.CompileToMemory - a compiler pipeline that compiles Boo code into memory instead of a file output. You'll want this for most scripting situations.

<p style="font-family: verdana, tahoma, helvetica, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em; color: rgb(0, 0, 0); font-style: normal; line-height: 16px; text-align: left;">Suppose script.boo is a class that the user has written, and you want to consume it by your application without the user having to dance with booc.exe or some other fancy pants method.

script.boo
<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">Calling scripting Boo from Boo is ridiculously easy--too easy to even explain, so here is the commented code.

runBoo.boo
<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">That was painless, wasn't it? As you're imaging, you can instanize classes and call instance methods via the convience of duck typing in a similar fashion. Consider the code-block below.

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">That's it. Use myInstance as you would any other class, sans code completion

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">This method, of course, is not as interesting as using another language entirely to invoke our Boo script. Let's see how we do it in C#:

runBoo.cs
<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">I compiled the above runBoo.cs script with this command (you can change csc to gmcs if you use mono):

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">If you are on Windows, make sure you specify the paths to the boo dlls. After compiling, either move runBoo.exe into the same folder as the boo dlls or copy the dlls to the same folder as your exe. Then run the exe, making sure "script.boo" is in the same folder as your current directory:

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">As you can see the C# variant is a bit more verbose, but that's your bag, let it roll.

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">Here are the highlights of the C# version.

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">ScriptModule is the name of the class encapsulating the main method and the stringManip method of the compiled "script.boo" It is a uniquely generated name determined by the file-name plus a "Module" postfix. Javascript:

<p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0.6em;">JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative , and functional programming styles.