20
Mruby & Me Seb Jacobs Monday, 11 February 13

Mruby & Me

Embed Size (px)

DESCRIPTION

An introduction to mruby http://skillsmatter.com/podcast/home/mruby

Citation preview

Page 1: Mruby & Me

Mruby & MeSeb Jacobs

Monday, 11 February 13

Page 2: Mruby & Me

Matz’s Dream

flickr/moofbong

Ruby for everyone, everywhere!

Monday, 11 February 13

Page 3: Mruby & Me

So many rubies?JRuby, Rubinius, Topaz, ...

why do we need another one?

Monday, 11 February 13

Page 4: Mruby & Me

What is mruby?lightweight ISO-compliant ruby

small memory footprintruby for embedded systems

Monday, 11 February 13

Page 5: Mruby & Me

mruby is the samebut different

• compile mruby to bytecode

• modular library system

• no regexps by default

• no standard library

• no require!

Monday, 11 February 13

Page 6: Mruby & Me

Hello bytecode

$ mruby -e 'puts "hello lrug";' --verbose

000 OP_LOADSELF!R1

001 OP_STRING! R2!"hello lrug"

002 OP_SEND! R1!:puts! 1

003 OP_STOP

Monday, 11 February 13

Page 7: Mruby & Me

C calling Ruby#include <mruby.h>#include <mruby/compile.h>

int main(void){ mrb_state *mrb = mrb_open(); char code[] = "p 'hello world!'"; printf("Executing Ruby code from C!\n");

mrb_load_string(mrb, code); return 0;}

https://github.com/mruby/mruby/wiki/Hello-World

Monday, 11 February 13

Page 8: Mruby & Me

Use it with your favourite language!

Ruby in LuaRuby in PHP

Ruby in Node.js!

Monday, 11 February 13

Page 9: Mruby & Me

php-mruby$mrb = new Mruby();$mrb->assign('$myname','sebjacobs');$mrb->run('puts $myname');

https://github.com/chobie/php-mruby

Monday, 11 February 13

Page 10: Mruby & Me

Embedded Ruby!Ruby in your fridgeRuby on your TVRuby on Wheels!

Monday, 11 February 13

Page 11: Mruby & Me

Build mobile apps withMobiruby or Jamruby

Monday, 11 February 13

Page 12: Mruby & Me

mod_mruby

r = Apache::Request.new()

Apache.rputs("redirecting request!")

r.filename = "/var/www/html/redirect.html"

Apache::return(Apache::OK)

https://github.com/matsumoto-r/mod_mruby

Monday, 11 February 13

Page 13: Mruby & Me

WebRubyhttps://qiezi.me/projects/webruby-tutorial/

Monday, 11 February 13

Page 14: Mruby & Me

MTestclass Test4MTest < MTest::Unit::TestCase

def test_assert_empty assert_empty([], 'array empty') end

def test_assert_equal assert_equal('', nil.to_s) end

def test_assert_includes assert_includes([1,2,3], 1) end

def test_assert_instance_of assert_instance_of Class, Array endend

MTest::Unit.new.run

https://github.com/iij/mruby-mtest

Monday, 11 February 13

Page 15: Mruby & Me

Get involved!

Monday, 11 February 13

Page 16: Mruby & Me

Module#constants

assert('Module#constants', '15.2.2.4.24') do! module Test4constants !! Const4Test4constant = 24! end

! module Test4constants2 !! include Test4constants !! Const4Test4constant2 = 42! end

! Test4constants.constants == [:Const4Test4constant]

! Test4constants2.constants == [:Const4Test4constant2]end

Monday, 11 February 13

Page 17: Mruby & Me

Module#constants

mrb_valuemrb_mod_constants(mrb_state *mrb, mrb_value mod){! mrb_value ary;! ary = mrb_ary_new(mrb);! if (obj_iv_p(mod) && mrb_obj_ptr(mod)->iv) ! { iv_foreach(mrb, mrb_obj_ptr(mod)->iv, const_i, &ary);! }! return ary;}

Monday, 11 February 13

Page 18: Mruby & Me

The future?mruby-ruby

Monday, 11 February 13

Page 19: Mruby & Me

Check out

• github.com/mruby/mruby

• mruby.sh

• github.com/iij/mruby

Monday, 11 February 13

Page 20: Mruby & Me

I’m @sebjacobsany questions?

Monday, 11 February 13