summaryrefslogtreecommitdiff
path: root/ext/fiddle/function.c
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-15 23:48:59 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-15 23:48:59 +0000
commit87ff4b24ae4911bda46a5426024959c278da69b2 (patch)
tree4598a48b30055b1824cadc12354c3d4e259a07f8 /ext/fiddle/function.c
parent8977d3e30c225ba17e6ed542875b320d3d8bd3e1 (diff)
* 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
Diffstat (limited to 'ext/fiddle/function.c')
-rw-r--r--ext/fiddle/function.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c
index 911c9b80fc..6e8909991a 100644
--- a/ext/fiddle/function.c
+++ b/ext/fiddle/function.c
@@ -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: */