638
edits
(→Properties of types: examples) |
(→CData objects: try to clarify aliasing example) |
||
| Line 302: | Line 302: | ||
''(TODO: Pointer types might need some properties of their own.)'' | ''(TODO: Pointer types might need some properties of their own.)'' | ||
Note that it is possible for several <code>CData</code> objects to refer to the same or overlapping memory. (In this way <code>CData</code> objects are like C++ references.) For example: | |||
const Point = new ctypes.StructType( | const Point = new ctypes.StructType( | ||
| Line 310: | Line 310: | ||
var r = Rect(); // a new CData object of type Rect | var r = Rect(); // a new CData object of type Rect | ||
r.topLeft.x = 100; // This | var p = r.topLeft; // refers to the topLeft member of r, not a copy | ||
r.topLeft.x = 100; // This would not work if `r.topLeft` was a copy! | |||
r.topLeft.x | |||
===> 100 // It works... | |||
p.x // and p refers to the same C/C++ object... | |||
===> 100 // so it sees the change as well. | |||
r.toSource() | r.toSource() | ||
===> "Rect({topLeft: | ===> "Rect({topLeft: {x: 100, y: 0}, bottomRight: {x: 0, y: 0}})" | ||
Minutiae: | Minutiae: | ||
edits