Jsctypes/api: Difference between revisions

Jump to navigation Jump to search
→‎Examples: copyediting
(→‎Examples: copyediting)
Line 525: Line 525:
This allocates a new C++ object of type <code>int32_t</code> (4 bytes of memory), zeroes it out, and returns a JS object that manages the allocated memory. Whenever the JS object is garbage-collected, the allocated memory will be automatically freed.
This allocates a new C++ object of type <code>int32_t</code> (4 bytes of memory), zeroes it out, and returns a JS object that manages the allocated memory. Whenever the JS object is garbage-collected, the allocated memory will be automatically freed.


(Of course you don't normally need to do this, as js-ctypes will autoconvert JS numbers to various C/C++ types for you.)
Of course you don't normally need to do this, as js-ctypes will autoconvert JS numbers to various C/C++ types for you:


  let myfunc = mylib.declare("myfunc", ctypes.default_abi,
  let myfunc = mylib.declare("myfunc", ctypes.default_abi,
Line 535: Line 535:
<code>ctypes.int32_t</code> is a <code>CType</code>. Like all other CTypes, it can be used for type specification when passed as an object, as above. (This will work for user-defined <code>CTypes</code> such as structs and pointers also - see later.)
<code>ctypes.int32_t</code> is a <code>CType</code>. Like all other CTypes, it can be used for type specification when passed as an object, as above. (This will work for user-defined <code>CTypes</code> such as structs and pointers also - see later.)


This kind of object is called a <code>CData</code> object, and they are described in detail in the "<code>CData</code> objects" section above.
The object created by <code>new ctypes.int32_t</code> is called a <code>CData</code> object, and they are described in detail in the "<code>CData</code> objects" section above.


Opaque pointers:
Opaque pointers:
638

edits

Navigation menu