diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-29 15:08:23 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-29 15:08:23 -0200 |
commit | 84df3ac2675af018d85d26746165325475575965 (patch) | |
tree | 7b00aeddd7382269cc5fc33c19818c01ef276e22 | |
parent | 55a70c9719cce1b5b9ba78919a0ab54c8442af73 (diff) | |
download | lua-84df3ac2675af018d85d26746165325475575965.tar.gz lua-84df3ac2675af018d85d26746165325475575965.tar.bz2 lua-84df3ac2675af018d85d26746165325475575965.zip |
new functions "tostring", "assert", and "format".
-rw-r--r-- | manual.tex | 57 |
1 files changed, 50 insertions, 7 deletions
@@ -1,3 +1,5 @@ | |||
1 | % $Id: $ | ||
2 | |||
1 | \documentstyle[A4,11pt,bnf]{article} | 3 | \documentstyle[A4,11pt,bnf]{article} |
2 | 4 | ||
3 | \newcommand{\rw}[1]{{\bf #1}} | 5 | \newcommand{\rw}[1]{{\bf #1}} |
@@ -42,6 +44,8 @@ as a configuration language for any program that needs one. | |||
42 | This document describes version 2.2 of the Lua programming language and the | 44 | This document describes version 2.2 of the Lua programming language and the |
43 | API that allows interaction between Lua programs and its host C program. | 45 | API that allows interaction between Lua programs and its host C program. |
44 | It also presents some examples of using the main features of the system. | 46 | It also presents some examples of using the main features of the system. |
47 | |||
48 | {\em Lua manual: \verb$Date$, \verb$Revision$} | ||
45 | \end{abstract} | 49 | \end{abstract} |
46 | 50 | ||
47 | \vspace{4ex} | 51 | \vspace{4ex} |
@@ -1080,8 +1084,9 @@ it can be unlocked with a call to \verb'lua_unlock'. | |||
1080 | The set of \Index{predefined functions} in Lua is small but powerful. | 1084 | The set of \Index{predefined functions} in Lua is small but powerful. |
1081 | Most of them provide features that allows some degree of | 1085 | Most of them provide features that allows some degree of |
1082 | \Index{reflexivity} in the language. | 1086 | \Index{reflexivity} in the language. |
1083 | Many of these features cannot be simulated with the rest of the | 1087 | Some of these features cannot be simulated with the rest of the |
1084 | Language nor with the standard API. | 1088 | Language nor with the standard Lua API. |
1089 | Others are just helpful interfaces to common API functions. | ||
1085 | 1090 | ||
1086 | The libraries, on the other hand, provide useful routines | 1091 | The libraries, on the other hand, provide useful routines |
1087 | that are implemented directly through the standard API. | 1092 | that are implemented directly through the standard API. |
@@ -1104,7 +1109,10 @@ declared in \verb-lualib.h-. | |||
1104 | \subsubsection*{{\tt dofile (filename)}}\Deffunc{dofile} | 1109 | \subsubsection*{{\tt dofile (filename)}}\Deffunc{dofile} |
1105 | This function receives a file name, | 1110 | This function receives a file name, |
1106 | opens it and executes its contents as a Lua chunk. | 1111 | opens it and executes its contents as a Lua chunk. |
1112 | When called without arguments, | ||
1113 | it executes the contents of the standard input. | ||
1107 | It returns 1 if there are no errors, \nil\ otherwise. | 1114 | It returns 1 if there are no errors, \nil\ otherwise. |
1115 | It issues an error when called with a non string argument. | ||
1108 | 1116 | ||
1109 | \subsubsection*{{\tt dostring (string)}}\Deffunc{dostring} | 1117 | \subsubsection*{{\tt dostring (string)}}\Deffunc{dostring} |
1110 | This function executes a given string as a Lua chunk. | 1118 | This function executes a given string as a Lua chunk. |
@@ -1141,6 +1149,10 @@ and its value, | |||
1141 | or \nil\ if there are no more variables. | 1149 | or \nil\ if there are no more variables. |
1142 | See Section \ref{exnext} for an example of the use of this function. | 1150 | See Section \ref{exnext} for an example of the use of this function. |
1143 | 1151 | ||
1152 | \subsubsection*{{\tt tostring (e)}}\Deffunc{tostring} | ||
1153 | This function receives an argument of any type and | ||
1154 | converts it to a string in a reasonable format. | ||
1155 | |||
1144 | \subsubsection*{{\tt print (e1, e2, ...)}}\Deffunc{print} | 1156 | \subsubsection*{{\tt print (e1, e2, ...)}}\Deffunc{print} |
1145 | This function receives any number of arguments, | 1157 | This function receives any number of arguments, |
1146 | and prints their values in a reasonable format. | 1158 | and prints their values in a reasonable format. |
@@ -1174,6 +1186,10 @@ This tag can be used to distinguish between user | |||
1174 | data with different tags, | 1186 | data with different tags, |
1175 | and between C functions and Lua functions. | 1187 | and between C functions and Lua functions. |
1176 | 1188 | ||
1189 | \subsubsection*{{\tt assert (v)}}\Deffunc{assert} | ||
1190 | This function issues an {\em ``assertion failed!''} error | ||
1191 | when its argument is \nil. | ||
1192 | |||
1177 | \subsubsection*{{\tt error (message)}}\Deffunc{error} | 1193 | \subsubsection*{{\tt error (message)}}\Deffunc{error} |
1178 | This function issues an error message and terminates | 1194 | This function issues an error message and terminates |
1179 | the last called function from the library | 1195 | the last called function from the library |
@@ -1185,6 +1201,7 @@ This function assigns the given value to a global variable. | |||
1185 | The string \verb'name' does not need to be a syntactically valid variable name. | 1201 | The string \verb'name' does not need to be a syntactically valid variable name. |
1186 | Therefore, this function can set global variables with strange names like | 1202 | Therefore, this function can set global variables with strange names like |
1187 | \verb'm v 1' or \verb'34'. | 1203 | \verb'm v 1' or \verb'34'. |
1204 | It returns the value of its second argument. | ||
1188 | 1205 | ||
1189 | \subsubsection*{{\tt getglobal (name)}}\Deffunc{getglobal} | 1206 | \subsubsection*{{\tt getglobal (name)}}\Deffunc{getglobal} |
1190 | This function retrieves the value of a global variable. | 1207 | This function retrieves the value of a global variable. |
@@ -1240,11 +1257,19 @@ All other characters are left unchanged. | |||
1240 | Returns the ascii code of the character \verb's[i]'. | 1257 | Returns the ascii code of the character \verb's[i]'. |
1241 | If \verb'i' is absent, it is assumed to be 1. | 1258 | If \verb'i' is absent, it is assumed to be 1. |
1242 | 1259 | ||
1243 | \subsubsection*{{\tt int2str (\{i\})}}\Deffunc{int2str} | 1260 | \subsubsection*{{\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format} |
1244 | Receives 0 or more numbers. | 1261 | This function returns a formated version of its variable number of arguments |
1245 | Returns a string with length equal to the number of arguments, | 1262 | following the description given in its first argument (which must be a string). |
1246 | wherein each character has ascii value equal | 1263 | The format string follows the same rules as the \verb'printf' family of |
1247 | to its correspondent argument. | 1264 | standard C functions. |
1265 | The only differencies are that the options/modifiers | ||
1266 | \verb'*', \verb'l', \verb'L', \verb'n', \verb'p', | ||
1267 | and \verb'h' are not supported. | ||
1268 | The options \verb'c', \verb'd', \verb'i', \verb'o', \verb'u', | ||
1269 | \verb'x', \verb'X', \verb'e', \verb'E', \verb'f', and \verb'g' all | ||
1270 | expect a number argument, | ||
1271 | while \verb's' expects a string. | ||
1272 | |||
1248 | 1273 | ||
1249 | \subsection{Mathematical Functions} \label{mathlib} | 1274 | \subsection{Mathematical Functions} \label{mathlib} |
1250 | 1275 | ||
@@ -1350,6 +1375,8 @@ Particularly, the format \verb'"s1"' reads a single character. | |||
1350 | \subsubsection*{{\tt readuntil (char)}}\Deffunc{readuntil} | 1375 | \subsubsection*{{\tt readuntil (char)}}\Deffunc{readuntil} |
1351 | 1376 | ||
1352 | Reads the current input until the first ocurrence of the given character. | 1377 | Reads the current input until the first ocurrence of the given character. |
1378 | When called with no parameters or with nil, | ||
1379 | reads until the end of the current input file. | ||
1353 | Returns the string read. | 1380 | Returns the string read. |
1354 | The character itself is not read. | 1381 | The character itself is not read. |
1355 | 1382 | ||
@@ -1383,10 +1410,26 @@ For integers, it is the minimum number of digits. | |||
1383 | This option has no meaning for strings. | 1410 | This option has no meaning for strings. |
1384 | \end{description} | 1411 | \end{description} |
1385 | 1412 | ||
1413 | {\em Warning:} | ||
1414 | This format parameter is now obsolete; | ||
1415 | formated output should use the \verb'format' function. | ||
1416 | |||
1386 | When called without a format string, | 1417 | When called without a format string, |
1387 | this function writes numbers using the \verb'%g' format | 1418 | this function writes numbers using the \verb'%g' format |
1388 | and strings with \verb'%s'. | 1419 | and strings with \verb'%s'. |
1389 | 1420 | ||
1421 | \subsubsection*{{\tt date ()}}\Deffunc{date} | ||
1422 | |||
1423 | This function returns 4 values: | ||
1424 | the current day of the month, | ||
1425 | the month ([1-12]), the current year, | ||
1426 | and the day of the week (1 = Sunday, 7 = Saturday). | ||
1427 | |||
1428 | \subsubsection*{{\tt time ()}}\Deffunc{time} | ||
1429 | |||
1430 | This function returns the current time through 3 values: | ||
1431 | hours ([0-23]), minutes, and seconds. | ||
1432 | |||
1390 | % \subsubsection*{{\tt debug ()}} | 1433 | % \subsubsection*{{\tt debug ()}} |
1391 | % This function, when called, repeatedly presents a prompt \verb'lua_debug> ' | 1434 | % This function, when called, repeatedly presents a prompt \verb'lua_debug> ' |
1392 | % in the error output stream (\verb'stderr'), | 1435 | % in the error output stream (\verb'stderr'), |