MCPcopy Create free account
hub / github.com/Tencent/xLua / luaO_pushvfstring

Function luaO_pushvfstring

WebGLPlugins/lobject.c:400–464  ·  view source on GitHub ↗

** this function handles only '%d', '%c', '%f', '%p', and '%s' conventional formats, plus Lua-specific '%I' and '%U' */

Source from the content-addressed store, hash-verified

398 conventional formats, plus Lua-specific '%I' and '%U'
399*/
400const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
401 int n = 0;
402 for (;;) {
403 const char *e = strchr(fmt, '%');
404 if (e == NULL) break;
405 pushstr(L, fmt, e - fmt);
406 switch (*(e+1)) {
407 case 's': { /* zero-terminated string */
408 const char *s = va_arg(argp, char *);
409 if (s == NULL) s = "(null)";
410 pushstr(L, s, strlen(s));
411 break;
412 }
413 case 'c': { /* an 'int' as a character */
414 char buff = cast(char, va_arg(argp, int));
415 if (lisprint(cast_uchar(buff)))
416 pushstr(L, &buff, 1);
417 else /* non-printable character; print its code */
418 luaO_pushfstring(L, "<\\%d>", cast_uchar(buff));
419 break;
420 }
421 case 'd': { /* an 'int' */
422 setivalue(L->top, va_arg(argp, int));
423 goto top2str;
424 }
425 case 'I': { /* a 'lua_Integer' */
426 setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));
427 goto top2str;
428 }
429 case 'f': { /* a 'lua_Number' */
430 setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
431 top2str: /* convert the top element to a string */
432 luaD_inctop(L);
433 luaO_tostring(L, L->top - 1);
434 break;
435 }
436 case 'p': { /* a pointer */
437 char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */
438 int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
439 pushstr(L, buff, l);
440 break;
441 }
442 case 'U': { /* an 'int' as a UTF-8 sequence */
443 char buff[UTF8BUFFSZ];
444 int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));
445 pushstr(L, buff + UTF8BUFFSZ - l, l);
446 break;
447 }
448 case '%': {
449 pushstr(L, "%", 1);
450 break;
451 }
452 default: {
453 luaG_runerror(L, "invalid option '%%%c' to 'lua_pushfstring'",
454 *(e + 1));
455 }
456 }
457 n += 2;

Callers 4

luaO_pushfstringFunction · 0.85
luaG_runerrorFunction · 0.85
lua_pushvfstringFunction · 0.85
lua_pushfstringFunction · 0.85

Calls 7

pushstrFunction · 0.85
luaO_pushfstringFunction · 0.85
luaD_inctopFunction · 0.85
luaO_tostringFunction · 0.85
luaO_utf8escFunction · 0.85
luaG_runerrorFunction · 0.85
luaV_concatFunction · 0.85

Tested by

no test coverage detected