aboutsummaryrefslogtreecommitdiff
path: root/manual.tex
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-08-24 17:14:56 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-08-24 17:14:56 -0300
commitee22af5ced0b14c2a445124fc0efffc5f44ed49a (patch)
tree4dea69431fe478cf8583038226f57567a7548c94 /manual.tex
parentcc117253c83ec32d226a8f2226d5ca144804f873 (diff)
downloadlua-ee22af5ced0b14c2a445124fc0efffc5f44ed49a.tar.gz
lua-ee22af5ced0b14c2a445124fc0efffc5f44ed49a.tar.bz2
lua-ee22af5ced0b14c2a445124fc0efffc5f44ed49a.zip
new functions "seek" and "flush".
Diffstat (limited to 'manual.tex')
-rw-r--r--manual.tex102
1 files changed, 67 insertions, 35 deletions
diff --git a/manual.tex b/manual.tex
index 5f56593c..55aaf3f8 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.17 1998/06/29 18:09:28 roberto Exp roberto $ 1% $Id: manual.tex,v 1.18 1998/08/21 17:43:44 roberto Exp roberto $
2 2
3\documentclass[11pt]{article} 3\documentclass[11pt]{article}
4\usepackage{fullpage,bnf} 4\usepackage{fullpage,bnf}
@@ -41,7 +41,7 @@ Waldemar Celes
41\tecgraf\ --- Computer Science Department --- PUC-Rio 41\tecgraf\ --- Computer Science Department --- PUC-Rio
42} 42}
43 43
44%\date{\small \verb$Date: 1998/06/29 18:09:28 $} 44%\date{\small \verb$Date: 1998/08/21 17:43:44 $}
45 45
46\maketitle 46\maketitle
47 47
@@ -1879,7 +1879,7 @@ and \verb|lua_iolibopen|, declared in \verb|lualib.h|.
1879 1879
1880\subsubsection*{\ff \T{call (func, arg [, mode [, errhandler]])}}\Deffunc{call} 1880\subsubsection*{\ff \T{call (func, arg [, mode [, errhandler]])}}\Deffunc{call}
1881\label{pdf-call} 1881\label{pdf-call}
1882This function calls function \verb|func| with 1882Calls function \verb|func| with
1883the arguments given by the table \verb|arg|. 1883the arguments given by the table \verb|arg|.
1884The call is equivalent to 1884The call is equivalent to
1885\begin{verbatim} 1885\begin{verbatim}
@@ -1932,7 +1932,7 @@ this limit.
1932the API function \verb|lua_collectgarbage|. 1932the API function \verb|lua_collectgarbage|.
1933 1933
1934\subsubsection*{\ff \T{dofile (filename)}}\Deffunc{dofile} 1934\subsubsection*{\ff \T{dofile (filename)}}\Deffunc{dofile}
1935This function receives a file name, 1935Receives a file name,
1936opens the file, and executes the file contents as a Lua chunk, 1936opens the file, and executes the file contents as a Lua chunk,
1937or as pre-compiled chunks. 1937or as pre-compiled chunks.
1938When called without arguments, 1938When called without arguments,
@@ -1945,7 +1945,7 @@ It issues an error when called with a non string argument.
1945\verb|dofile| is equivalent to the API function \verb|lua_dofile|. 1945\verb|dofile| is equivalent to the API function \verb|lua_dofile|.
1946 1946
1947\subsubsection*{\ff \T{dostring (string [, chunkname])}}\Deffunc{dostring} 1947\subsubsection*{\ff \T{dostring (string [, chunkname])}}\Deffunc{dostring}
1948This function executes a given string as a Lua chunk. 1948Executes a given string as a Lua chunk.
1949If there is any error executing the string, 1949If there is any error executing the string,
1950\verb|dostring| returns \nil. 1950\verb|dostring| returns \nil.
1951Otherwise, it returns the values returned by the chunk, 1951Otherwise, it returns the values returned by the chunk,
@@ -1960,7 +1960,7 @@ Returns a new tag.
1960\verb|newtag| is equivalent to the API function \verb|lua_newtag|. 1960\verb|newtag| is equivalent to the API function \verb|lua_newtag|.
1961 1961
1962\subsubsection*{\ff \T{next (table, index)}}\Deffunc{next} 1962\subsubsection*{\ff \T{next (table, index)}}\Deffunc{next}
1963This function allows a program to traverse all fields of a table. 1963Allows a program to traverse all fields of a table.
1964Its first argument is a table and its second argument 1964Its first argument is a table and its second argument
1965is an index in this table. 1965is an index in this table.
1966It returns the next index of the table and the 1966It returns the next index of the table and the
@@ -2038,13 +2038,13 @@ end
2038\end{verbatim} 2038\end{verbatim}
2039 2039
2040\subsubsection*{\ff \T{tostring (e)}}\Deffunc{tostring} 2040\subsubsection*{\ff \T{tostring (e)}}\Deffunc{tostring}
2041This function receives an argument of any type and 2041Receives an argument of any type and
2042converts it to a string in a reasonable format. 2042converts it to a string in a reasonable format.
2043For complete control on how numbers are converted, 2043For complete control on how numbers are converted,
2044use function \verb|format|. 2044use function \verb|format|.
2045 2045
2046\subsubsection*{\ff \T{print (e1, e2, ...)}}\Deffunc{print} 2046\subsubsection*{\ff \T{print (e1, e2, ...)}}\Deffunc{print}
2047This function receives any number of arguments, 2047Receives any number of arguments,
2048and prints their values using the strings returned by \verb|tostring|. 2048and prints their values using the strings returned by \verb|tostring|.
2049This function is not intended for formatted output, 2049This function is not intended for formatted output,
2050but only as a quick way to show a value, 2050but only as a quick way to show a value,
@@ -2052,14 +2052,14 @@ for instance for debugging.
2052See \See{libio} for functions for formatted output. 2052See \See{libio} for functions for formatted output.
2053 2053
2054\subsubsection*{\ff \T{_ALERT (message)}}\Deffunc{alert}\label{alert} 2054\subsubsection*{\ff \T{_ALERT (message)}}\Deffunc{alert}\label{alert}
2055This function prints its only string argument to \IndexVerb{stderr}. 2055Prints its only string argument to \IndexVerb{stderr}.
2056All error messages in Lua are printed through this function. 2056All error messages in Lua are printed through this function.
2057Therefore, a program may redefine it 2057Therefore, a program may redefine it
2058to change the way such messages are shown 2058to change the way such messages are shown
2059(for instance, for systems without \verb|stderr|). 2059(for instance, for systems without \verb|stderr|).
2060 2060
2061\subsubsection*{\ff \T{tonumber (e [, base])}}\Deffunc{tonumber} 2061\subsubsection*{\ff \T{tonumber (e [, base])}}\Deffunc{tonumber}
2062This function receives one argument, 2062Receives one argument,
2063and tries to convert it to a number. 2063and tries to convert it to a number.
2064If the argument is already a number or a string convertible 2064If the argument is already a number or a string convertible
2065to a number, then \verb|tonumber| returns that number; 2065to a number, then \verb|tonumber| returns that number;
@@ -2075,7 +2075,7 @@ as well as an optional exponent part \see{coercion}.
2075In other bases, only integers are accepted. 2075In other bases, only integers are accepted.
2076 2076
2077\subsubsection*{\ff \T{type (v)}}\Deffunc{type}\label{pdf-type} 2077\subsubsection*{\ff \T{type (v)}}\Deffunc{type}\label{pdf-type}
2078This function allows Lua to test the type of a value. 2078Allows Lua to test the type of a value.
2079It receives one argument, and returns its type, coded as a string. 2079It receives one argument, and returns its type, coded as a string.
2080The possible results of this function are 2080The possible results of this function are
2081\verb|"nil"| (a string, not the value \nil), 2081\verb|"nil"| (a string, not the value \nil),
@@ -2086,12 +2086,12 @@ The possible results of this function are
2086and \verb|"userdata"|. 2086and \verb|"userdata"|.
2087 2087
2088\subsubsection*{\ff \T{tag (v)}}\Deffunc{tag} 2088\subsubsection*{\ff \T{tag (v)}}\Deffunc{tag}
2089This function allows Lua to test the tag of a value \see{TypesSec}. 2089Allows Lua to test the tag of a value \see{TypesSec}.
2090It receives one argument, and returns its tag (a number). 2090It receives one argument, and returns its tag (a number).
2091\verb|tag| is equivalent to the API function \verb|lua_tag|. 2091\verb|tag| is equivalent to the API function \verb|lua_tag|.
2092 2092
2093\subsubsection*{\ff \T{settag (t, tag)}}\Deffunc{settag} 2093\subsubsection*{\ff \T{settag (t, tag)}}\Deffunc{settag}
2094This function sets the tag of a given table \see{TypesSec}. 2094Sets the tag of a given table \see{TypesSec}.
2095\verb|tag| must be a value created with \verb|newtag| 2095\verb|tag| must be a value created with \verb|newtag|
2096\see{pdf-newtag}. 2096\see{pdf-newtag}.
2097It returns the value of its first argument (the table). 2097It returns the value of its first argument (the table).
@@ -2100,7 +2100,7 @@ it is impossible to change the tag of a userdata from Lua.
2100 2100
2101 2101
2102\subsubsection*{\ff \T{assert (v [, message])}}\Deffunc{assert} 2102\subsubsection*{\ff \T{assert (v [, message])}}\Deffunc{assert}
2103This function issues an \emph{``assertion failed!''} error 2103Issues an \emph{``assertion failed!''} error
2104when its argument is \nil. 2104when its argument is \nil.
2105This function is equivalent to the following Lua function: 2105This function is equivalent to the following Lua function:
2106\begin{verbatim} 2106\begin{verbatim}
@@ -2113,7 +2113,7 @@ end
2113\end{verbatim} 2113\end{verbatim}
2114 2114
2115\subsubsection*{\ff \T{error (message)}}\Deffunc{error}\label{pdf-error} 2115\subsubsection*{\ff \T{error (message)}}\Deffunc{error}\label{pdf-error}
2116This function calls the error handler and then terminates 2116Calls the error handler and then terminates
2117the last protected function called 2117the last protected function called
2118(in~C: \verb|lua_dofile|, \verb|lua_dostring|, 2118(in~C: \verb|lua_dofile|, \verb|lua_dostring|,
2119\verb|lua_dobuffer|, or \verb|lua_callfunction|; 2119\verb|lua_dobuffer|, or \verb|lua_callfunction|;
@@ -2136,7 +2136,7 @@ without invoking any tag method.
2136and \verb|value| is any Lua value. 2136and \verb|value| is any Lua value.
2137 2137
2138\subsubsection*{\ff \T{rawsetglobal (name, value)}}\Deffunc{rawsetglobal} 2138\subsubsection*{\ff \T{rawsetglobal (name, value)}}\Deffunc{rawsetglobal}
2139This function assigns the given value to a global variable. 2139Assigns the given value to a global variable.
2140The string \verb|name| does not need to be a 2140The string \verb|name| does not need to be a
2141syntactically valid variable name. 2141syntactically valid variable name.
2142Therefore, 2142Therefore,
@@ -2145,7 +2145,7 @@ this function can set global variables with strange names like
2145Function \verb|rawsetglobal| returns the value of its second argument. 2145Function \verb|rawsetglobal| returns the value of its second argument.
2146 2146
2147\subsubsection*{\ff \T{setglobal (name, value)}}\Deffunc{setglobal} 2147\subsubsection*{\ff \T{setglobal (name, value)}}\Deffunc{setglobal}
2148This function assigns the given value to a global variable, 2148Assigns the given value to a global variable,
2149or calls a tag method. 2149or calls a tag method.
2150Its full semantics is explained in \See{tag-method}. 2150Its full semantics is explained in \See{tag-method}.
2151The string \verb|name| does not need to be a 2151The string \verb|name| does not need to be a
@@ -2153,12 +2153,12 @@ syntactically valid variable name.
2153Function \verb|setglobal| returns the value of its second argument. 2153Function \verb|setglobal| returns the value of its second argument.
2154 2154
2155\subsubsection*{\ff \T{rawgetglobal (name)}}\Deffunc{rawgetglobal} 2155\subsubsection*{\ff \T{rawgetglobal (name)}}\Deffunc{rawgetglobal}
2156This function retrieves the value of a global variable. 2156Retrieves the value of a global variable.
2157The string \verb|name| does not need to be a 2157The string \verb|name| does not need to be a
2158syntactically valid variable name. 2158syntactically valid variable name.
2159 2159
2160\subsubsection*{\ff \T{getglobal (name)}}\Deffunc{getglobal} 2160\subsubsection*{\ff \T{getglobal (name)}}\Deffunc{getglobal}
2161This function retrieves the value of a global variable, 2161Retrieves the value of a global variable,
2162or calls a tag method. 2162or calls a tag method.
2163Its full semantics is explained in \See{tag-method}. 2163Its full semantics is explained in \See{tag-method}.
2164The string \verb|name| does not need to be a 2164The string \verb|name| does not need to be a
@@ -2166,19 +2166,19 @@ syntactically valid variable name.
2166 2166
2167\subsubsection*{\ff \T{settagmethod (tag, event, newmethod)}} 2167\subsubsection*{\ff \T{settagmethod (tag, event, newmethod)}}
2168\Deffunc{settagmethod} 2168\Deffunc{settagmethod}
2169This function sets a new tag method to the given pair \M{(tag, event)}. 2169Sets a new tag method to the given pair \M{(tag, event)}.
2170It returns the old method. 2170It returns the old method.
2171If \verb|newmethod| is \nil, 2171If \verb|newmethod| is \nil,
2172\verb|settagmethod| restores the default behavior for the given event. 2172\verb|settagmethod| restores the default behavior for the given event.
2173 2173
2174\subsubsection*{\ff \T{gettagmethod (tag, event)}} 2174\subsubsection*{\ff \T{gettagmethod (tag, event)}}
2175\Deffunc{gettagmethod} 2175\Deffunc{gettagmethod}
2176This function returns the current tag method 2176Returns the current tag method
2177for a given pair \M{(tag, event)}. 2177for a given pair \M{(tag, event)}.
2178 2178
2179\subsubsection*{\ff \T{copytagmethods (tagto, tagfrom)}} 2179\subsubsection*{\ff \T{copytagmethods (tagto, tagfrom)}}
2180\Deffunc{copytagmethods} 2180\Deffunc{copytagmethods}
2181This function copies all tag methods from one tag to another; 2181Copies all tag methods from one tag to another;
2182it returns \verb|tagto|. 2182it returns \verb|tagto|.
2183 2183
2184 2184
@@ -2190,7 +2190,7 @@ When indexing a string, the first character is at position~1
2190 2190
2191\subsubsection*{\ff \T{strfind (str, pattern [, init [, plain]])}} 2191\subsubsection*{\ff \T{strfind (str, pattern [, init [, plain]])}}
2192\Deffunc{strfind} 2192\Deffunc{strfind}
2193This function looks for the first \emph{match} of 2193Looks for the first \emph{match} of
2194\verb|pattern| in \verb|str|. 2194\verb|pattern| in \verb|str|.
2195If it finds one, then it returns the indices on \verb|str| 2195If it finds one, then it returns the indices on \verb|str|
2196where this occurrence starts and ends; 2196where this occurrence starts and ends;
@@ -2265,7 +2265,7 @@ Note that numerical codes are not necessarily portable across platforms.
2265 2265
2266\subsubsection*{\ff \T{format (formatstring, e1, e2, \ldots)}}\Deffunc{format} 2266\subsubsection*{\ff \T{format (formatstring, e1, e2, \ldots)}}\Deffunc{format}
2267\label{format} 2267\label{format}
2268This function returns a formatted version of its variable number of arguments 2268Returns a formatted version of its variable number of arguments
2269following the description given in its first argument (which must be a string). 2269following the description given in its first argument (which must be a string).
2270The format string follows the same rules as the \verb|printf| family of 2270The format string follows the same rules as the \verb|printf| family of
2271standard C functions. 2271standard C functions.
@@ -2579,7 +2579,7 @@ usually limited and depends on the system.
2579 2579
2580\subsubsection*{\ff \T{appendto (filename)}}\Deffunc{appendto} 2580\subsubsection*{\ff \T{appendto (filename)}}\Deffunc{appendto}
2581 2581
2582This function opens a file named \verb|filename| and sets it as the 2582Opens a file named \verb|filename| and sets it as the
2583value of \verb|_OUTPUT|. 2583value of \verb|_OUTPUT|.
2584Unlike the \verb|writeto| operation, 2584Unlike the \verb|writeto| operation,
2585this function does not erase any previous content of the file. 2585this function does not erase any previous content of the file.
@@ -2591,26 +2591,58 @@ available to close an output file opened by \verb|appendto|.
2591 2591
2592\subsubsection*{\ff \T{remove (filename)}}\Deffunc{remove} 2592\subsubsection*{\ff \T{remove (filename)}}\Deffunc{remove}
2593 2593
2594This function deletes the file with the given name. 2594Deletes the file with the given name.
2595If this function fails, it returns \nil, 2595If this function fails, it returns \nil,
2596plus a string describing the error. 2596plus a string describing the error.
2597 2597
2598\subsubsection*{\ff \T{rename (name1, name2)}}\Deffunc{rename} 2598\subsubsection*{\ff \T{rename (name1, name2)}}\Deffunc{rename}
2599 2599
2600This function renames file named \verb|name1| to \verb|name2|. 2600Renames file named \verb|name1| to \verb|name2|.
2601If this function fails, it returns \nil, 2601If this function fails, it returns \nil,
2602plus a string describing the error. 2602plus a string describing the error.
2603 2603
2604\subsubsection*{\ff \T{flush ([filehandle])}}\Deffunc{flush}
2605
2606Saves any written data to the given file.
2607If \verb|filehandle| is not specified,
2608flushes all open files.
2609If this function fails, it returns \nil,
2610plus a string describing the error.
2611
2612\subsubsection*{\ff \T{seek (filehandle [, whence] [, offset])}}\Deffunc{seek}
2613
2614Sets the file position, measured in bytes from the beginning of the file,
2615to the position given by \verb|offset| plus a base
2616specified by the string \verb|whence|, as follows:
2617\begin{description}
2618\item[\tt "set"] base is position 0 (beginning of the file);
2619\item[\tt "cur"] base is current position;
2620\item[\tt "end"] base is end of file;
2621\end{description}
2622In case of success, function \verb|seek| returns the final file position,
2623measured in bytes from the beginning of the file.
2624If the call fails, it returns \nil,
2625plus a string describing the error.
2626
2627The default value for \verb|whence| is \verb|"cur"|,
2628and for \verb|offset| is 0.
2629Therefore, the call \verb|seek(file)| returns the current
2630file position, without changing it;
2631the call \verb|seek(file, "set")| sets the position to the
2632beginning of the file (and returns 0);
2633and the call \verb|seek(file, "end")| sets the position to the
2634end of the file, and returns its size.
2635
2604\subsubsection*{\ff \T{tmpname ()}}\Deffunc{tmpname} 2636\subsubsection*{\ff \T{tmpname ()}}\Deffunc{tmpname}
2605 2637
2606This function returns a string with a file name that can safely 2638Returns a string with a file name that can safely
2607be used for a temporary file. 2639be used for a temporary file.
2608The file must be explicitly removed when no longer needed. 2640The file must be explicitly removed when no longer needed.
2609 2641
2610\subsubsection*{\ff \T{read ([filehandle] [readpattern])}}\Deffunc{read} 2642\subsubsection*{\ff \T{read ([filehandle] [readpattern])}}\Deffunc{read}
2611 2643
2612This function reads the file \verb|_INPUT|, 2644Reads file \verb|_INPUT|,
2613or from \verb|filehandle| if this argument is given, 2645or \verb|filehandle| if this argument is given,
2614according to a read pattern, which specifies how much to read; 2646according to a read pattern, which specifies how much to read;
2615characters are read from the input file until 2647characters are read from the input file until
2616the read pattern fails or ends. 2648the read pattern fails or ends.
@@ -2662,9 +2694,9 @@ or \nil\ if the next characters do not conform to an integer format.
2662 2694
2663\subsubsection*{\ff \T{write ([filehandle, ] value1, ...)}}\Deffunc{write} 2695\subsubsection*{\ff \T{write ([filehandle, ] value1, ...)}}\Deffunc{write}
2664 2696
2665This function writes the value of each of its arguments to the 2697Writes the value of each of its arguments to
2666file \verb|_OUTPUT|, 2698file \verb|_OUTPUT|,
2667or to \verb|filehandle| if this argument is given, 2699or to \verb|filehandle| if this argument is given.
2668The arguments must be strings or numbers. 2700The arguments must be strings or numbers.
2669To write other values, 2701To write other values,
2670use \verb|tostring| or \verb|format| before \verb|write|. 2702use \verb|tostring| or \verb|format| before \verb|write|.
@@ -2673,7 +2705,7 @@ plus a string describing the error.
2673 2705
2674\subsubsection*{\ff \T{date ([format])}}\Deffunc{date} 2706\subsubsection*{\ff \T{date ([format])}}\Deffunc{date}
2675 2707
2676This function returns a string containing date and time 2708Returns a string containing date and time
2677formatted according to the given string \verb|format|, 2709formatted according to the given string \verb|format|,
2678following the same rules of the ANSI C function \verb|strftime|. 2710following the same rules of the ANSI C function \verb|strftime|.
2679When called without arguments, 2711When called without arguments,
@@ -2682,12 +2714,12 @@ the host system and the locale.
2682 2714
2683\subsubsection*{\ff \T{clock ()}}\Deffunc{clock} 2715\subsubsection*{\ff \T{clock ()}}\Deffunc{clock}
2684 2716
2685This function returns an approximation of the amount of CPU time 2717Returns an approximation of the amount of CPU time
2686used by the program, in seconds. 2718used by the program, in seconds.
2687 2719
2688\subsubsection*{\ff \T{exit ([code])}}\Deffunc{exit} 2720\subsubsection*{\ff \T{exit ([code])}}\Deffunc{exit}
2689 2721
2690This function calls the C function \verb|exit|, 2722Calls the C function \verb|exit|,
2691with an optional \verb|code|, 2723with an optional \verb|code|,
2692to terminate the program. 2724to terminate the program.
2693The default value for \verb|code| is 1. 2725The default value for \verb|code| is 1.