diff options
| -rw-r--r-- | manual.tex | 54 |
1 files changed, 46 insertions, 8 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | % $Id: manual.tex,v 1.10 1996/02/12 18:32:09 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.11 1996/02/16 13:12:12 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | \documentstyle[A4,11pt,bnf]{article} | 3 | \documentstyle[A4,11pt,bnf]{article} |
| 4 | 4 | ||
| @@ -34,7 +34,7 @@ Waldemar Celes Filho | |||
| 34 | \tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio | 34 | \tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | \date{\small \verb$Date: 1996/02/12 18:32:09 $} | 37 | \date{\small \verb$Date: 1996/02/16 13:12:12 $} |
| 38 | 38 | ||
| 39 | \maketitle | 39 | \maketitle |
| 40 | 40 | ||
| @@ -1269,12 +1269,19 @@ following the description given in its first argument (which must be a string). | |||
| 1269 | The format string follows the same rules as the \verb'printf' family of | 1269 | The format string follows the same rules as the \verb'printf' family of |
| 1270 | standard C functions. | 1270 | standard C functions. |
| 1271 | The only differencies are that the options/modifiers | 1271 | The only differencies are that the options/modifiers |
| 1272 | \verb'*', \verb'l', \verb'L', \verb'n', \verb'p', | 1272 | \verb'*', \verb'l', \verb'L', \verb'n', \verb'p', |
| 1273 | and \verb'h' are not supported. | 1273 | and \verb'h' are not supported, |
| 1274 | The options \verb'c', \verb'd', \verb'i', \verb'o', \verb'u', | 1274 | and there is an extra option, \verb'q'. |
| 1275 | \verb'x', \verb'X', \verb'e', \verb'E', \verb'f', and \verb'g' all | 1275 | This option formats a string in a form suitable to be safely read |
| 1276 | back by the Lua interpreter. | ||
| 1277 | The string is written between double quotes, | ||
| 1278 | and all double quotes, returns and backslashes in the string | ||
| 1279 | are correctly escaped when written. | ||
| 1280 | |||
| 1281 | The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f', | ||
| 1282 | \verb'g' \verb'i', \verb'o', \verb'u', \verb'X', and \verb'x' all | ||
| 1276 | expect a number argument, | 1283 | expect a number argument, |
| 1277 | while \verb's' expects a string. | 1284 | while \verb'q' and \verb's' expects a string. |
| 1278 | 1285 | ||
| 1279 | 1286 | ||
| 1280 | \subsection{Mathematical Functions} \label{mathlib} | 1287 | \subsection{Mathematical Functions} \label{mathlib} |
| @@ -1360,6 +1367,15 @@ This function returns 2 if the file already exists, | |||
| 1360 | 1367 | ||
| 1361 | This function deletes the file with the given name. | 1368 | This function deletes the file with the given name. |
| 1362 | 1369 | ||
| 1370 | \subsubsection*{{\tt rename (name1, name2)}}\Deffunc{rename} | ||
| 1371 | |||
| 1372 | This function renames file \verb'name1' to \verb'name2'. | ||
| 1373 | |||
| 1374 | \subsubsection*{{\tt tmpname ()}}\Deffunc{tmpname} | ||
| 1375 | |||
| 1376 | This function returns a string with a file name that can safely | ||
| 1377 | be used for a temporary file. | ||
| 1378 | |||
| 1363 | \subsubsection*{{\tt read ([format])}}\Deffunc{read} | 1379 | \subsubsection*{{\tt read ([format])}}\Deffunc{read} |
| 1364 | 1380 | ||
| 1365 | This function returns a value read from the current input. | 1381 | This function returns a value read from the current input. |
| @@ -1698,6 +1714,28 @@ end | |||
| 1698 | \end{verbatim} | 1714 | \end{verbatim} |
| 1699 | 1715 | ||
| 1700 | 1716 | ||
| 1717 | \subsection{\Index{Variable number of arguments}} | ||
| 1718 | Lua does not provide any explicit mechanism to deal with | ||
| 1719 | variable number of arguments. | ||
| 1720 | However, one can use table constructors to simulate this mechanism. | ||
| 1721 | As an example, suppose a function to concatenate all its arguments. | ||
| 1722 | It could be written like | ||
| 1723 | \begin{verbatim} | ||
| 1724 | function concat (o) | ||
| 1725 | local i = 1 | ||
| 1726 | local s = '' | ||
| 1727 | while o[i] do | ||
| 1728 | s = s .. o[i] | ||
| 1729 | i = i+1 | ||
| 1730 | end | ||
| 1731 | return s | ||
| 1732 | end | ||
| 1733 | \end{verbatim} | ||
| 1734 | To call it, one uses a table constructor to join all arguments: | ||
| 1735 | \begin{verbatim} | ||
| 1736 | x = concat{"hello ", "john", " and ", "mary"} | ||
| 1737 | \end{verbatim} | ||
| 1738 | |||
| 1701 | \subsection{\Index{Persistence}} | 1739 | \subsection{\Index{Persistence}} |
| 1702 | Because of its reflexive facilities, | 1740 | Because of its reflexive facilities, |
| 1703 | persistence in Lua can be achieved within the language. | 1741 | persistence in Lua can be achieved within the language. |
| @@ -1829,7 +1867,7 @@ void Index (void) | |||
| 1829 | \end{figure} | 1867 | \end{figure} |
| 1830 | This code must be registered with: | 1868 | This code must be registered with: |
| 1831 | \begin{verbatim} | 1869 | \begin{verbatim} |
| 1832 | lua_pushliteral("parent"); | 1870 | lua_pushstring("parent"); |
| 1833 | lockedParentName = lua_lock(); | 1871 | lockedParentName = lua_lock(); |
| 1834 | lua_pushobject(lua_setfallback("index", Index)); | 1872 | lua_pushobject(lua_setfallback("index", Index)); |
| 1835 | lockedOldIndex = lua_lock(); | 1873 | lockedOldIndex = lua_lock(); |
