aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-12-14 09:53:27 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-12-14 09:53:27 -0200
commit2d1d57bc18c18b06f4f81b9a8ec9e5cd8f915450 (patch)
treed9a1aa611634ba5a38fae9d971b3039b044f4491 /lobject.c
parent03412af06e7d2f6c09125c54d3d3dc442aabdddb (diff)
downloadlua-2d1d57bc18c18b06f4f81b9a8ec9e5cd8f915450.tar.gz
lua-2d1d57bc18c18b06f4f81b9a8ec9e5cd8f915450.tar.bz2
lua-2d1d57bc18c18b06f4f81b9a8ec9e5cd8f915450.zip
comments
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/lobject.c b/lobject.c
index 93dba050..ca299f92 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.107 2015/11/02 14:02:35 roberto Exp roberto $ 2** $Id: lobject.c,v 2.108 2015/11/02 16:09:30 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -351,8 +351,10 @@ static void pushstr (lua_State *L, const char *str, size_t l) {
351} 351}
352 352
353 353
354/* this function handles only '%d', '%c', '%f', '%p', and '%s' 354/*
355 conventional formats, plus Lua-specific '%I' and '%U' */ 355** this function handles only '%d', '%c', '%f', '%p', and '%s'
356 conventional formats, plus Lua-specific '%I' and '%U'
357*/
356const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { 358const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
357 int n = 0; 359 int n = 0;
358 for (;;) { 360 for (;;) {
@@ -360,13 +362,13 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
360 if (e == NULL) break; 362 if (e == NULL) break;
361 pushstr(L, fmt, e - fmt); 363 pushstr(L, fmt, e - fmt);
362 switch (*(e+1)) { 364 switch (*(e+1)) {
363 case 's': { 365 case 's': { /* zero-terminated string */
364 const char *s = va_arg(argp, char *); 366 const char *s = va_arg(argp, char *);
365 if (s == NULL) s = "(null)"; 367 if (s == NULL) s = "(null)";
366 pushstr(L, s, strlen(s)); 368 pushstr(L, s, strlen(s));
367 break; 369 break;
368 } 370 }
369 case 'c': { 371 case 'c': { /* an 'int' as a character */
370 char buff = cast(char, va_arg(argp, int)); 372 char buff = cast(char, va_arg(argp, int));
371 if (lisprint(cast_uchar(buff))) 373 if (lisprint(cast_uchar(buff)))
372 pushstr(L, &buff, 1); 374 pushstr(L, &buff, 1);
@@ -374,28 +376,28 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
374 luaO_pushfstring(L, "<\\%d>", cast_uchar(buff)); 376 luaO_pushfstring(L, "<\\%d>", cast_uchar(buff));
375 break; 377 break;
376 } 378 }
377 case 'd': { 379 case 'd': { /* an 'int' */
378 setivalue(L->top, va_arg(argp, int)); 380 setivalue(L->top, va_arg(argp, int));
379 goto top2str; 381 goto top2str;
380 } 382 }
381 case 'I': { 383 case 'I': { /* a 'lua_Integer' */
382 setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt))); 384 setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));
383 goto top2str; 385 goto top2str;
384 } 386 }
385 case 'f': { 387 case 'f': { /* a 'lua_Number' */
386 setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); 388 setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
387 top2str: 389 top2str: /* convert the top element to a string */
388 luaD_inctop(L); 390 luaD_inctop(L);
389 luaO_tostring(L, L->top - 1); 391 luaO_tostring(L, L->top - 1);
390 break; 392 break;
391 } 393 }
392 case 'p': { 394 case 'p': { /* a pointer */
393 char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */ 395 char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */
394 int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *)); 396 int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
395 pushstr(L, buff, l); 397 pushstr(L, buff, l);
396 break; 398 break;
397 } 399 }
398 case 'U': { 400 case 'U': { /* an 'int' as a UTF-8 sequence */
399 char buff[UTF8BUFFSZ]; 401 char buff[UTF8BUFFSZ];
400 int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long))); 402 int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));
401 pushstr(L, buff + UTF8BUFFSZ - l, l); 403 pushstr(L, buff + UTF8BUFFSZ - l, l);