name: duk_opt_buffer proto: | void *duk_opt_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len); stack: | [ ... val! ... ] summary: |

Get the data pointer for a (plain) buffer value at idx without modifying or coercing the value. Returns a non-NULL pointer if the value is a valid buffer with a non-zero size. For a zero-size buffer, may return a NULL or a non-NULL pointer. If out_size is non-NULL, the size of the buffer is written to *out_size. If the value is undefined or the index is invalid, def_ptr default value is returned and the def_len default length is written to *out_size (if out_size is non-NULL). In other cases (null and non-matching type) throws an error.

example: | void *ptr; duk_size_t sz; char buf[256]; /* Use a buffer given at index 2, or default to 'buf'. */ ptr = duk_opt_buffer(ctx, 2, &sz, (void *) buf, sizeof(buf)); printf("buf=%p, size=%lu\n", ptr, (unsigned long) sz); tags: - stack - buffer seealso: - duk_opt_buffer_data introduced: 2.1.0