Jason Orendorff pointed out
https://wiki.mozilla.org/Jsctypes/api#User-defined_types
from the "ctypes" (libffi) bindings for SpiderMonkey docs. Excerpt
below. Ctypes is overkill (and unsafe to boot!) but the ability to
generate array and struct types is pretty much what I've been sketching.
/be
....
new ctypes.ArrayType(t, n) - Return the array type t[n]. If t is not a
type or t.size is undefined or n is not a size value (defined below),
throw a TypeError. If the size of the resulting array type, in bytes,
would not be exactly representable both as a size_t and as a
JavaScript number, throw a RangeError.
A size value is either a non-negative, integer-valued primitive
number, an Int64 object with a non-negative value, or a UInt64 object.
(Array types with 0 elements are allowed. Rationale: C/C++ allow them,
and it is convenient to be able to pass an array to a foreign
function, and have it autoconverted to a C array, without worrying
about the special case where the array is empty.)
new ctypes.StructType(name, fields) - Create a new struct type with
the given name and fields. fields is an array of field descriptors, of
the format
[ { field1: type1 }, { field2: type2 }, ... ]
where fieldn is a string denoting the name of the field, and typen is
a ctypes type. js-ctypes calculates the offsets of the fields from its
encyclopedic knowledge of the architecture's struct layout rules. If
name is not a string, or any typen is such that typen.size is
undefined, throw a TypeError. If the size of the struct, in bytes,
would not be exactly representable both as a size_t and as a
JavaScript number, throw a RangeError.
(Open issue: Specify a way to tell ctypes.StructType to use #pragma
pack(n).)
These constructors behave exactly the same way when called without the
new keyword.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss