diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-08-24 17:14:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-08-24 17:14:56 -0300 |
commit | ee22af5ced0b14c2a445124fc0efffc5f44ed49a (patch) | |
tree | 4dea69431fe478cf8583038226f57567a7548c94 | |
parent | cc117253c83ec32d226a8f2226d5ca144804f873 (diff) | |
download | lua-ee22af5ced0b14c2a445124fc0efffc5f44ed49a.tar.gz lua-ee22af5ced0b14c2a445124fc0efffc5f44ed49a.tar.bz2 lua-ee22af5ced0b14c2a445124fc0efffc5f44ed49a.zip |
new functions "seek" and "flush".
-rw-r--r-- | liolib.c | 49 | ||||
-rw-r--r-- | manual.tex | 102 |
2 files changed, 107 insertions, 44 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.21 1998/06/18 17:04:28 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.22 1998/08/21 17:43:44 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -76,7 +76,7 @@ static int ishandler (lua_Object f) | |||
76 | else return 0; | 76 | else return 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | static FILE *getfile (char *name) | 79 | static FILE *getfilebyname (char *name) |
80 | { | 80 | { |
81 | lua_Object f = lua_getglobal(name); | 81 | lua_Object f = lua_getglobal(name); |
82 | if (!ishandler(f)) | 82 | if (!ishandler(f)) |
@@ -85,21 +85,26 @@ static FILE *getfile (char *name) | |||
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static FILE *getfileparam (char *name, int *arg) | 88 | static FILE *getfile (int arg) { |
89 | { | 89 | lua_Object f = lua_getparam(arg); |
90 | lua_Object f = lua_getparam(*arg); | 90 | return (ishandler(f)) ? lua_getuserdata(f) : NULL; |
91 | if (ishandler(f)) { | 91 | } |
92 | |||
93 | |||
94 | static FILE *getfileparam (char *name, int *arg) { | ||
95 | FILE *f = getfile(*arg); | ||
96 | if (f) { | ||
92 | (*arg)++; | 97 | (*arg)++; |
93 | return lua_getuserdata(f); | 98 | return f; |
94 | } | 99 | } |
95 | else | 100 | else |
96 | return getfile(name); | 101 | return getfilebyname(name); |
97 | } | 102 | } |
98 | 103 | ||
99 | 104 | ||
100 | static void closefile (char *name) | 105 | static void closefile (char *name) |
101 | { | 106 | { |
102 | FILE *f = getfile(name); | 107 | FILE *f = getfilebyname(name); |
103 | if (f == stdin || f == stdout) return; | 108 | if (f == stdin || f == stdout) return; |
104 | if (pclose(f) == -1) | 109 | if (pclose(f) == -1) |
105 | fclose(f); | 110 | fclose(f); |
@@ -271,6 +276,30 @@ static void io_write (void) | |||
271 | } | 276 | } |
272 | 277 | ||
273 | 278 | ||
279 | static void io_seek (void) { | ||
280 | static int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | ||
281 | static char *modenames[] = {"set", "cur", "end", NULL}; | ||
282 | FILE *f = getfile(FIRSTARG-1+1); | ||
283 | int op = luaL_findstring(luaL_opt_string(FIRSTARG-1+2, "cur"), modenames); | ||
284 | long offset = luaL_opt_number(FIRSTARG-1+3, 0); | ||
285 | luaL_arg_check(f, 1, "invalid file handler"); | ||
286 | luaL_arg_check(op != -1, 2, "invalid mode"); | ||
287 | op = fseek(f, offset, mode[op]); | ||
288 | if (op) | ||
289 | pushresult(0); /* error */ | ||
290 | else | ||
291 | lua_pushnumber(ftell(f)); | ||
292 | } | ||
293 | |||
294 | |||
295 | static void io_flush (void) { | ||
296 | FILE *f = getfile(FIRSTARG); | ||
297 | luaL_arg_check(f || lua_getparam(FIRSTARG) == LUA_NOOBJECT, 1, | ||
298 | "invalid file handler"); | ||
299 | pushresult(fflush(f) == 0); | ||
300 | } | ||
301 | |||
302 | |||
274 | static void io_execute (void) | 303 | static void io_execute (void) |
275 | { | 304 | { |
276 | lua_pushnumber(system(luaL_check_string(1))); | 305 | lua_pushnumber(system(luaL_check_string(1))); |
@@ -420,7 +449,9 @@ static struct luaL_reg iolibtag[] = { | |||
420 | {"readfrom", io_readfrom}, | 449 | {"readfrom", io_readfrom}, |
421 | {"writeto", io_writeto}, | 450 | {"writeto", io_writeto}, |
422 | {"appendto", io_appendto}, | 451 | {"appendto", io_appendto}, |
452 | {"flush", io_flush}, | ||
423 | {"read", io_read}, | 453 | {"read", io_read}, |
454 | {"seek", io_seek}, | ||
424 | {"write", io_write} | 455 | {"write", io_write} |
425 | }; | 456 | }; |
426 | 457 | ||
@@ -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} |
1882 | This function calls function \verb|func| with | 1882 | Calls function \verb|func| with |
1883 | the arguments given by the table \verb|arg|. | 1883 | the arguments given by the table \verb|arg|. |
1884 | The call is equivalent to | 1884 | The call is equivalent to |
1885 | \begin{verbatim} | 1885 | \begin{verbatim} |
@@ -1932,7 +1932,7 @@ this limit. | |||
1932 | the API function \verb|lua_collectgarbage|. | 1932 | the API function \verb|lua_collectgarbage|. |
1933 | 1933 | ||
1934 | \subsubsection*{\ff \T{dofile (filename)}}\Deffunc{dofile} | 1934 | \subsubsection*{\ff \T{dofile (filename)}}\Deffunc{dofile} |
1935 | This function receives a file name, | 1935 | Receives a file name, |
1936 | opens the file, and executes the file contents as a Lua chunk, | 1936 | opens the file, and executes the file contents as a Lua chunk, |
1937 | or as pre-compiled chunks. | 1937 | or as pre-compiled chunks. |
1938 | When called without arguments, | 1938 | When 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} |
1948 | This function executes a given string as a Lua chunk. | 1948 | Executes a given string as a Lua chunk. |
1949 | If there is any error executing the string, | 1949 | If there is any error executing the string, |
1950 | \verb|dostring| returns \nil. | 1950 | \verb|dostring| returns \nil. |
1951 | Otherwise, it returns the values returned by the chunk, | 1951 | Otherwise, 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} |
1963 | This function allows a program to traverse all fields of a table. | 1963 | Allows a program to traverse all fields of a table. |
1964 | Its first argument is a table and its second argument | 1964 | Its first argument is a table and its second argument |
1965 | is an index in this table. | 1965 | is an index in this table. |
1966 | It returns the next index of the table and the | 1966 | It 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} |
2041 | This function receives an argument of any type and | 2041 | Receives an argument of any type and |
2042 | converts it to a string in a reasonable format. | 2042 | converts it to a string in a reasonable format. |
2043 | For complete control on how numbers are converted, | 2043 | For complete control on how numbers are converted, |
2044 | use function \verb|format|. | 2044 | use function \verb|format|. |
2045 | 2045 | ||
2046 | \subsubsection*{\ff \T{print (e1, e2, ...)}}\Deffunc{print} | 2046 | \subsubsection*{\ff \T{print (e1, e2, ...)}}\Deffunc{print} |
2047 | This function receives any number of arguments, | 2047 | Receives any number of arguments, |
2048 | and prints their values using the strings returned by \verb|tostring|. | 2048 | and prints their values using the strings returned by \verb|tostring|. |
2049 | This function is not intended for formatted output, | 2049 | This function is not intended for formatted output, |
2050 | but only as a quick way to show a value, | 2050 | but only as a quick way to show a value, |
@@ -2052,14 +2052,14 @@ for instance for debugging. | |||
2052 | See \See{libio} for functions for formatted output. | 2052 | See \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} |
2055 | This function prints its only string argument to \IndexVerb{stderr}. | 2055 | Prints its only string argument to \IndexVerb{stderr}. |
2056 | All error messages in Lua are printed through this function. | 2056 | All error messages in Lua are printed through this function. |
2057 | Therefore, a program may redefine it | 2057 | Therefore, a program may redefine it |
2058 | to change the way such messages are shown | 2058 | to 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} |
2062 | This function receives one argument, | 2062 | Receives one argument, |
2063 | and tries to convert it to a number. | 2063 | and tries to convert it to a number. |
2064 | If the argument is already a number or a string convertible | 2064 | If the argument is already a number or a string convertible |
2065 | to a number, then \verb|tonumber| returns that number; | 2065 | to a number, then \verb|tonumber| returns that number; |
@@ -2075,7 +2075,7 @@ as well as an optional exponent part \see{coercion}. | |||
2075 | In other bases, only integers are accepted. | 2075 | In 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} |
2078 | This function allows Lua to test the type of a value. | 2078 | Allows Lua to test the type of a value. |
2079 | It receives one argument, and returns its type, coded as a string. | 2079 | It receives one argument, and returns its type, coded as a string. |
2080 | The possible results of this function are | 2080 | The 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 | |||
2086 | and \verb|"userdata"|. | 2086 | and \verb|"userdata"|. |
2087 | 2087 | ||
2088 | \subsubsection*{\ff \T{tag (v)}}\Deffunc{tag} | 2088 | \subsubsection*{\ff \T{tag (v)}}\Deffunc{tag} |
2089 | This function allows Lua to test the tag of a value \see{TypesSec}. | 2089 | Allows Lua to test the tag of a value \see{TypesSec}. |
2090 | It receives one argument, and returns its tag (a number). | 2090 | It 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} |
2094 | This function sets the tag of a given table \see{TypesSec}. | 2094 | Sets 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}. |
2097 | It returns the value of its first argument (the table). | 2097 | It 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} |
2103 | This function issues an \emph{``assertion failed!''} error | 2103 | Issues an \emph{``assertion failed!''} error |
2104 | when its argument is \nil. | 2104 | when its argument is \nil. |
2105 | This function is equivalent to the following Lua function: | 2105 | This 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} |
2116 | This function calls the error handler and then terminates | 2116 | Calls the error handler and then terminates |
2117 | the last protected function called | 2117 | the 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. | |||
2136 | and \verb|value| is any Lua value. | 2136 | and \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} |
2139 | This function assigns the given value to a global variable. | 2139 | Assigns the given value to a global variable. |
2140 | The string \verb|name| does not need to be a | 2140 | The string \verb|name| does not need to be a |
2141 | syntactically valid variable name. | 2141 | syntactically valid variable name. |
2142 | Therefore, | 2142 | Therefore, |
@@ -2145,7 +2145,7 @@ this function can set global variables with strange names like | |||
2145 | Function \verb|rawsetglobal| returns the value of its second argument. | 2145 | Function \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} |
2148 | This function assigns the given value to a global variable, | 2148 | Assigns the given value to a global variable, |
2149 | or calls a tag method. | 2149 | or calls a tag method. |
2150 | Its full semantics is explained in \See{tag-method}. | 2150 | Its full semantics is explained in \See{tag-method}. |
2151 | The string \verb|name| does not need to be a | 2151 | The string \verb|name| does not need to be a |
@@ -2153,12 +2153,12 @@ syntactically valid variable name. | |||
2153 | Function \verb|setglobal| returns the value of its second argument. | 2153 | Function \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} |
2156 | This function retrieves the value of a global variable. | 2156 | Retrieves the value of a global variable. |
2157 | The string \verb|name| does not need to be a | 2157 | The string \verb|name| does not need to be a |
2158 | syntactically valid variable name. | 2158 | syntactically valid variable name. |
2159 | 2159 | ||
2160 | \subsubsection*{\ff \T{getglobal (name)}}\Deffunc{getglobal} | 2160 | \subsubsection*{\ff \T{getglobal (name)}}\Deffunc{getglobal} |
2161 | This function retrieves the value of a global variable, | 2161 | Retrieves the value of a global variable, |
2162 | or calls a tag method. | 2162 | or calls a tag method. |
2163 | Its full semantics is explained in \See{tag-method}. | 2163 | Its full semantics is explained in \See{tag-method}. |
2164 | The string \verb|name| does not need to be a | 2164 | The 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} |
2169 | This function sets a new tag method to the given pair \M{(tag, event)}. | 2169 | Sets a new tag method to the given pair \M{(tag, event)}. |
2170 | It returns the old method. | 2170 | It returns the old method. |
2171 | If \verb|newmethod| is \nil, | 2171 | If \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} |
2176 | This function returns the current tag method | 2176 | Returns the current tag method |
2177 | for a given pair \M{(tag, event)}. | 2177 | for 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} |
2181 | This function copies all tag methods from one tag to another; | 2181 | Copies all tag methods from one tag to another; |
2182 | it returns \verb|tagto|. | 2182 | it 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} |
2193 | This function looks for the first \emph{match} of | 2193 | Looks for the first \emph{match} of |
2194 | \verb|pattern| in \verb|str|. | 2194 | \verb|pattern| in \verb|str|. |
2195 | If it finds one, then it returns the indices on \verb|str| | 2195 | If it finds one, then it returns the indices on \verb|str| |
2196 | where this occurrence starts and ends; | 2196 | where 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} |
2268 | This function returns a formatted version of its variable number of arguments | 2268 | Returns a formatted version of its variable number of arguments |
2269 | following the description given in its first argument (which must be a string). | 2269 | following the description given in its first argument (which must be a string). |
2270 | The format string follows the same rules as the \verb|printf| family of | 2270 | The format string follows the same rules as the \verb|printf| family of |
2271 | standard C functions. | 2271 | standard 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 | ||
2582 | This function opens a file named \verb|filename| and sets it as the | 2582 | Opens a file named \verb|filename| and sets it as the |
2583 | value of \verb|_OUTPUT|. | 2583 | value of \verb|_OUTPUT|. |
2584 | Unlike the \verb|writeto| operation, | 2584 | Unlike the \verb|writeto| operation, |
2585 | this function does not erase any previous content of the file. | 2585 | this 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 | ||
2594 | This function deletes the file with the given name. | 2594 | Deletes the file with the given name. |
2595 | If this function fails, it returns \nil, | 2595 | If this function fails, it returns \nil, |
2596 | plus a string describing the error. | 2596 | plus 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 | ||
2600 | This function renames file named \verb|name1| to \verb|name2|. | 2600 | Renames file named \verb|name1| to \verb|name2|. |
2601 | If this function fails, it returns \nil, | 2601 | If this function fails, it returns \nil, |
2602 | plus a string describing the error. | 2602 | plus a string describing the error. |
2603 | 2603 | ||
2604 | \subsubsection*{\ff \T{flush ([filehandle])}}\Deffunc{flush} | ||
2605 | |||
2606 | Saves any written data to the given file. | ||
2607 | If \verb|filehandle| is not specified, | ||
2608 | flushes all open files. | ||
2609 | If this function fails, it returns \nil, | ||
2610 | plus a string describing the error. | ||
2611 | |||
2612 | \subsubsection*{\ff \T{seek (filehandle [, whence] [, offset])}}\Deffunc{seek} | ||
2613 | |||
2614 | Sets the file position, measured in bytes from the beginning of the file, | ||
2615 | to the position given by \verb|offset| plus a base | ||
2616 | specified 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} | ||
2622 | In case of success, function \verb|seek| returns the final file position, | ||
2623 | measured in bytes from the beginning of the file. | ||
2624 | If the call fails, it returns \nil, | ||
2625 | plus a string describing the error. | ||
2626 | |||
2627 | The default value for \verb|whence| is \verb|"cur"|, | ||
2628 | and for \verb|offset| is 0. | ||
2629 | Therefore, the call \verb|seek(file)| returns the current | ||
2630 | file position, without changing it; | ||
2631 | the call \verb|seek(file, "set")| sets the position to the | ||
2632 | beginning of the file (and returns 0); | ||
2633 | and the call \verb|seek(file, "end")| sets the position to the | ||
2634 | end of the file, and returns its size. | ||
2635 | |||
2604 | \subsubsection*{\ff \T{tmpname ()}}\Deffunc{tmpname} | 2636 | \subsubsection*{\ff \T{tmpname ()}}\Deffunc{tmpname} |
2605 | 2637 | ||
2606 | This function returns a string with a file name that can safely | 2638 | Returns a string with a file name that can safely |
2607 | be used for a temporary file. | 2639 | be used for a temporary file. |
2608 | The file must be explicitly removed when no longer needed. | 2640 | The 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 | ||
2612 | This function reads the file \verb|_INPUT|, | 2644 | Reads file \verb|_INPUT|, |
2613 | or from \verb|filehandle| if this argument is given, | 2645 | or \verb|filehandle| if this argument is given, |
2614 | according to a read pattern, which specifies how much to read; | 2646 | according to a read pattern, which specifies how much to read; |
2615 | characters are read from the input file until | 2647 | characters are read from the input file until |
2616 | the read pattern fails or ends. | 2648 | the 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 | ||
2665 | This function writes the value of each of its arguments to the | 2697 | Writes the value of each of its arguments to |
2666 | file \verb|_OUTPUT|, | 2698 | file \verb|_OUTPUT|, |
2667 | or to \verb|filehandle| if this argument is given, | 2699 | or to \verb|filehandle| if this argument is given. |
2668 | The arguments must be strings or numbers. | 2700 | The arguments must be strings or numbers. |
2669 | To write other values, | 2701 | To write other values, |
2670 | use \verb|tostring| or \verb|format| before \verb|write|. | 2702 | use \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 | ||
2676 | This function returns a string containing date and time | 2708 | Returns a string containing date and time |
2677 | formatted according to the given string \verb|format|, | 2709 | formatted according to the given string \verb|format|, |
2678 | following the same rules of the ANSI C function \verb|strftime|. | 2710 | following the same rules of the ANSI C function \verb|strftime|. |
2679 | When called without arguments, | 2711 | When 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 | ||
2685 | This function returns an approximation of the amount of CPU time | 2717 | Returns an approximation of the amount of CPU time |
2686 | used by the program, in seconds. | 2718 | used 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 | ||
2690 | This function calls the C function \verb|exit|, | 2722 | Calls the C function \verb|exit|, |
2691 | with an optional \verb|code|, | 2723 | with an optional \verb|code|, |
2692 | to terminate the program. | 2724 | to terminate the program. |
2693 | The default value for \verb|code| is 1. | 2725 | The default value for \verb|code| is 1. |