mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 06:56:13 +02:00
* backport r32981 and r32982 from trunk.
* ext/dl: Add documentation. Patch by Vincent Batts. [Ruby 1.9 - Bug #5192] * ext/.document (fiddle): Remove duplicate entry * ext/fiddle: Complete documentation of Fiddle. Patch by Vincent Batts. [#5192] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d42e5dcfce
commit
c33343b964
15 changed files with 606 additions and 8 deletions
|
@ -138,17 +138,80 @@ function_call(int argc, VALUE argv[], VALUE self)
|
|||
void
|
||||
Init_fiddle_function(void)
|
||||
{
|
||||
/*
|
||||
* Document-class: Fiddle::Function
|
||||
*
|
||||
* == Description
|
||||
*
|
||||
* A representation of a C function
|
||||
*
|
||||
* == Examples
|
||||
*
|
||||
* === 'strcpy'
|
||||
*
|
||||
* @libc = DL.dlopen "/lib/libc.so.6"
|
||||
* => #<DL::Handle:0x00000001d7a8d8>
|
||||
* f = Fiddle::Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
|
||||
* => #<Fiddle::Function:0x00000001d8ee00>
|
||||
* buff = "000"
|
||||
* => "000"
|
||||
* str = f.call(buff, "123")
|
||||
* => #<DL::CPtr:0x00000001d0c380 ptr=0x000000018a21b8 size=0 free=0x00000000000000>
|
||||
* str.to_s
|
||||
* => "123"
|
||||
*
|
||||
* === ABI check
|
||||
*
|
||||
* @libc = DL.dlopen "/lib/libc.so.6"
|
||||
* => #<DL::Handle:0x00000001d7a8d8>
|
||||
* f = Fiddle::Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
|
||||
* => #<Fiddle::Function:0x00000001d8ee00>
|
||||
* f.abi == Fiddle::Function::DEFAULT
|
||||
* => true
|
||||
*/
|
||||
cFiddleFunction = rb_define_class_under(mFiddle, "Function", rb_cObject);
|
||||
|
||||
/*
|
||||
* Document-const: DEFAULT
|
||||
*
|
||||
* Default ABI
|
||||
*
|
||||
*/
|
||||
rb_define_const(cFiddleFunction, "DEFAULT", INT2NUM(FFI_DEFAULT_ABI));
|
||||
|
||||
#ifdef FFI_STDCALL
|
||||
/*
|
||||
* Document-const: STDCALL
|
||||
*
|
||||
* FFI implementation of WIN32 stdcall convention
|
||||
*
|
||||
*/
|
||||
rb_define_const(cFiddleFunction, "STDCALL", INT2NUM(FFI_STDCALL));
|
||||
#endif
|
||||
|
||||
rb_define_alloc_func(cFiddleFunction, allocate);
|
||||
|
||||
/*
|
||||
* Document-method: call
|
||||
*
|
||||
* Calls the constructed Function, with +args+
|
||||
*
|
||||
* For an example see Fiddle::Function
|
||||
*
|
||||
*/
|
||||
rb_define_method(cFiddleFunction, "call", function_call, -1);
|
||||
|
||||
/*
|
||||
* Document-method: new
|
||||
* call-seq: new(ptr, *args, ret_type, abi = DEFAULT)
|
||||
*
|
||||
* Constructs a Function object.
|
||||
* * +ptr+ is a referenced function, of a DL::Handle
|
||||
* * +args+ is an Array of arguments, passed to the +ptr+ function
|
||||
* * +ret_type+ is the return type of the function
|
||||
* * +abi+ is the ABI of the function
|
||||
*
|
||||
*/
|
||||
rb_define_method(cFiddleFunction, "initialize", initialize, -1);
|
||||
}
|
||||
/* vim: set noet sws=4 sw=4: */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue