Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Estendendo Ruby com C
Search
Rodrigo Navarro
April 20, 2012
Programming
94
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Estendendo Ruby com C
Techtalk apresentado na Tagview Tecnologia sobre como criar extensões em C em Ruby.
Rodrigo Navarro
April 20, 2012
More Decks by Rodrigo Navarro
See All by Rodrigo Navarro
DOM
reu
1
220
Processos Unix & Ruby
reu
0
110
Other Decks in Programming
See All in Programming
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
780
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.4k
残高管理から台帳サービスへの進化
artoy
1
200
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.7k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
440
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
620
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
110
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
Featured
See All Featured
Being A Developer After 40
akosma
92
590k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
520
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Mobile First: as difficult as doing things right
swwweet
225
10k
Mind Mapping
helmedeiros
1
400
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.4k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Evolving SEO for Evolving Search Engines
ryanjones
0
330
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Transcript
Estendendo Ruby com C
WHY? 1) Utilizar libs que já existem: • libcurl •
libxml • libssh • libvorbis • ...
WHY? 2) Performance • nokogiri • eventmachine • mongrel2 •
standard_deviation =] • ...
WHY? 3) Comunicação baixo nível • comunicação serial (impressoras) •
RFID • acesso direto a memória • ...?
Easy como tudo em ruby... extconf.rb require("mkmf") create_makefile("hello") hello.c #include
<ruby.h> void Init_hello() { printf("Hello world"); }
Definindo classes #include <ruby.h> void Init_hello() { rb_define_class("Greeter", rb_cObject); }
Definindo classes #include <ruby.h> void Init_hello() { rb_define_class("Greeter", rb_cObject); }
Objetos pre-definidos Classes rb_cArray = rb_define_class("Array", rb_cObject); rb_cBignum = rb_define_class("Bignum",
rb_cInteger); rb_cBasicObject = boot_defclass("BasicObject", 0); rb_cObject = boot_defclass("Object", rb_cBasicObject); rb_cModule = boot_defclass("Module", rb_cObject); rb_cClass = boot_defclass("Class", rb_cModule); rb_cComplex = rb_define_class("Complex", rb_cNumeric); egrep '^ *rb_c.* *=' *
Objetos pre-definidos Módulos rb_mComparable = rb_define_module("Comparable"); rb_mEnumerable = rb_define_module("Enumerable"); b_mErrno
= rb_define_module("Errno"); rb_mFileTest = rb_define_module("FileTest"); egrep '^ *rb_m.* *=' *
Objetos pre-definidos Constantes Qnil Qtrue Qfalse
extconf.rb # Criar um Makefile create_makefile("nome"); # Exigindo um header
raise "some_lib not found, plz install some_lib" unless have_header("some_lib.h") # Exigindo uma lib raise "some_lib not found, plz install some_lib" unless have_library("some_lib.h") # Exigindo uma função have_func("some_function", "some_function/lib.h")
Estrutura de um objeto ruby em C FLAGS "lolwut" RString
FLAGS [1, 2, 3] RArray RValue
Strings char * StringValueCStr(VALUE string) VALUE rb_str_new2("String")
Arrays int RARRAY_LEN(VALUE array) VALUE* RARRAY_PTR(VALUE array) VALUE rb_ary_new2(int size)
rb_ary_store(VALUE array, int index, VALUE value) rb_ary_push(VALUE array, VALUE value)
rb_funcall(VALUE object, VALUE id, arguments_count, arguments...) rb_path2class(char *class_name) rb_intern(char *identifier)
Outras funções
Live coding oh noes...