MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / luaO_pushvfstring

Function luaO_pushvfstring

examples/ThirdPartyLibs/lua-5.2.3/src/lobject.c:200–261  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

198
199/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
200const char *luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)
201{
202 int n = 0;
203 for (;;)
204 {
205 const char *e = strchr(fmt, '%');
206 if (e == NULL) break;
207 luaD_checkstack(L, 2); /* fmt + item */
208 pushstr(L, fmt, e - fmt);
209 switch (*(e + 1))
210 {
211 case 's':
212 {
213 const char *s = va_arg(argp, char *);
214 if (s == NULL) s = "(null)";
215 pushstr(L, s, strlen(s));
216 break;
217 }
218 case 'c':
219 {
220 char buff;
221 buff = cast(char, va_arg(argp, int));
222 pushstr(L, &buff, 1);
223 break;
224 }
225 case 'd':
226 {
227 setnvalue(L->top++, cast_num(va_arg(argp, int)));
228 break;
229 }
230 case 'f':
231 {
232 setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
233 break;
234 }
235 case 'p':
236 {
237 char buff[4 * sizeof(void *) + 8]; /* should be enough space for a `%p' */
238 int l = sprintf(buff, "%p", va_arg(argp, void *));
239 pushstr(L, buff, l);
240 break;
241 }
242 case '%':
243 {
244 pushstr(L, "%", 1);
245 break;
246 }
247 default:
248 {
249 luaG_runerror(L,
250 "invalid option " LUA_QL("%%%c") " to " LUA_QL("lua_pushfstring"),
251 *(e + 1));
252 }
253 }
254 n += 2;
255 fmt = e + 2;
256 }
257 luaD_checkstack(L, 1);

Callers 4

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

Calls 4

pushstrFunction · 0.85
luaG_runerrorFunction · 0.85
luaV_concatFunction · 0.85
castFunction · 0.50

Tested by

no test coverage detected