1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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/trunk@32981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2011-08-15 23:48:59 +00:00
parent 8977d3e30c
commit 87ff4b24ae
8 changed files with 208 additions and 1 deletions

View file

@ -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: */