Jump to content

mruby

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 84.113.183.242 (talk) at 15:25, 16 July 2014 (Features). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


mruby
Developer(s)Yukihiro Matsumoto et al.
Stable release
1.0.0 / February 9, 2014 (2014-02-09)
Repository
Written inC and Ruby
Operating systemCross-platform
TypeRuby programming language interpreter
LicenseMIT License
Websitemruby.org

mruby is an interpreter for the Ruby programming language with the intention of being lightweight and easily embeddable.[1][2] The project is headed by Yukihiro Matsumoto, with over 100 contributors currently working on the project.

Features

mruby 1.0 supports the Ruby 2.1 core API but none of the standard library. As well as being able to execute most basic Ruby code, mruby also features a bytecode compiler and virtual machine, as well as the ability to be easily embedded and integrated into C or C++ code.

mruby also aims to be compliant with the ISO/IEC 30170:2012 standard.[1]

Examples

Calling mruby from C

#include <stdio.h>
#include <mruby.h>
#include <mruby/compile.h>

int main(int argc, char **argv) {
    mrb_state *mrb = mrb_open();
    char code[] = "5.times { puts 'mruby is awesome!' }";

    printf("Executing Ruby code with mruby:\n");
    mrb_load_string(mrb, code);

    mrb_close(mrb);
    return 0;
}

Assuming that you have mruby installed, the following program can be compiled and executed by running the following command from your terminal:[3]

$ cc example.c -lmruby -lm -o example
$ ./example

Precompiled Bytecode

mruby includes a minimalistic virtual machine used to execute mruby bytecode, nicknamed ritevm:

$ mrbc test.rb
$ mruby -b test.mrb

The first command compiles Ruby code to mruby bytecode, creating a file called "test.mrb", which can then be executed by appending the "-b" flag to the normal interpreter arguments.[4]

References

  1. ^ a b "mruby/mruby". GitHub. Retrieved 2013-12-29.
  2. ^ mruby and MobiRuby announced
  3. ^ Aimonetti, Matt (2012-04-25). "Getting started with mruby". Retrieved 2013-12-29.
  4. ^ geekmonkey (2012-10-30). "An introduction to Mini Ruby". Retrieved 2013-12-29.