mruby
DeveloperYukihiro Matsumoto et al.
Initial releaseApril 20, 2012; 14 years ago (2012-04-20)
Stable release
4.0.0[1] Edit this on Wikidata / 20 April 2026; 56 days ago (20 April 2026)
Written inC and Ruby
Operating systemCross-platform
StandardISO/IEC 30170:2012
TypeRuby programming language interpreter
LicenseMIT License[2]
Websitemruby.org Edit this at Wikidata
Repository

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

Features

edit

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, in a similar manner to Lua or Tcl.

mruby 2.0.0[5] adds support for several Ruby 2.x methods beyond Ruby 2.1. v2.0.0 also changed to variable length bytecode instructions format.

mruby bytecode can be embedded in C code, and thus, can be compiled into a standalone executable.[6]

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

Examples

edit

Calling mruby from C

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

int main(void) {
    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 the mruby library and headers are installed, the program can be compiled and executed by running the following commands from the terminal:[8]

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

Precompiled Bytecode

edit

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.[9]

References

edit
  1. ^ "Release 4.0.0". 20 April 2026. Retrieved 22 April 2026.
  2. ^ "LICENSE". Github. Retrieved 6 September 2019.
  3. ^ a b "mruby/mruby". GitHub. Retrieved 2018-04-30.
  4. ^ "mruby and mobiruby". matt.aimonetti.net. 2012-04-20. Retrieved 2026-06-11.
  5. ^ "mruby 2.0.0 released". mruby.org. Retrieved 2019-04-01.
  6. ^ "Executing Ruby code with mruby". mruby.org. Retrieved 2019-04-01.
  7. ^ "ISO/IEC 30170:2012". ISO. Retrieved 2019-04-01.
  8. ^ Aimonetti, Matt (2012-04-25). "Getting started with mruby". Retrieved 2013-12-29.
  9. ^ geekmonkey (2012-10-30). "An introduction to Mini Ruby". Retrieved 2013-12-29.

📚 Artikel Terkait di Wikipedia

Yukihiro Matsumoto

Retrieved 25 April 2012. "mruby: Lightweight Ruby". 2 November 2017 – via GitHub. Matt Aimonetti (20 April 2012). "mruby and MobiRuby – Matt Aimonetti"

Ruby (programming language)

JRuby, Rubinius, and mruby. Each takes a different approach, with JRuby and Rubinius providing just-in-time compilation and mruby also providing ahead-of-time

Mod ruby

applications running simultaneously). There is also the similar mod_mruby for mruby, a lightweight Ruby implementation. As of at least 2015, the project

ESP32

recommended platform by Espressif Systems, AWS IoT, and Google Cloud IoT. mruby and picoruby for the ESP32 Nim for the ESP32 NodeMCU – Lua-based firmware

WebAssembly

(GHC) backend. Julia: community implementations. Ruby: supported through MRuby. Ring: supported with Wasm backend. Dart: supported WebAssembly as a compiling

Ruby Version Manager

installer for various other implementations of Ruby. These include JRuby, mruby, MacRuby, IronRuby, Maglev, Rubinius, Ruby Enterprise Edition, Topaz, and

List of Ruby software and tools

embeds the Ruby interpreter to improve performance of Ruby web applications Mruby – lightweight Ruby interpreter Rubinius – alternative Ruby implementation

Red fluorescent protein

the mFruits variants (mCherry, mOrange, mRaspberry), mKO, TagRFP, mKate, mRuby, FusionRed, mScarlet and DsRed-Express. In contrast to many engineered monomeric