From 72b3fff72f6bb9cf5796bbcd50e9a490d4e02b4b Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sun, 23 Jan 2011 14:23:21 +0100
Subject: FFI: Simplify initializer rules. Clarify docs.
---
doc/ext_ffi_semantics.html | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
(limited to 'doc/ext_ffi_semantics.html')
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html
index 598d44c9..4a1b6c11 100644
--- a/doc/ext_ffi_semantics.html
+++ b/doc/ext_ffi_semantics.html
@@ -70,6 +70,47 @@ TODO
TODO
+Initializers
+
+Creating a cdata object with ffi.new()
+or the equivalent constructor syntax always initializes its contents,
+too. Different rules apply, depending on the number of optional
+initializers and the C types involved:
+
+
+- If no initializers are given, the object is filled with zero bytes.
+
+- Scalar types (numbers and pointers) accept a single initializer.
+The standard C type conversion rules
+apply.
+
+- Valarrays (complex numbers and vectors) are treated like scalars
+when a single initializer is given. Otherwise they are treated like
+regular arrays.
+
+- Aggregate types (arrays and structs) accept either a single
+compound initializer (Lua table or string) or a flat list of
+initializers.
+
+- The elements of an array are initialized, starting at index zero.
+If a single initializer is given for an array, it's repeated for all
+remaining elements. This doesn't happen if two or more initializers
+are given: all remaining uninitialized elements are filled with zero
+bytes.
+
+- The fields of a struct are initialized in the order of
+their declaration. Uninitialized fields are filled with zero
+bytes.
+
+- Only the first field of a union can be initialized with a
+flat initializer.
+
+- Elements or fields which are aggregates themselves are initialized
+with a single initializer, but this may be a compound
+initializer or a compatible aggregate, of course.
+
+
+
C Library Namespaces
A C library namespace is a special kind of object which allows
--
cgit v1.2.3-55-g6feb