diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-07 14:26:48 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-07 14:26:48 -0200 |
commit | 26679b1a48de4f7cfcde985764cb31c78ece4fc3 (patch) | |
tree | df30c6972204791dd6a792dd36c1dd132bc5dbf4 /manual.tex | |
parent | e04c2b9aa817ed59b4e05025e0d33bfb3bba8f59 (diff) | |
download | lua-26679b1a48de4f7cfcde985764cb31c78ece4fc3.tar.gz lua-26679b1a48de4f7cfcde985764cb31c78ece4fc3.tar.bz2 lua-26679b1a48de4f7cfcde985764cb31c78ece4fc3.zip |
back to upavalues as extra arguments for C closures; this way it's
trivial to make currying.
Diffstat (limited to 'manual.tex')
-rw-r--r-- | manual.tex | 30 |
1 files changed, 14 insertions, 16 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 1.1 1998/01/02 18:34:00 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.2 1998/01/06 19:17:31 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: 1998/01/02 18:34:00 $} | 41 | \date{\small \verb$Date: 1998/01/06 19:17:31 $} |
42 | 42 | ||
43 | \maketitle | 43 | \maketitle |
44 | 44 | ||
@@ -1647,7 +1647,8 @@ many results. | |||
1647 | 1647 | ||
1648 | When a C function is created, | 1648 | When a C function is created, |
1649 | it is possible to associate some \emph{upvalues} to it; | 1649 | it is possible to associate some \emph{upvalues} to it; |
1650 | then these values can be accessed by the function whenever it is called. | 1650 | then these values are passed to the function whenever it is called, |
1651 | as common arguments. | ||
1651 | To associate upvalues to a function, | 1652 | To associate upvalues to a function, |
1652 | first these values must be pushed on C2lua. | 1653 | first these values must be pushed on C2lua. |
1653 | Then the function: | 1654 | Then the function: |
@@ -1660,14 +1661,11 @@ with the argument \verb|n| telling how many upvalues must be | |||
1660 | associated with the function | 1661 | associated with the function |
1661 | (notice that the macro \verb|lua_pushcfunction| is defined as | 1662 | (notice that the macro \verb|lua_pushcfunction| is defined as |
1662 | \verb|lua_pushCclosure| with \verb|n| set to 0). | 1663 | \verb|lua_pushCclosure| with \verb|n| set to 0). |
1663 | Any time the function \verb|fn| is called, | 1664 | Then, any time the function is called, |
1664 | it can access those upvalues using: | 1665 | these upvalues are inserted as the first arguments to the function, |
1665 | \Deffunc{lua_upvalue} | 1666 | before the actual arguments provided in the call. |
1666 | \begin{verbatim} | ||
1667 | lua_Object lua_upvalue (int n); | ||
1668 | \end{verbatim} | ||
1669 | 1667 | ||
1670 | For some examples, see files \verb|lstrlib.c|, | 1668 | For some examples of C functions, see files \verb|lstrlib.c|, |
1671 | \verb|liolib.c| and \verb|lmathlib.c| in Lua distribution. | 1669 | \verb|liolib.c| and \verb|lmathlib.c| in Lua distribution. |
1672 | 1670 | ||
1673 | \subsection{References to Lua Objects} | 1671 | \subsection{References to Lua Objects} |
@@ -2080,7 +2078,7 @@ If \verb|i| is absent, then it is assumed to be 1. | |||
2080 | 2078 | ||
2081 | \subsubsection*{\ff \T{format (formatstring, e1, e2, \ldots)}}\Deffunc{format} | 2079 | \subsubsection*{\ff \T{format (formatstring, e1, e2, \ldots)}}\Deffunc{format} |
2082 | \label{format} | 2080 | \label{format} |
2083 | This function returns a formated version of its variable number of arguments | 2081 | This function returns a formatted version of its variable number of arguments |
2084 | following the description given in its first argument (which must be a string). | 2082 | following the description given in its first argument (which must be a string). |
2085 | The format string follows the same rules as the \verb|printf| family of | 2083 | The format string follows the same rules as the \verb|printf| family of |
2086 | standard C functions. | 2084 | standard C functions. |
@@ -2112,7 +2110,7 @@ decimal digit in the range [1,9], | |||
2112 | giving the position of the argument in the argument list. | 2110 | giving the position of the argument in the argument list. |
2113 | For instance, the call \verb|format("%2$d -> %1$03d", 1, 34)| will | 2111 | For instance, the call \verb|format("%2$d -> %1$03d", 1, 34)| will |
2114 | result in \verb|"34 -> 001"|. | 2112 | result in \verb|"34 -> 001"|. |
2115 | The same argument can be used in more than one convertion. | 2113 | The same argument can be used in more than one conversion. |
2116 | 2114 | ||
2117 | The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|, | 2115 | The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|, |
2118 | \verb|g|, \verb|G|, \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all | 2116 | \verb|g|, \verb|G|, \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all |
@@ -2506,7 +2504,7 @@ It returns an error code, which is system-dependent. | |||
2506 | \subsubsection*{\ff \T{setlocale (locale [, category])}}\Deffunc{setlocale} | 2504 | \subsubsection*{\ff \T{setlocale (locale [, category])}}\Deffunc{setlocale} |
2507 | 2505 | ||
2508 | This function is an interface to the ANSI C function \verb|setlocale|. | 2506 | This function is an interface to the ANSI C function \verb|setlocale|. |
2509 | \verb|locale| is a string specifing a locale; | 2507 | \verb|locale| is a string specifying a locale; |
2510 | \verb|category| is a number describing which category to change: | 2508 | \verb|category| is a number describing which category to change: |
2511 | 0 is \verb|LC_ALL|, 1 is \verb|LC_COLLATE|, 2 is \verb|LC_CTYPE|, | 2509 | 0 is \verb|LC_ALL|, 1 is \verb|LC_COLLATE|, 2 is \verb|LC_CTYPE|, |
2512 | 3 is \verb|LC_MONETARY|, 4 is \verb|LC_NUMERIC|, and 5 is \verb|LC_TIME|; | 2510 | 3 is \verb|LC_MONETARY|, 4 is \verb|LC_NUMERIC|, and 5 is \verb|LC_TIME|; |
@@ -2659,7 +2657,7 @@ This program can be called with any sequence of the following arguments: | |||
2659 | \item[\T{-e stat}] executes \verb|stat| as a Lua chunk. | 2657 | \item[\T{-e stat}] executes \verb|stat| as a Lua chunk. |
2660 | \item[\T{-i}] runs interactively, | 2658 | \item[\T{-i}] runs interactively, |
2661 | accepting commands from standard input until an \verb|EOF|. | 2659 | accepting commands from standard input until an \verb|EOF|. |
2662 | Each line entered is immediatly executed. | 2660 | Each line entered is immediately executed. |
2663 | \item[\T{-q}] same as \T{-i}, but without a prompt (quiet mode). | 2661 | \item[\T{-q}] same as \T{-i}, but without a prompt (quiet mode). |
2664 | \item[\T{-}] executes \verb|stdin| as a file. | 2662 | \item[\T{-}] executes \verb|stdin| as a file. |
2665 | \item[\T{var=value}] sets global \verb|var| with string \verb|value|. | 2663 | \item[\T{var=value}] sets global \verb|var| with string \verb|value|. |
@@ -2711,7 +2709,7 @@ Here is a list of all these incompatibilities. | |||
2711 | \begin{itemize} | 2709 | \begin{itemize} |
2712 | 2710 | ||
2713 | \item To support for multiple contexts, | 2711 | \item To support for multiple contexts, |
2714 | the whole library must be explicitly openen before used. | 2712 | the whole library must be explicitly opened before used. |
2715 | However, all standard libraries check whether Lua is already opened, | 2713 | However, all standard libraries check whether Lua is already opened, |
2716 | so any program that opens at least one standard library before using | 2714 | so any program that opens at least one standard library before using |
2717 | Lua API does not need to be corrected. | 2715 | Lua API does not need to be corrected. |
@@ -2727,7 +2725,7 @@ Closures make this feature irrelevant. | |||
2727 | \item The syntax for function declaration is now more restricted; | 2725 | \item The syntax for function declaration is now more restricted; |
2728 | for instance, the old syntax \verb|function f[exp] (x) ... end| is not | 2726 | for instance, the old syntax \verb|function f[exp] (x) ... end| is not |
2729 | accepted in 3.1. | 2727 | accepted in 3.1. |
2730 | Progams should use an explicit assignment instead, like this: | 2728 | Programs should use an explicit assignment instead, like this: |
2731 | \verb|f[exp] = function (x) ... end|. | 2729 | \verb|f[exp] = function (x) ... end|. |
2732 | 2730 | ||
2733 | \item Old pre-compiled code is obsolete, and must be re-compiled. | 2731 | \item Old pre-compiled code is obsolete, and must be re-compiled. |