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.
39 lines
1.1 KiB
39 lines
1.1 KiB
name: duk_to_buffer
|
|
|
|
proto: |
|
|
void *duk_to_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size);
|
|
|
|
stack: |
|
|
[ ... val! ... ] -> [ ... buffer(val)! ... ]
|
|
|
|
summary: |
|
|
<p>Replace the value at <code>idx</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>idx</code> is invalid, throws an error.</p>
|
|
|
|
<p>Coercion rules:</p>
|
|
<ul>
|
|
<li>Buffer: no change, dynamic/fixed/external 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;
|
|
duk_size_t sz;
|
|
|
|
ptr = duk_to_buffer(ctx, -3, &sz);
|
|
printf("coerced data at %p, size %lu\n", ptr, (unsigned long) sz);
|
|
|
|
tags:
|
|
- stack
|
|
- buffer
|
|
|
|
seealso:
|
|
- duk_to_fixed_buffer
|
|
- duk_to_dynamic_buffer
|
|
|
|
introduced: 1.0.0
|
|
|