mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
963 B
31 lines
963 B
=proto
|
|
void *duk_to_buffer(duk_context *ctx, int index, size_t *out_size);
|
|
|
|
=stack
|
|
[ ... val! ... ] -> [ ... buffer(val)! ... ]
|
|
|
|
=summary
|
|
<p>Replace the value at <code>index</code> with a buffer-coerced value. Returns
|
|
a pointer to the buffer data (may be <code>NULL</code> for a zero-size buffer),
|
|
and writes the size of the buffer into <code>*out_size</code> (if <code>out_size</code>
|
|
is non-<code>NULL</code>). If <code>index</code> is invalid, throws an error.</p>
|
|
|
|
<p>Coercion rules:</p>
|
|
<ul>
|
|
<li>Buffer: no change, dynamic/fixed nature not changed</li>
|
|
<li>String: coerces into a fixed size buffer, byte-for-byte</li>
|
|
<li>Other types: first apply Ecmascript
|
|
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-9.8">ToString()</a>,
|
|
then coerce into a fixed size buffer, byte-for-byte</li>
|
|
</ul>
|
|
|
|
=example
|
|
void *ptr;
|
|
size_t sz;
|
|
|
|
ptr = duk_to_buffer(ctx, -3, &sz);
|
|
printf("coerced data at %p, size %u\n", ptr, (unsigned int) sz);
|
|
|
|
=tags
|
|
stack
|
|
buffer
|
|
|