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.
 
 
 
 
 
 

31 lines
1.0 KiB

name: duk_push_sprintf
proto: |
const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...);
stack: |
[ ... ] -> [ ... str! ]
summary: |
<p>Format a string like <code>sprintf()</code> (but safely) and push the result
to the value stack. Returns a non-<code>NULL</code> pointer to the resulting
string.</p>
<p>If <code>fmt</code> is <code>NULL</code>, an empty string is pushed to the stack
and a non-<code>NULL</code> pointer to an empty string is returned (this
behavior mimics what <code>sprintf()</code> does for a <code>NULL</code> format
string, at least on Linux). The returned pointer can be dereferenced and a
NUL terminator character is guaranteed.</p>
<p>Unlike <code>sprintf()</code> the string formatting is safe. Concretely,
the implementation will try increasing temporary buffer sizes until a
large enough buffer is found for the temporary formatted value.</p>
example: |
duk_push_sprintf(ctx, "meaning of life: %d, name: %s", 42, "Zaphod");
tags:
- stack
- string
introduced: 1.0.0