summaryrefslogtreecommitdiff
path: root/ext/fiddle/function.c
diff options
context:
space:
mode:
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 911c9b80fc5..6e8909991aa 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: */