Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A naïve introduction to mruby
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Jason L Perry
August 21, 2014
Technology
870
3
Share
A naïve introduction to mruby
Slides from a short talk given to the Tampa Ruby Brigade on August 21, 2014.
Jason L Perry
August 21, 2014
More Decks by Jason L Perry
See All by Jason L Perry
Tomorrow's Javascript, Today.
ambethia
0
110
Advanced JS Crash Course
ambethia
1
420
Intro to Javascript
ambethia
1
110
Ruby for the Newbie
ambethia
2
130
Other Decks in Technology
See All in Technology
Python開発環境にハーネス適用を検討する
yuuka51
1
510
AIが変えた"品質の守り方"
kkakizaki
9
2.7k
AI時代から振り返るTerraform drift運用の歴史 / AI Age Reflections on the History of Terraform Drift Operations
aeonpeople
0
360
形式手法特論:公平性制約の位相的特徴づけ #kernelvm / Kernel VM Study Kansai 12th
ytaka23
0
170
最新技術を"今は選ばない"という技術選定
leveragestech
PRO
0
410
まだ道半ば、AI-DLCを歩み始めている話
news_it_enj
2
180
oracle-to-databricks-migration-with-llm-and-dbt
casek
0
120
はじめてのAI-DLC
yoshidashingo
2
530
組織の中で自分を経営する技術
shoota
0
150
GitHub Copilot CLI の Rubber Duck 機能を使ってコーディングの品質をあげよう #techbaton_findy
stefafafan
2
1.1k
Harnessing the Power of Mocks and Stubs in PHPUnit / #laravellivejp
asumikam
0
560
checker.tsにチキンレースを仕掛けてみた:型エラー(TS2589)が発生する境界線を求めて
hal_spidernight
1
200
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
900
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
150
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
270
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
290
sira's awesome portfolio website redesign presentation
elsirapls
0
250
YesSQL, Process and Tooling at Scale
rocio
174
15k
Statistics for Hackers
jakevdp
799
230k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
130
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
450
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
Transcript
mruby A naïve introduction to
Embedded Devices Native Applications Scripting Applications
Know some Ruby Know some C Know Japanese Getting Started
Ask Google: “mruby [ANYTHING]”
< 128kb
None
`require`
stdlib
mrbgems
mruby-array-ext mruby-bin-mirb mruby-bin-mruby-config mruby-bin-mruby mruby-bin-strip mruby-enum-ext mruby-enum-lazy mruby-enumerator mruby-eval mruby-exit
mruby-fiber mruby-hash-ext mruby-kernel-ext mruby-math mruby-numeric-ext mruby-object-ext mruby-objectspace mruby-print mruby-proc-ext mruby-random mruby-range-ext mruby-sprintf mruby-string-ext mruby-string-utf8 mruby-struct mruby-symbol-ext mruby-time mruby-toplevel-ext
MRuby::Build.new do |conf| toolchain :gcc conf.gem :core => 'mruby-bin-mirb' conf.gem
:core => 'mruby-bin-mruby' conf.gem :core => 'mruby-print' conf.gem :core => 'mruby-proc-ext' conf.gem :core => 'mruby-sprintf' conf.gem :core => 'mruby-time' ! conf.gem :git => 'https://github.com/iij/mruby-io.git' conf.gem :git => 'https://github.com/iij/mruby-mtest.git' conf.gem :git => 'https://github.com/iij/mruby-socket.git' end build_config.rb
Many Ways
Interpreted $ mruby hello_world.rb Hello, World. ! $ mruby -e
“Hello, World!” Hello, World.
Interactive Shell (mirb) $ mirb mirb - Embeddable Interactive Ruby
Shell ! > puts "Hello, World!" Hello, World! => nil
Bytecode (*.mrb) $ mrbc hello_world.rb $ cat -v hello_world.mrb RITE0002&?
^@^@^@gMATZ0000IREP^@^@^@I0000^@^@^@=^@^A^@^D^@ ^@^@^@^@^D^@M-^@^@^F^A^@^@=^@M-^@^@? ^@^@^@J^@^@^@^A^@^@^MHello, World! ^@^@^@^A^@^Dputs^@END^@^@^@^@^H% $ mruby -b hello_world.mrb Hello, World!
Binary C Code $ mrbc -B hello_world_bin hello_world.h $ cat
hello_world.h const char hello_world_bin[] ={ 0x52,0x49,0x54,0x45,0x30,0x30,0x30,0x39,0x30,0x 30,0x30,0x30,0x30,0x30,0x30,0x39,… };
Binary C Code #include <mruby.h>! #include <mruby/irep.h>! ! #include “hello_world.h”!
! int main(void)! {! mrb_state *mrb;! mrb = mrb_open();! mrb_load_irep(mrb, hello_world_bin);! mrb_close(mrb);! return 0;! }
Running Ruby from C // car = Car! // car.run!
struct RClass *Car = mrb_class_get(mrb, "Car");! mrb_value merv = mrb_class_new_instance(mrb, 0, NULL, Car);! mrb_funcall(mrb, car, "run", 0, NULL);!
CODE SPELUNKING github.com/ambethia/merv