MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / luaO_pushvfstring

Function luaO_pushvfstring

extlibs/lua/src/lobject.c:460–527  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

458 conventional formats, plus Lua-specific '%I' and '%U'
459*/
460const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
461 BuffFS buff; /* holds last part of the result */
462 const char *e; /* points to next '%' */
463 buff.pushed = buff.blen = 0;
464 buff.L = L;
465 while ((e = strchr(fmt, '%')) != NULL) {
466 addstr2buff(&buff, fmt, e - fmt); /* add 'fmt' up to '%' */
467 switch (*(e + 1)) { /* conversion specifier */
468 case 's': { /* zero-terminated string */
469 const char *s = va_arg(argp, char *);
470 if (s == NULL) s = "(null)";
471 addstr2buff(&buff, s, strlen(s));
472 break;
473 }
474 case 'c': { /* an 'int' as a character */
475 char c = cast_uchar(va_arg(argp, int));
476 addstr2buff(&buff, &c, sizeof(char));
477 break;
478 }
479 case 'd': { /* an 'int' */
480 TValue num;
481 setivalue(&num, va_arg(argp, int));
482 addnum2buff(&buff, &num);
483 break;
484 }
485 case 'I': { /* a 'lua_Integer' */
486 TValue num;
487 setivalue(&num, cast(lua_Integer, va_arg(argp, l_uacInt)));
488 addnum2buff(&buff, &num);
489 break;
490 }
491 case 'f': { /* a 'lua_Number' */
492 TValue num;
493 setfltvalue(&num, cast_num(va_arg(argp, l_uacNumber)));
494 addnum2buff(&buff, &num);
495 break;
496 }
497 case 'p': { /* a pointer */
498 const int sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */
499 char *bf = getbuff(&buff, sz);
500 void *p = va_arg(argp, void *);
501 int len = lua_pointer2str(bf, sz, p);
502 addsize(&buff, len);
503 break;
504 }
505 case 'U': { /* a 'long' as a UTF-8 sequence */
506 char bf[UTF8BUFFSZ];
507 int len = luaO_utf8esc(bf, va_arg(argp, long));
508 addstr2buff(&buff, bf + UTF8BUFFSZ - len, len);
509 break;
510 }
511 case '%': {
512 addstr2buff(&buff, "%", 1);
513 break;
514 }
515 default: {
516 luaG_runerror(L, "invalid option '%%%c' to 'lua_pushfstring'",
517 *(e + 1));

Callers 4

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

Calls 7

addstr2buffFunction · 0.85
addnum2buffFunction · 0.85
getbuffFunction · 0.85
luaO_utf8escFunction · 0.85
luaG_runerrorFunction · 0.85
clearbuffFunction · 0.85
luaV_concatFunction · 0.85

Tested by

no test coverage detected