name: duk_push_string proto: | const char *duk_push_string(duk_context *ctx, const char *str); stack: | [ ... ] -> [ ... str! ] (if str != NULL) [ ... ] -> [ ... null! ] (if str == NULL) summary: |

Push a C string into the stack. String length is automatically detected with a strlen() equivalent (i.e. looking for the first NUL character). A pointer to the interned string data is returned. If the operation fails, throws an error.

If str is NULL, an ECMAScript null is pushed to the stack and NULL is returned. This behavior differs from duk_push_lstring on purpose.

C code should normally only push valid CESU-8 strings to the stack. Some invalid CESU-8/UTF-8 byte sequences are reserved for special uses such as representing Symbol values. When you push such an invalid byte sequence, the value on the value stack will behave like a string for C code but will appear as a Symbol for ECMAScript code. See Symbols for more discussion.

If input string might contain internal NUL characters, use duk_push_lstring() instead.

example: | duk_push_string(ctx, "foo"); duk_push_string(ctx, "foo\0bar"); /* push "foo", not "foo\0bar" */ duk_push_string(ctx, ""); /* push empty string */ duk_push_string(ctx, NULL); /* push 'null' */ tags: - stack - string introduced: 1.0.0