Scripts

icon_script.png Scripts allow us to write programs for execution within Manifold using a variety of built in and supported languages.    Scripts can be edited when they are opened in a Script window.  In addition, JavaScript, IronPython and IronRuby can be edited and executed from the Command window, using the Command window as a REPL (Read-Eval-Print Loop) console.

 

tech_yoshi_sm.png

Must read info:   All programmers should review the API Documentation online.    The API Documentation provides total details on the API and also provides hundreds of examples, many of which are provided side-by-side in three versions, in C#, in VBScript and in IronPython, for example:

 

il_api_eg_csharp.png

il_api_eg_vbscript.png

il_api_eg_ironpython.png

The above example connects to an IMG file and retrieves a table that contains image data. The file format can be ERDAS IMG, ENVI IMG, IDRISI IMG or any other supported technology that matches the filename.

 

To create a script:

 

 

Running a script:

 

 

Languages

Manifold allows scripting in eleven different scripting languages by supporting them for use within Script windows.  Six scripting  languages are always available for use in every Manifold installation without requiring any additional installation of any kind, either because they are built in to Manifold (Javascript) or because they are automatically available as a result of Microsoft facilities that are required for any Manifold installation.

 

Two additional languages, IronPython and IronRuby, are automatically supported by the Command Window when they are installed.   Five more languages, F#, PerlScript and PythonScript, are supported when they are installed.  

 

Always available languages:

 

 

JavaScript using the Google V8 engine is built into Manifold and is the recommended default.  The other always available languages are provide by Microsoft COM/.NET, which are required for Manifold installation.

 

Additional languages built into the Command Window:

 

 

IronPython and IronRuby are supported by the Command Window just like the built in JavaScript engine, but they are not part of  Manifold installations.   IronPython and IronRuby are installed separately.  

 

Additional Supported Languages:

 

 

Manifold understands and supports the above languages for scripting using script components.

 

Default Scripts

Following are examples of the default "Hello, World!" scripts which are created when we create a new script using the various languages used by Manifold.   The default scripts write the "Hello, World!" text to a log window that is automatically opened when the script is executed.  In addition to illustrations the code is included below as text to enable copy and pasting from this documentation.

C#

il_script_csharp.png

Code:

 

// C#

 

class Script

{

 

static Manifold.Context Manifold;

static void Main()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

}

 

F#

il_script_fsharp.png

Code:

 

// F#

//

// Note: running script requires F# and F# PowerPack (FSharp.Compiler.CodeDom.dll)

 

module Script

    let mutable Manifold: Manifold.Context = null

    let Main() =

        Manifold.Application.Log("Hello, World!")

        Manifold.Application.OpenLog()

 

IronPython

il_script_ironpython.png

Code:

 

# IronPython

#

# Note: running script requires IronPython (IronPython.dll)

 

def Main():

Manifold.Application.Log("Hello, World!")

Manifold.Application.OpenLog()

 

IronRuby

il_script_ironruby.png

Code:

 

# IronRuby

#

# Note: running script requires IronRuby (IronRuby.dll)

 

def Main()

manifold.application.log('Hello, World!')

manifold.application.open_log()

end

 

JavaScript

il_script_javascript.png

Code:

 

// JavaScript

 

var Main = function()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

JScript

il_script_jscript.png

Code:

 

// JScript

 

var Main = function()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

JScript.NET

il_script_jscriptnet.png

Code:

 

// JScript.NET

 

class Script

{

 

static var Manifold: Manifold.Context;

static function Main()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

}

 

PerlScript

il_script_perlscript.png

Code:

 

# PerlScript

#

# Note: running script requires ActivePerl

 

sub Main

{

$Manifold->Application->Log("Hello, World!");

$Manifold->Application->OpenLog();

}

 

PythonScript

il_script_pythonscript.png

Code:

 

# PythonScript

#

# Note: running script requires ActivePython

 

def Main():

Manifold.Application.Log("Hello, World!")

Manifold.Application.OpenLog()

 

VB.NET

il_script_vbnet.png

Code:

 

' VB.NET

 

Class Script

 

Shared Manifold As Manifold.Context

Shared Sub Main()

Manifold.Application.Log("Hello, World!")

Manifold.Application.OpenLog()

End Sub

 

End Class

 

VBScript

il_script_vbscript.png

Code:

 

' VBScript

 

Sub Main

Manifold.Application.Log "Hello, World!"

Manifold.Application.OpenLog

End Sub

 

 

Notes

Agnosticism - Manifold is completely agnostic about programming languages, as can be seen by the wide range of languages which are directly supported for scripting in Manifold.  JavaScript is built in for convenience and to leverage the ubiquity achieved by JavaScript as a result of Internet.  The V8 engine was selected as a high quality and fast JavaScript engine that is compatible with Manifold parallelism and which would fit within an .msi installation.    The Manifold Command Window by default supports both IronPython and IronRuby to provide stylish alternatives to JavaScript.  C#, JScript, JScript.NET, VB.NET and VBScript are supported and are always available because of the Microsoft infrastructure required for a Manifold installation.   Manifold also supports F#, PerlScript and PythonScript, which are easy to install if desired.

 

See Also

Command Window

 

Example: Run JavaScript in the Command Window - How to run a simple V8 JavaScript script in the Command window.