Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A naïve introduction to mruby
Search
Jason L Perry
August 21, 2014
Technology
3
840
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
Tweet
Share
More Decks by Jason L Perry
See All by Jason L Perry
Tomorrow's Javascript, Today.
ambethia
0
100
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
生成AI時代におけるグローバル戦略思考
taka_aki
0
190
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
Haskell を武器にして挑む競技プログラミング ─ 操作的思考から意味モデル思考へ
naoya
6
1.5k
IAMユーザーゼロの運用は果たして可能なのか
yama3133
1
380
モダンデータスタック (MDS) の話とデータ分析が起こすビジネス変革
sutotakeshi
0
500
「Managed Instances」と「durable functions」で広がるAWS Lambdaのユースケース
lamaglama39
0
320
AWS Security Agentの紹介/introducing-aws-security-agent
tomoki10
0
270
SREには開発組織全体で向き合う
koh_naga
0
330
AI 駆動開発勉強会 フロントエンド支部 #1 w/あずもば
1ftseabass
PRO
0
380
AIの長期記憶と短期記憶の違いについてAgentCoreを例に深掘ってみた
yakumo
3
340
mairuでつくるクレデンシャルレス開発環境 / Credential-less development environment using Mailru
mirakui
5
520
ChatGPTで論⽂は読めるのか
spatial_ai_network
9
28k
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
How GitHub (no longer) Works
holman
316
140k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Practical Orchestrator
shlominoach
190
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
How STYLIGHT went responsive
nonsquared
100
6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.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