Getting Started

Adam Parrott edited this page Jan 5, 2014 · 7 revisions

Installation

JRuby

If you're using JRuby, you can install the latest version of the Mirah gem from the command line:

gem install mirah

Once the gem is installed, test your Mirah installation with a simple "Hello, World!" test by running:

mirah -e 'puts "Hello, Mirah!"'

If successful, you should see Hello, Mirah! in your terminal window.

Maven

If you're using Maven, check out the sample Maven project in the repository for an example of how to integrate Mirah with your Maven environment.

Binary packages

Current and previous binary distributions can be directly downloaded from our Downloads page. Follow the instructions in the enclosed README.txt file for directions on how to install each distribution onto your local machine.

Usage

Basic usage

Similar to Ruby, running programs with Mirah can be easily handled with a single call from the command line. Unlike Ruby, however, Mirah can also compile programs into Java .class files that can then be packaged into a JAR file and consumed by many different JVMs. To handle these two different tasks, the Mirah package contains two executables: mirah for running scripts, and mirahc for compiling scripts.

Run an inline script

Running a quick inline script through the mirah runner is a great way to test pieces of code outside of your normal workflow. In this example, we use the -e command line switch to pass our inline script to Mirah using single quotes:

$ mirah -e 'def result:String; "Hi!"; end; puts result;'
Hi!

Run a saved script

Similarly, running a single script saved to disk through the mirah runner can be easily achieved with a similar command line call. In this example, we create a test script called Test.mirah, save it to disk, and then pass that script name to Mirah for evaluation:

# Test.mirah

def result:String
  "Hi!"
end

puts result
$ mirah Test.mirah
Hi!

Compile an inline script

Compiling a quick inline script through the mirahc compiler works the same way as the mirah runner, only instead of directing it's output to the command line (or stdout), the compiler will direct it's output into a single file called DashE.class. In this example, we use the same -e command line switch to pass our inline script to Mirah using single quotes:

mirahc -e 'def result:String; "Hi!"; end; puts result;'

This should produce a compiled DashE.class in the current directory containing our inline script code.

Compile a saved script

Similar to running a saved script, compiling a single script works with a quick call to the mirahc compiler. In this example, we create a test script called Test.mirah, save it to disk, and then pass that script name to Mirah for compilation:

# Test.mirah

def result:String
  "Hi!"
end

puts result
$ mirahc Test.mirah
Parsing...
  Test.mirah
Inferring types...
Compiling...
  Test.mirah
Done!

This should produce a compiled file named Test.class in the current directory containing our saved script code.

For additional examples of running and compiling programs with Mirah, please check out our Usage page.

Tutorials

Whether you want to start by writing your first Mirah program or you're curious how to code a certain design pattern, be sure to check out our growing compilation of Tutorials for step-by-step recipes that explore various aspects of Mirah in greater detail.

Differences from other languages

If you're coming to Mirah from another programming language, be sure to check out our pages highlighting the differences between Mirah and some of the other popular programming languages:

Command reference

Curious about what data types Mirah supports? Need to see which version of Mirah supports a particular command or feature? Be sure to check out our handy Command Reference page for a summarized listing of all data types, commands, and other language meta data.

Troubleshooting

Need help troubleshooting a strange compiler error or frustrating piece of code? Try these resources first:

  • Visit our Troubleshooting page for a list of the most common Mirah problems and some possible solutions.
  • If that doesn't help, pop over to the Issues tracker and see if your problem has been addressed in a closed issue.
  • If you're still stuck, post your questions to the Mirah mailing list or visit the #mirah IRC channel on Freenode for some live help.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.