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.
38 lines
1.2 KiB
38 lines
1.2 KiB
name: duk_get_lstring
|
|
|
|
proto: |
|
|
const char *duk_get_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
|
|
|
|
stack: |
|
|
[ ... val! ... ]
|
|
|
|
summary: |
|
|
<p>Get character data pointer and length for a string at <code>idx</code>
|
|
without modifying or coercing the value. Returns a non-<code>NULL</code>
|
|
pointer to the read-only, NUL-terminated string data, and writes the
|
|
string byte length to <code>*out_len</code> (if <code>out_len</code> is
|
|
non-<code>NULL</code>). Returns <code>NULL</code> and writes zero to <code>*out_len</code>
|
|
(if <code>out_len</code> is non-<code>NULL</code>) if the value is not a string or
|
|
the index is invalid.</p>
|
|
|
|
<p>To get the string character length (instead of byte length), use
|
|
<code><a href="#duk_get_length">duk_get_length()</a></code>.</p>
|
|
|
|
<div class="note">
|
|
A non-<code>NULL</code> return value is guaranteed even for zero length strings;
|
|
this differs from how buffer data pointers are handled (for technical reasons).
|
|
</div>
|
|
|
|
example: |
|
|
const char *buf;
|
|
duk_size_t len;
|
|
|
|
buf = duk_get_lstring(ctx, -3, &len);
|
|
if (buf) {
|
|
printf("value is a string, %lu bytes\n", (unsigned long) len);
|
|
}
|
|
|
|
tags:
|
|
- stack
|
|
|
|
introduced: 1.0.0
|
|
|