MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaO_pushvfstring

Function luaO_pushvfstring

freebsd/contrib/openzfs/module/lua/lobject.c:174–225  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

172
173/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
174const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
175 int n = 0;
176 for (;;) {
177 const char *e = strchr(fmt, '%');
178 if (e == NULL) break;
179 luaD_checkstack(L, 2); /* fmt + item */
180 pushstr(L, fmt, e - fmt);
181 switch (*(e+1)) {
182 case 's': {
183 const char *s = va_arg(argp, char *);
184 if (s == NULL) s = "(null)";
185 pushstr(L, s, strlen(s));
186 break;
187 }
188 case 'c': {
189 char buff;
190 buff = cast(char, va_arg(argp, int));
191 pushstr(L, &buff, 1);
192 break;
193 }
194 case 'd': {
195 setnvalue(L->top++, cast_num(va_arg(argp, int)));
196 break;
197 }
198 case 'f': {
199 setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
200 break;
201 }
202 case 'p': {
203 char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
204 int l = lcompat_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
205 pushstr(L, buff, l);
206 break;
207 }
208 case '%': {
209 pushstr(L, "%", 1);
210 break;
211 }
212 default: {
213 luaG_runerror(L,
214 "invalid option " LUA_QL("%%%c") " to " LUA_QL("lua_pushfstring"),
215 *(e + 1));
216 }
217 }
218 n += 2;
219 fmt = e+2;
220 }
221 luaD_checkstack(L, 1);
222 pushstr(L, fmt, strlen(fmt));
223 if (n > 0) luaV_concat(L, n + 1);
224 return svalue(L->top - 1);
225}
226
227
228const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {

Callers 4

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

Calls 5

strchrFunction · 0.85
lcompat_sprintfFunction · 0.85
pushstrFunction · 0.70
luaG_runerrorFunction · 0.70
luaV_concatFunction · 0.70

Tested by

no test coverage detected