Skip to content

How does emscripten_console_xxx work? #21783

Closed Answered by sbc100
msqr1 asked this question in Q&A
Apr 18, 2024 · 5 comments · 7 replies
Discussion options

You must be logged in to vote

The formatting is done to a string, rather than to stdout (using sprintf). The result of the formatting is that sent directly to JS:

static void vlogf(const char* fmt, va_list ap, void (*callback)(const char*)) {
va_list ap2;
va_copy(ap2, ap);
size_t len = vsnprintf(0, 0, fmt, ap2);
va_end(ap2);
char* buf = alloca(len + 1);
vsnprintf(buf, len + 1, fmt, ap);
callback(buf);
}
void emscripten_console_logf(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
vlogf(fmt, ap, &emscripten_console_log);
va_end(ap);
}

If you want ev…

Replies: 5 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by msqr1
Comment options

You must be logged in to vote
7 replies
@sbc100
Comment options

@sbc100
Comment options

@msqr1
Comment options

@sbc100
Comment options

@msqr1
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants