Getting started with mruby (Part 3)

by Yuji Yokoo

In the previous posts, I have got up to the point where I built mruby and ran some ruby code in 6 different ways.

Now let me continue from there and demonstrate some other ways of using mruby.

mruby on MIPS

mruby can be compiled for many platforms. I happen to have a MISP router (D-Link DIR-320) running openwrt. If you want to find out more, see

This should build openwrt and its toolchain. If you are not 100% sure your image is compatible with this version of toolchain, you should install this new image on your router.

Next, you need to build mruby for MIPS. I'll just copy the mruby directory and rename it mruby-mips:

Interesting. Building mruby depends on mrbc! An easy way to work around this is to copy your platform's mrbc to bin:

This should build mruby now. My openwrt (I think openwrt by default) has the ip address of Also, I can run "strip" to make the file smaller. Then I copy the file, ssh into the router, and run the mruby executable like this:


Cross compiling mruby programs for MIPS

You can also cross-compile the mruby-generated C code for MIPS using the openwrt toolchain. I still have the same helloworld.c and helloworld_main.c generated from previous posts:

You can compile these, copy, then run as follows:


Calling mruby from PHP with php-mruby

php-mruby ( lets you embed mruby calls within your PHP scripts:

This should build and install php-mruby. Then make a php file like this:

Now it's time to run the mruby inside php:

Great success! Now you can write mruby inside PHP!

Other interesting things (which I should look at next)

There are lots of interesting things happening with mruby right now. Some examples here:

Update (13/12/2012)

For a list of mruby-related projects, see

Also, it looks like is the correct place instead of "Sinachiku" link above.