MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaO_pushvfstring

Function luaO_pushvfstring

depends/lua/src/lobject.c:400–465  ·  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 void *p = va_arg(argp, void *);
439 int l = lua_pointer2str(buff, sizeof(buff), p);
440 pushstr(L, buff, l);
441 break;
442 }
443 case 'U': { /* an 'int' as a UTF-8 sequence */
444 char buff[UTF8BUFFSZ];
445 int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));
446 pushstr(L, buff + UTF8BUFFSZ - l, l);
447 break;
448 }
449 case '%': {
450 pushstr(L, "%", 1);
451 break;
452 }
453 default: {
454 luaG_runerror(L, "invalid option '%%%c' to 'lua_pushfstring'",
455 *(e + 1));
456 }
457 }

Callers 4

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

Calls 8

pushstrFunction · 0.85
castFunction · 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