A data type is defined by instances of union type_info, which is
declared in include/common.h and has the following fields (total size
is 8 bytes):
- genus
- The only field that is always available; it specifies what
type the type has, and as that sounds somewhat convoluted, I chose the
name "genus" for this field. Following values are possible:
- GENUS_NON_NATIVE (0) - this entry refers to a type defined in another
module.
- GENUS_STRUCTURE (1) - a composite type, i.e. struct or union.
- GENUS_FUNCTION (2) - a function pointer; a location of the function's
signature is provided.
- GENUS_FUNDAMENTAL (3) - a fundamental type (other than function) which
is handled directly by ffi2lua_xxx or lua2ffi_xxx functions.
- fundamental_idx
- Index into the module's own array of fundamental
types (i.e., fundamental_hash), where the entries are just 32 bit hash values
of the type name, like "signed char*" or "long unsigned int". When a module
is loaded, the conversion table module.fundamental_map is created
that gives the core module's fundamental_idx, i.e. the index into the core
module's ffi_type_map.
- is_const
- Set if this type is a "const" type, i.e. points to an
immutable memory area; this is only useful for pointers.
- is_native
- If zero, this entry refers to a data type in another
module; only the name_hash field is used in this case. If one,
this is a regular type entry; and if two, it's a fundamental data type and
isn't added to gnome.typemap (Note: might be changed soon as of
2008-08-20)
- indirections
- Specifies how many "*" to place after the type's
name, for example, this is 0 for "char" and 1 for "char*". This is sometimes
less than the corresponding fundamental type has, because the plain type name
may already be a pointer, e.g. "GdkAtom".
- is_array
- If set, then this type is a one- or twodimensional
array. This is very rare and so an extra array is used to specify the
dimensions for such types (see struct array_info and
module.array_list).
- name_ofs
- Offset into the big name string where the name of this
type is stored. Using an offset instead of a pointer has advantages: the
size of the offset is less than a full pointer, and no relocation needs to
be done when the module shared object is loaded.
- for structures
- If the fundamental type specifies a structure,
following fields are filled: struct_size, elem_start, elem_count,
which detail the structure and refer to the module.elem_list.
- for functions
- If the fundamental type is a function, an offset
into the function prototypes in provided. The information contained there
is identical to the data in the function hash table.
- for non-native types
- The hash value of the
type's name is stored; it is used to look up the type in the table
gnome.typemap as described in the section about Type Hashing. Additionally, either the
name of the module known to contain that type is given, or the type's name.
This allows to automatically load the correct module, or to display a
sensible error message.