MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / luaO_pushvfstring

Function luaO_pushvfstring

other_src/lua/src/lobject.cpp:111–170  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

109
110/* this function handles only `%d', `%i', `%c', `%f', `%p', and `%s' formats */
111const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
112 int n = 1;
113 pushstr(L, "");
114 for (;;) {
115 const char *e = strchr(fmt, '%');
116 if (e == NULL) break;
117 setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
118 incr_top(L);
119 switch (*(e+1)) {
120 case 's': {
121 const char *s = va_arg(argp, char *);
122 if (s == NULL) s = "(null)";
123 pushstr(L, s);
124 break;
125 }
126 case 'c': {
127 char buff[2];
128 buff[0] = cast(char, va_arg(argp, int));
129 buff[1] = '\0';
130 pushstr(L, buff);
131 break;
132 }
133 case 'i':
134 case 'd': {
135 setnvalue(L->top, cast_num(va_arg(argp, int)));
136 incr_top(L);
137 break;
138 }
139 case 'f': {
140 setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
141 incr_top(L);
142 break;
143 }
144 case 'p': {
145 char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
146 sprintf(buff, "%p", va_arg(argp, void *));
147 pushstr(L, buff);
148 break;
149 }
150 case '%': {
151 pushstr(L, "%");
152 break;
153 }
154 default: {
155 char buff[3];
156 buff[0] = '%';
157 buff[1] = *(e+1);
158 buff[2] = '\0';
159 pushstr(L, buff);
160 break;
161 }
162 }
163 n += 2;
164 fmt = e+2;
165 }
166 pushstr(L, fmt);
167 luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
168 L->top -= n;

Callers 4

luaG_runerrorFunction · 0.70
luaO_pushfstringFunction · 0.70
lua_pushvfstringFunction · 0.70
lua_pushfstringFunction · 0.70

Calls 3

pushstrFunction · 0.70
luaS_newlstrFunction · 0.70
luaV_concatFunction · 0.70

Tested by

no test coverage detected