|
|
|
=proto
|
|
|
|
void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_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;
|
|
|
|
duk_size_t sz;
|
|
|
|
|
|
|
|
ptr = duk_get_buffer(ctx, &sz);
|
|
|
|
printf("buf=%p, size=%lu\n", ptr, (unsigned long) sz);
|
|
|
|
|
|
|
|
=tags
|
|
|
|
stack
|
|
|
|
buffer
|