From 0123e4fc895f4a52422dff05a29596e389b4749c Mon Sep 17 00:00:00 2001
From: Mike Pall
⑤ 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. +