diff --git a/doc/ext_ffi_tutorial.html b/doc/ext_ffi_tutorial.html index 9349aea4..fb46a842 100644 --- a/doc/ext_ffi_tutorial.html +++ b/doc/ext_ffi_tutorial.html @@ -15,6 +15,7 @@ span.mark { color: #4040c0; font-family: Courier New, Courier, monospace; pre.mark { padding-left: 2em; } table.idiomtable { line-height: 1.2; } table.idiomtable tt { font-size: 100%; } +table.idiomtable td { vertical-align: top; } tr.idiomhead td { font-weight: bold; } td.idiomc { width: 12em; } td.idiomlua { width: 14em; } @@ -454,7 +455,7 @@ the origin. If we run out of operators, we can define named methods, too. Here the __index table defines an area function. For custom indexing needs, one might want to -define __index and __newindex functions instead. +define __index and __newindex functions instead.

This associates the metamethods with @@ -478,6 +479,24 @@ defined metamethods. Note that area is a method and must be called with the Lua syntax for methods: a:area(), not a.area().

+

+The C type metamethod mechanism is most useful when used in +conjunction with C libraries that are written in an object-oriented +style. Creators return a pointer to a new instance and methods take an +instance pointer as the first argument. Sometimes you can just point +__index to the library namespace and __gc to the +destructor and you're done. But often enough you'll want to add +convenience wrappers, e.g. to return actual Lua strings or when +returning multiple values. +

+

+Some C libraries only declare instance pointers as an opaque +void * type. In this case you can use a fake type for all +declarations, e.g. a pointer to a named (incomplete) struct will do: +typedef struct foo_type *foo_handle. The C side doesn't +know what you declare with the LuaJIT FFI, but as long as the underlying +types are compatible, everything still works. +

Translating C Idioms