diff options
-rw-r--r-- | manual.tex | 21 | ||||
-rw-r--r-- | strlib.c | 26 |
2 files changed, 31 insertions, 16 deletions
@@ -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, | |||
826 | but also its arguments, its results and the default behavior. | 826 | but also its arguments, its results and the default behavior. |
827 | Please notice that the code shown here is only illustrative; | 827 | Please notice that the code shown here is only illustrative; |
828 | the real behavior is hard coded in the interpreter, | 828 | the real behavior is hard coded in the interpreter, |
829 | and it is much more efficient than this simulation. | 829 | and it is much more efficient than this simulation. |
830 | All functions used in these descriptions | 830 | All functions used in these descriptions |
831 | (\verb|rawgetglobal|, \verb|tonumber|, \verb|call|, etc) | 831 | (\verb|rawgetglobal|, \verb|tonumber|, \verb|call|, etc) |
832 | are described in \See{predefined}. | 832 | are 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} |
996 | called whenever Lua assigns to a global variable. | 996 | called whenever Lua assigns to a global variable. |
997 | This method cannot be set for numbers, strings, and tables and | 997 | This method cannot be set for numbers, strings, and tables and |
998 | userdata with default tags. | 998 | userdata 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, | |||
1280 | and pops it. | 1280 | and pops it. |
1281 | 1281 | ||
1282 | As a general rule, all API functions pop from the stack | 1282 | As a general rule, all API functions pop from the stack |
1283 | all elements that they use. | 1283 | all elements that they use. |
1284 | 1284 | ||
1285 | Because userdata are objects, | 1285 | Because userdata are objects, |
1286 | the function \verb|lua_pushusertag| may create a new userdata. | 1286 | the 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 | ||
1888 | Conversions can be applied to the n-th argument in the argument list, | ||
1889 | rather than the next unused argument. | ||
1890 | In this case, the conversion character \verb|%| is replaced | ||
1891 | by the sequence \verb|%d$|, where \verb|d| is a | ||
1892 | decimal digit in the range [1,9], | ||
1893 | giving the position of the argument in the argument list. | ||
1894 | For instance, the call \verb|format("%2$d -> %1$03d", 1, 34)| will | ||
1895 | result in \verb|"34 -> 001"|. | ||
1896 | |||
1888 | The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|, | 1897 | The 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 |
1890 | expect a number as argument, | 1899 | expect a number as argument, |
@@ -3,7 +3,7 @@ | |||
3 | ** String library to LUA | 3 | ** String library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_strlib="$Id: strlib.c,v 1.45 1997/06/19 17:45:28 roberto Exp roberto $"; | 6 | char *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) | |||
468 | static void str_format (void) | 468 | static 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'"); |