Io.open: Difference between revisions

From GiderosMobile
No edit summary
redone
Line 1: Line 1:
__NOTOC__
__NOTOC__
<languages />
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[io]]<br/>


'''<translate>Available since</translate>:''' Gideros 2011.6
=== Description ===
<br/>
This function opens a file in the specified mode. The function returns a new file handle, or nil plus an error message.
'''<translate>Class</translate>:''' [[Special:MyLanguage/io|io]]
<source lang="lua">
<br/>
(file) = io.open(filename, mode)
</source>


=== <translate>Description</translate> ===
<translate>This function opens a file, in the mode specified in the string mode. It returns a new file handle, or, in case of errors, nil plus an error message.</translate>
<br/>


The mode string can be any of the following:
The '''mode''' string can be any of the following:
<br/>
*"r": read mode (the default)
<br/>
*"w": write mode
"r": read mode (the default);
*"a": append mode
<br/>
*"r+": update mode, all previous data is preserved
"w": write mode;
*"w+": update mode, all previous data is erased
<br/>
*"a+": append update mode, previous data is preserved, writing is only allowed at the end of file
"a": append mode;
<br/>
"r+": update mode, all previous data is preserved;
<br/>
"w+": update mode, all previous data is erased;
<br/>
"a+": append update mode, previous data is preserved, writing is only allowed at the end of file.
<br/>
<br/>


<translate>The mode string can also have a 'b' at the end, which is needed in some systems to open the file in binary mode.
The '''mode''' string can also have a ''''b'''' at the end, which is needed in some systems to open the file in binary mode.
<br/>
 
This string is exactly what is used in the standard C function fopen.</translate>
This string is exactly what is used in the standard C function fopen.
<br/>
<source lang="lua">
(file) = io.open(filename,mode)
</source>


=== <translate>Parameters</translate> ===
=== Parameters ===
'''filename''': (string) <translate>filename to open</translate> <br/>
'''filename''': (string) filename to open<br/>
'''mode''': (string) <translate>mode in which to open the file</translate> '''optional'''<br/>
'''mode''': (string) mode in which to open the file '''optional''' (default = "r")<br/>


=== <translate>Return values</translate> ===
=== Return values ===
'''<translate>Returns</translate>''' (file) <translate>file object</translate><br/>
'''Returns''' (file) file object<br/>


{{Io}}
{{Io}}

Revision as of 05:04, 7 December 2020

Available since: Gideros 2011.6
Class: io

Description

This function opens a file in the specified mode. The function returns a new file handle, or nil plus an error message.

(file) = io.open(filename, mode)


The mode string can be any of the following:

  • "r": read mode (the default)
  • "w": write mode
  • "a": append mode
  • "r+": update mode, all previous data is preserved
  • "w+": update mode, all previous data is erased
  • "a+": append update mode, previous data is preserved, writing is only allowed at the end of file

The mode string can also have a 'b' at the end, which is needed in some systems to open the file in binary mode.

This string is exactly what is used in the standard C function fopen.

Parameters

filename: (string) filename to open
mode: (string) mode in which to open the file optional (default = "r")

Return values

Returns (file) file object