MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaO_pushvfstring

Function luaO_pushvfstring

Source/Misc/lua/src/lua.c:7371–7429  ·  view source on GitHub ↗

this function handles only `%d', `%c', %f, %p, and `%s' formats */

Source from the content-addressed store, hash-verified

7369
7370/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
7371const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
7372int n = 1;
7373pushstr(L, "");
7374for (;;) {
7375const char *e = strchr(fmt, '%');
7376if (e == NULL) break;
7377setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
7378incr_top(L);
7379switch (*(e+1)) {
7380case 's': {
7381const char *s = va_arg(argp, char *);
7382if (s == NULL) s = "(null)";
7383pushstr(L, s);
7384break;
7385}
7386case 'c': {
7387char buff[2];
7388buff[0] = cast(char, va_arg(argp, int));
7389buff[1] = '\0';
7390pushstr(L, buff);
7391break;
7392}
7393case 'd': {
7394setnvalue(L->top, cast_num(va_arg(argp, int)));
7395incr_top(L);
7396break;
7397}
7398case 'f': {
7399setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
7400incr_top(L);
7401break;
7402}
7403case 'p': {
7404char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
7405sprintf(buff, "%p", va_arg(argp, void *));
7406pushstr(L, buff);
7407break;
7408}
7409case '%': {
7410pushstr(L, "%");
7411break;
7412}
7413default: {
7414char buff[3];
7415buff[0] = '%';
7416buff[1] = *(e+1);
7417buff[2] = '\0';
7418pushstr(L, buff);
7419break;
7420}
7421}
7422n += 2;
7423fmt = e+2;
7424}
7425pushstr(L, fmt);
7426luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
7427L->top -= n;
7428return svalue(L->top - 1);

Callers 4

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

Calls 3

pushstrFunction · 0.85
luaS_newlstrFunction · 0.85
luaV_concatFunction · 0.85

Tested by

no test coverage detected