Home
Explore
Submit Search
Upload
Login
Signup
Advertisement
Check these out next
関数型プログラミングの世界
Kenta Murata
Let's begin Behavior Driven Development using RSpec
Kenta Murata
Rubyをたのしくするために私が考えていること
Kenta Murata
Ruby の懸案事項
Kenta Murata
Rubykaigi2010mrkn bigdecimal
Kenta Murata
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Kenta Murata
Ruby の標準乱数生成器とその改善案
Kenta Murata
5分で分かる Measure
Kenta Murata
1
of
23
Top clipped slide
Ruby 拡張モジュール入門
Nov. 17, 2007
•
0 likes
13 likes
×
Be the first to like this
Show More
•
3,554 views
views
×
Total views
0
On Slideshare
0
From embeds
0
Number of embeds
0
Download Now
Download to read offline
Report
Technology
Ruby の拡張モジュール作成への導入
Kenta Murata
Follow
CRO at Xica Co., Ltd.
Advertisement
Advertisement
Advertisement
Recommended
Web scale backups for MySQL, Алексей Копытов (Percona)
Ontico
1.3K views
•
33 slides
Float is Legacy
Kenta Murata
3.8K views
•
79 slides
校内勉強会のススメ An encouragement to hold workshops In your school
Kenta Murata
1.6K views
•
50 slides
5分弱で分かる量子ビット
Kenta Murata
6.7K views
•
32 slides
Introduction to ATDD with Cucumber and RSpec
Kenta Murata
14.1K views
•
48 slides
The world without the literal notation for floating-point numbers
Kenta Murata
1.2K views
•
38 slides
More Related Content
More from Kenta Murata
(12)
関数型プログラミングの世界
Kenta Murata
•
3.7K views
Let's begin Behavior Driven Development using RSpec
Kenta Murata
•
1.6K views
Rubyをたのしくするために私が考えていること
Kenta Murata
•
1.9K views
Ruby の懸案事項
Kenta Murata
•
2.6K views
Rubykaigi2010mrkn bigdecimal
Kenta Murata
•
1K views
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Kenta Murata
•
800 views
Ruby の標準乱数生成器とその改善案
Kenta Murata
•
4K views
5分で分かる Measure
Kenta Murata
•
1.9K views
Measure 単位付き数値ライブラリ
Kenta Murata
•
1.5K views
情報学特論#02
Kenta Murata
•
876 views
情報学特論#01
Kenta Murata
•
816 views
北海道関数型言語勉強会@札幌#2のお知らせ
Kenta Murata
•
768 views
Recently uploaded
(20)
검증바카라 [WWW.RTЗЗ.TOP]코드:b77 시에라리온 분석 ⑩ psg ㈾ 필리핀온라인카지노 ㊡ 토토사이트메이저 ⑾ 온라인카지노바카라 ...
sangin3
•
7 views
Convert to HTML CSS
Samaritan Technologies
•
1 view
最新1:1仿造梅西大学毕业证文凭
gboth
•
3 views
농구매치결과 〈www,rtЗЗ,top〉코드 b77 울트라프라임 ㈃ 플레이포커 Ⓒ 영국령 인도양 지역 토토 ㈸ 올란드 제도 ㋘ 라미스 ㈔ 리...
sangin3
•
22 views
Sands expo and convention centre Las Vegas, NV USA
Sahajanand Laser Technology Limited
•
3 views
How To Write an Essay On Technology-Based Topics
AffanIT1
•
3 views
无法毕业?美国阿肯色理工大学毕业证书和学位证书办理
sefomo
•
3 views
Encuentra la gama completa en Oasify
Oasify
•
2 views
食べるサイト {ωωω,rtЗЗ,top}コードb77 ギャンブル Å カタル ອ サッカー北米バッティング ➝ イエメンサッカー Ⴄ ブンデスリーガ分析...
ssuser8be025
•
10 views
ホールデムサイト 【www,rt33,top】コードb77 バカラ予測 💨 コモロ ℭ mgmちょっとリアルタイム ๊ エンジエンバカラ ᄎ ビビカジノ ...
ssuser8be025
•
8 views
哪里可以买法国上阿尔萨斯大学毕业证文凭
aswdgyo
•
3 views
Sylviabutler19: I will nft game, blackjack, rummy game, nft game, solana game...
sylviabutler4
•
15 views
最新1:1仿造爱丁堡大学毕业证文凭
gboth
•
3 views
加拿大蒙特埃里森大学毕业证文凭成绩单制作指南
nahej99297
•
3 views
留学美国必看:美国社区大学毕业证、学位证办理流程
oqcymp
•
3 views
스포츠중계 《www,rtЗЗ,top》코드 b77 야추주사위 চ 세계축구중계 🚇 몽골 바카라 ڊ 호텔카지노바카라 ㈺ 봄비토토 👓 야구실시간중계
1xBet 원엑스벳
•
37 views
titanbet {ωωω,rt33,top}코드 b77 애볼루션 ㈩ 말리 분석 ⓙ 모잠비크 국가경기 ⑸ 축구보기 ㈚ 스포츠토토배트맨 ㋞ 네덜...
sangin3
•
3 views
哪里可以买英国威尔士三一圣大卫大学毕业证文凭
aswdgyo
•
4 views
Sylviabutler19: I will build nft game, p2e nft game, metaverse game,3d nft ga...
sylviabutler4
•
8 views
无法毕业?澳大利亚拉筹伯大学毕业证书和学位证书办理
ynexeyb
•
4 views
Advertisement
Ruby 拡張モジュール入門
Ruby
Ruby 拡張モジュール⼊⾨ 拡張モジュール⼊⾨ むらけん 2007-11-17
おしながき
おしながき 拡張モジュールとは なにもしない拡張モジュール hello.so 拡張モジュールを作る前に まとめ 2007-11-17 Ruby 勉強会@札幌 #6 1
拡張モジュールとは
拡張モジュールとは ⽇本語でおk 2 2007-11-17 Ruby 勉強会@札幌 #6
拡張モジュールって何?
拡張モジュールって何? 拡張モジュールとは・・・ Ruby では実現不可能だけど,C ⾔語なら実現可 能な事柄を,C ⾔語で実装して Ruby から使えるよ うにするための共有ライブラリ Ruby で実装すると遅いけど,C ⾔語なら実⽤的な 実⾏速度を実現できるようなアルゴリズムなどを,C ⾔語で実装して Ruby から使えるようにするための 共有ライブラリ アセンブリ⾔語も使えるよ\(^o^)/ 2007-11-17 Ruby 勉強会@札幌 #6 3
拡張モジュールの例
拡張モジュールの例 標準添付 独⽴配布 Ruby/OpenSSL Ruby/GNOME2 Ruby/Win32API RubyCocoa Enumerator Libxml-Ruby iconv Ruby PostgreSQL Ruby/Tk MySQL/Ruby Win32OLE fastthread Ruby/Zlib http11 (mongrel) 2007-11-17 Ruby 勉強会@札幌 #6 4
なにもしない
なにもしない 拡張モジュール 拡張モジュール nothing to do 5 2007-11-17 Ruby 勉強会@札幌 #6
準
備 準 備 3つのファイルを nothing ディレクトリの中に⼊れましょう [nothing.c] [extconf.rb] void require 'mkmf' Init_nothing(void) { create_makefile('nothing') } ~/nothing$ ls [depends] depends extconf.rb nothing.c nothing.o: nothing.c ~/nothing$ 2007-11-17 Ruby 勉強会@札幌 #6 6
コンパイル
コンパイル extconf.rb を実⾏することによって Makefile が作られます. 作成された Makefile を make することでコンパイルします. make の後に⽣成される nothing.so が拡張モジュールです. ~/nothing$ ruby extconf.rb creating Makefile ~/nothing$ ls Makefile depends extconf.rb nothing.c ~/nothing$ make cc -I. -I/usr/lib/ruby/1.8/i486-linux -I/usr/lib/ruby/1.8/i486-linux -I. -fPIC -fno-stric... cc -shared -o nothing.so nothing.o -Lquot;.quot; -Lquot;/usr/libquot; -L. -rdynamic -Wl,-export-dynamic ... ~/nothing$ ls Makefile depends extconf.rb nothing.c nothing.o nothing.so 2007-11-17 Ruby 勉強会@札幌 #6 7
使ってみる
使ってみる 出来上がった nothing.so を Ruby から使うには require 'nothing' を⾏います. ~/nothing$ irb irb(main):001:0> require 'nothing' => true irb(main):002:0> exit ~/nothing$ 2007-11-17 Ruby 勉強会@札幌 #6 8
ここまでのまとめ (1)
ここまでのまとめ (1) 拡張モジュールに必ず必要な関数 void Init_モジュール名(void) { ... } 拡張モジュールがロードされた直後に Ruby インタ プリタがこの関数を呼び出す 本来ならば,この関数の中で拡張モジュールの初 期化処理が⾏われる 2007-11-17 Ruby 勉強会@札幌 #6 9
ここまでのまとめ (2)
ここまでのまとめ (2) Ruby に標準添付されている拡張モジュール 開発環境 extconf.rb の中で mkmf ライブラリを⽤いて, Makefile を作成するための処理を⾏う • とりあえず create_makefile('モジュール名') と書くことで「モジュール名.so」を⽣成するための Makefile が作られる depends ファイルの中に Makefile に書いて欲し い依存関係を記述する 2007-11-17 Ruby 勉強会@札幌 #6 10
hello.so
hello.so そう,こんにちわ 11 2007-11-17 Ruby 勉強会@札幌 #6
hello.c
hello.c [hello.c] [左から続き] #include <ruby.h> void #include <stdio.h> Init_hello(void) { static VALUE VALUE cHello; hello_hello(VALUE self) { printf(quot;[XXX] Init_hello¥nquot;); VALUE str; cHello = rb_define_class( printf(quot;[XXX] hello_hello¥nquot;); quot;Helloquot;, rb_cObject); rb_define_method( str = rb_str_new2(quot;hello, worldquot;); cHello, quot;helloquot;, hello_hello, 0); rb_io_puts(1, &str, rb_stdout); } return self; } 2007-11-17 Ruby 勉強会@札幌 #6 12
コンパイル
コンパイル [extconf.rb] ~/hello$ ls require 'mkmf' depends extconf.rb hello.c ~/hello$ ruby extconf.rb create_makefile('hello') creating Makefile ~/hello$ make cc -I. -I/usr/lib/ruby/1.8/i486-linux - I/usr/lib/ruby/1.8/i486-linux -I. -fPIC - fno-strict-aliasing -g -O2 -fPIC -c [depends] hello.c hello.o: hello.c $(hdrdir)/ruby.h cc -shared -o hello.so hello.o -Lquot;.quot; - Lquot;/usr/libquot; -L. -rdynamic -Wl,-export- dynamic -lruby1.8 -lpthread -ldl - lcrypt -lm -lc ~/hello$ ls depends extconf.rb hello.c hello.o hello.so 2007-11-17 Ruby 勉強会@札幌 #6 13
使ってみる
使ってみる ~/hello$ irb void irb(main):001:0> require 'hello' Init_hello(void) [XXX] Init_hello { => true VALUE cHello; irb(main):002:0> h = Hello.new => #<Hello:0xb7c7e590> printf(quot;[XXX] Init_hello¥nquot;); irb(main):003:0> h.hello ====================================== [XXX] hello_hello static VALUE hello, world hello_hello(VALUE self) => #<Hello:0xb7c7e590> { irb(main):004:0> exit VALUE str; ~/hello$ printf(quot;[XXX] hello_hello¥nquot;); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ return self; } 2007-11-17 Ruby 勉強会@札幌 #6 14
ここまでのまとめ (1)
ここまでのまとめ (1) クラスを定義する rb_define_class(クラス名, 親クラスオブジェクト) クラスにインスタンスメソッドを定義する rb_define_method( クラスオブジェクト, メソッド名, メソッドを実装している関数, 引数の個数) 2007-11-17 Ruby 勉強会@札幌 #6 15
ここまでのまとめ (2)
ここまでのまとめ (2) メソッドの実体となる関数 (hello_hello) 第1仮引数・・・レシーバオブジェクト その他・・・メソッドの引数 Ruby の⽂字列オブジェクトを⽣成する rb_str_new2(C の⽂字列) puts rb_io_puts(1, &⽂字列, rb_stdout) • 本当は rb_io_puts(argc, argv, rb_stdout) で,argv が puts に渡す実引数の C 配列,argc がその⻑さ 2007-11-17 Ruby 勉強会@札幌 #6 16
拡張モジュールを
拡張モジュールを 作る前に 作る前に そんなに難しくないよ 17 2007-11-17 Ruby 勉強会@札幌 #6
おちついて⼀読すべし
おちついて⼀読すべし Ruby には拡張モジュールの作り⽅のドキュメ ントがもれなくついてくる! README.EXT README.EXT.ja 2007-11-17 Ruby 勉強会@札幌 #6 18
拡張モジュールを作るとは
拡張モジュールを作るとは どういうことか? どういうことか? Ruby インタプリタが理解できることば 構⽂⽊ C ⾔語 拡張モジュールを作る = Ruby インタプリタとお喋りする 2007-11-17 Ruby 勉強会@札幌 #6 19
参考になるものたち
参考になるものたち Ruby のソースを読むべし! array.c hash.c object.c string.c よく使うクラスを実装しているコードを読むことで 拡張モジュール作成のための知識を増やそう 2007-11-17 Ruby 勉強会@札幌 #6 20
まとめ
まとめ MA☆TO☆めけーも 21 2007-11-17 Ruby 勉強会@札幌 #6
拡張モジュールを作ろう!
C ⾔語で Ruby とお喋りしよう 2007-11-17 Ruby 勉強会@札幌 #6 22
Advertisement