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.
32 lines
1.1 KiB
32 lines
1.1 KiB
=proto
|
|
void *duk_get_buffer(duk_context *ctx, int index, size_t *out_size);
|
|
|
|
=stack
|
|
[ ... val! ... ]
|
|
|
|
=summary
|
|
<p>Get the data pointer for a buffer value at <code>index</code> without modifying
|
|
or coercing the value. Returns a non-<code>NULL</code> pointer if the value is a
|
|
valid buffer (fixed or dynamic) with a non-zero size. For a zero-size buffer,
|
|
may return a <code>NULL</code> or a <code>non-NULL</code> pointer. Returns <code>NULL</code>
|
|
if the value is not a buffer or the index is invalid. If <code>out_size</code> is
|
|
non-<code>NULL</code>, the size of the buffer is written to <code>*out_size</code>; 0
|
|
is written if the return value is <code>NULL</code>.</p>
|
|
|
|
<div class="note">
|
|
There is no reliable way to distinguish a zero-size buffer from a non-buffer
|
|
based on the return values. A <code>NULL</code> with zero size is returned for
|
|
a non-buffer. The same values may be returned for a zero-size buffer (although
|
|
it is also possible that a non-<code>NULL</code> pointer is returned).
|
|
</div>
|
|
|
|
=example
|
|
void *ptr;
|
|
size_t sz;
|
|
|
|
ptr = duk_get_buffer(ctx, &sz);
|
|
printf("buf=%p, size=%d\n", ptr, (int) sz);
|
|
|
|
=tags
|
|
stack
|
|
buffer
|
|
|