aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manual.tex21
-rw-r--r--strlib.c26
2 files changed, 31 insertions, 16 deletions
diff --git a/manual.tex b/manual.tex
index 37b51ba0..19f4e34a 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 2.9 1997/07/01 17:41:34 roberto Exp roberto $ 1% $Id: manual.tex,v 2.10 1997/07/02 17:09:48 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -38,7 +38,7 @@ Waldemar Celes
38\tecgraf\ --- Computer Science Department --- PUC-Rio 38\tecgraf\ --- Computer Science Department --- PUC-Rio
39} 39}
40 40
41\date{\small \verb$Date: 1997/07/01 17:41:34 $} 41\date{\small \verb$Date: 1997/07/02 17:09:48 $}
42 42
43\maketitle 43\maketitle
44 44
@@ -826,8 +826,8 @@ The function not only shows when a tag method is called,
826but also its arguments, its results and the default behavior. 826but also its arguments, its results and the default behavior.
827Please notice that the code shown here is only illustrative; 827Please notice that the code shown here is only illustrative;
828the real behavior is hard coded in the interpreter, 828the real behavior is hard coded in the interpreter,
829and it is much more efficient than this simulation. 829and it is much more efficient than this simulation.
830All functions used in these descriptions 830All functions used in these descriptions
831(\verb|rawgetglobal|, \verb|tonumber|, \verb|call|, etc) 831(\verb|rawgetglobal|, \verb|tonumber|, \verb|call|, etc)
832are described in \See{predefined}. 832are described in \See{predefined}.
833 833
@@ -994,7 +994,7 @@ Notice: the function \verb|getglobal| is pre-defined in Lua \see{predefined}.
994 994
995\item[``setglobal'':]\index{setglobal event} 995\item[``setglobal'':]\index{setglobal event}
996called whenever Lua assigns to a global variable. 996called whenever Lua assigns to a global variable.
997This method cannot be set for numbers, strings, and tables and 997This method cannot be set for numbers, strings, and tables and
998userdata with default tags. 998userdata with default tags.
999\begin{verbatim} 999\begin{verbatim}
1000 function setglobal (varname, newvalue) 1000 function setglobal (varname, newvalue)
@@ -1280,7 +1280,7 @@ returns a reference to the object at the top of the C2lua stack,
1280and pops it. 1280and pops it.
1281 1281
1282As a general rule, all API functions pop from the stack 1282As a general rule, all API functions pop from the stack
1283all elements that they use. 1283all elements that they use.
1284 1284
1285Because userdata are objects, 1285Because userdata are objects,
1286the function \verb|lua_pushusertag| may create a new userdata. 1286the function \verb|lua_pushusertag| may create a new userdata.
@@ -1885,6 +1885,15 @@ will produce the string:
1885 new line" 1885 new line"
1886\end{verbatim} 1886\end{verbatim}
1887 1887
1888Conversions can be applied to the n-th argument in the argument list,
1889rather than the next unused argument.
1890In this case, the conversion character \verb|%| is replaced
1891by the sequence \verb|%d$|, where \verb|d| is a
1892decimal digit in the range [1,9],
1893giving the position of the argument in the argument list.
1894For instance, the call \verb|format("%2$d -> %1$03d", 1, 34)| will
1895result in \verb|"34 -> 001"|.
1896
1888The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|, 1897The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|,
1889\verb|g| \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all 1898\verb|g| \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all
1890expect a number as argument, 1899expect a number as argument,
diff --git a/strlib.c b/strlib.c
index b576b265..6d16043a 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.45 1997/06/19 17:45:28 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.46 1997/06/19 18:49:40 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -468,7 +468,7 @@ void luaI_addquoted (char *s)
468static void str_format (void) 468static void str_format (void)
469{ 469{
470 int arg = 1; 470 int arg = 1;
471 char *strfrmt = luaL_check_string(arg++); 471 char *strfrmt = luaL_check_string(arg);
472 luaI_emptybuff(); /* initialize */ 472 luaI_emptybuff(); /* initialize */
473 while (*strfrmt) { 473 while (*strfrmt) {
474 if (*strfrmt != '%') 474 if (*strfrmt != '%')
@@ -478,29 +478,35 @@ static void str_format (void)
478 else { /* format item */ 478 else { /* format item */
479 char form[MAX_FORMAT]; /* store the format ('%...') */ 479 char form[MAX_FORMAT]; /* store the format ('%...') */
480 char *buff; 480 char *buff;
481 char *initf = strfrmt-1; /* -1 to include % */ 481 char *initf = strfrmt;
482 strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0); 482 form[0] = '%';
483 strfrmt = match(strfrmt, "%d?%$?[-+ #]*(%d*)%.?(%d*)", 0);
483 if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */ 484 if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */
484 lua_error("invalid format (width or precision too long)"); 485 lua_error("invalid format (width or precision too long)");
485 strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */ 486 if (isdigit((unsigned char)initf[0]) && initf[1] == '$') {
486 form[strfrmt-initf+1] = 0; 487 arg = initf[0] - '0';
488 initf += 2; /* skip the 'n$' */
489 }
490 arg++;
491 strncpy(form+1, initf, strfrmt-initf+1); /* +1 to include convertion */
492 form[strfrmt-initf+2] = 0;
487 buff = openspace(1000); /* to store the formated value */ 493 buff = openspace(1000); /* to store the formated value */
488 switch (*strfrmt++) { 494 switch (*strfrmt++) {
489 case 'q': 495 case 'q':
490 luaI_addquoted(luaL_check_string(arg++)); 496 luaI_addquoted(luaL_check_string(arg));
491 continue; 497 continue;
492 case 's': { 498 case 's': {
493 char *s = luaL_check_string(arg++); 499 char *s = luaL_check_string(arg);
494 buff = openspace(strlen(s)); 500 buff = openspace(strlen(s));
495 sprintf(buff, form, s); 501 sprintf(buff, form, s);
496 break; 502 break;
497 } 503 }
498 case 'c': case 'd': case 'i': case 'o': 504 case 'c': case 'd': case 'i': case 'o':
499 case 'u': case 'x': case 'X': 505 case 'u': case 'x': case 'X':
500 sprintf(buff, form, (int)luaL_check_number(arg++)); 506 sprintf(buff, form, (int)luaL_check_number(arg));
501 break; 507 break;
502 case 'e': case 'E': case 'f': case 'g': 508 case 'e': case 'E': case 'f': case 'g':
503 sprintf(buff, form, luaL_check_number(arg++)); 509 sprintf(buff, form, luaL_check_number(arg));
504 break; 510 break;
505 default: /* also treat cases 'pnLlh' */ 511 default: /* also treat cases 'pnLlh' */
506 lua_error("invalid format option in function `format'"); 512 lua_error("invalid format option in function `format'");