diff --git a/doc/binding.xml b/doc/binding.xml index 1215134f..68419e52 100644 --- a/doc/binding.xml +++ b/doc/binding.xml @@ -16,7 +16,7 @@ This chapter runs through the four main styles that have been found to work well. If you want to write a new binding, one of these should be close to what you need. - +
Don’t bind the top-level C API The libvips C API (vips_add() and so on) is very inconvenient and dangerous to use from other languages due to its heavy use of varargs. @@ -79,7 +79,7 @@ main( int argc, char **argv ) /* Call the operation. This will look up the operation+args in the vips * operation cache and either return a previous operation, or build - * this one. In either case, we have a new ref we mst release. + * this one. In either case, we have a new ref we must release. */ if( !(new_op = vips_cache_operation_build( op )) ) { g_object_unref( op ); @@ -112,13 +112,13 @@ main( int argc, char **argv ) } - libvips has a couple of extra things to let you examine the arguments and types of an operator at runtime. Use vips_lib.vips_argument_map() to loop over all the arguments of an operator, and vips_object_get_argument() to fetch the type and flags of a specific argument. + libvips has a couple of extra things to let you examine the arguments and types of an operator at runtime. Use vips_argument_map() to loop over all the arguments of an operator, and vips_object_get_argument() to fetch the type and flags of a specific argument. Use vips_operation_get_flags() to get general information about an operator. - - +
+
Compiled language which can call C The C++ binding uses this lower layer to define a function called VImage::call() which can call any libvips operator with a not-varargs set of variable arguments. @@ -144,23 +144,23 @@ VImage VImage::invert( VOption *options ) The VImage class also adds automatic reference counting, constant expansion, operator overloads, and various other useful features. - - +
+
Dynamic language with FFI - Languages like Ruby, Python, JavaScript and Lua can’t call C directly, but they do support FFI. The bindings for these languages work rather like C++, but use FFI to call into libvips and run operations. + Languages like Ruby, Python, JavaScript and LuaJIT can’t call C directly, but they do support FFI. The bindings for these languages work rather like C++, but use FFI to call into libvips and run operations. Since these languages are dynamic, they can add another trick: they intercept the method-missing hook and attempt to run any method calls not implemented by the Image class as libvips operators. This makes these bindings self-writing: they only contain a small amount of code and just expose everything they find in the libvips class hierarchy. - - +
+
Dynamic langauge without FFI PHP does not have FFI, unfortunately, so for this language a small native module implements the general vips_call() function for PHP language types, and a larger pure PHP layer makes it convenient to use. - - +
+
gobject-introspection The C source code to libvips has been marked up with special comments describing the interface in a standard way. These comments are read by the gobject-introspection package when libvips is compiled and used to generate a typelib, a description of how to call the library. Many languages have gobject-introspection packages: all you need to do to call libvips from your favorite language is to start g-o-i, load the libvips typelib, and you should have the whole library available. For example, from Python it’s as simple as: @@ -177,8 +177,8 @@ from gi.repository import Vips If you have a choice, I would recommend simply using FFI. - - +
+
Documentation You can generate searchable docs from a .gir (the thing that is built from scanning libvips and which in turn turn the typelib is made from) with g-ir-doc-tool, for example: @@ -202,7 +202,7 @@ $ yelp-build html . To make HTML docs. This is an easy way to see what you can call in the library. - +