mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Correct.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
66484faf1b
commit
cb944528b6
1 changed files with 8 additions and 8 deletions
|
@ -17,8 +17,8 @@ and LoadLibrary() on Windows.
|
||||||
|
|
||||||
= Using Ruby/DL
|
= Using Ruby/DL
|
||||||
|
|
||||||
We should usually use DL::Importable module provided by dl/import.rb.
|
We should usually use DL::Importable module provided by "dl/import.rb".
|
||||||
It has high-level functions to access to library functions. We use
|
It has high-level functions to access library functions. We use
|
||||||
DL::Importable module to extend a module as follows:
|
DL::Importable module to extend a module as follows:
|
||||||
|
|
||||||
require "dl/import"
|
require "dl/import"
|
||||||
|
@ -26,22 +26,22 @@ DL::Importable module to extend a module as follows:
|
||||||
extend DL::Importable
|
extend DL::Importable
|
||||||
end
|
end
|
||||||
|
|
||||||
Now we can use methods dlload() and extern() in this module. We load the
|
Now we can use methods dlload and extern in this module. We load the
|
||||||
libraries using dlload(), and define wrapper methods to library functions
|
libraries using dlload, and define wrapper methods to library functions
|
||||||
using extern() respectively as follows:
|
using extern respectively as follows:
|
||||||
|
|
||||||
module LIBC
|
module LIBC
|
||||||
extend DL::Importable
|
extend DL::Importable
|
||||||
dlload "libc.so.6","libm.so.6"
|
dlload "libc.so.6","libm.so.6"
|
||||||
extern "int strlen(char*)"
|
extern "int strlen(char*)"
|
||||||
end
|
end
|
||||||
|
# Note that we should not include the module LIBC from some reason.
|
||||||
|
|
||||||
Note that we should not include the module LIBC from some reason.
|
We can call the library function strlen() using LIBC.strlen. If the first
|
||||||
We can call the library function strlen() using LIBC.strlen(). If the first
|
|
||||||
character of given function name is an uppercase, the first character of the
|
character of given function name is an uppercase, the first character of the
|
||||||
defined method name becomes lowercase.
|
defined method name becomes lowercase.
|
||||||
We can also construct memory images of structures and unions using functions
|
We can also construct memory images of structures and unions using functions
|
||||||
struct and union which are defined in dl/struct.rb as follows:
|
struct and union which are defined in "dl/struct.rb" as follows:
|
||||||
|
|
||||||
require "dl/import"
|
require "dl/import"
|
||||||
require "dl/struct"
|
require "dl/struct"
|
||||||
|
|
Loading…
Add table
Reference in a new issue