MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaO_pushvfstring

Function luaO_pushvfstring

third-party/lua-5.2.4/src/lobject.c:179–230  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

pushstrFunction · 0.70
luaG_runerrorFunction · 0.70
luaV_concatFunction · 0.70

Tested by

no test coverage detected