Nasal library/io: Difference between revisions

Jump to navigation Jump to search
→‎open(): Finish table
(→‎open(): More doc)
(→‎open(): Finish table)
Line 107: Line 107:
|syntax = io.open(path[, mode]);
|syntax = io.open(path[, mode]);
|text = Opens the file with the specified mode and returns an <code>iofile</code> ghost object representing the file.
|text = Opens the file with the specified mode and returns an <code>iofile</code> ghost object representing the file.
{{{!}} class="wikitable"
! Character !! Meaning
{{!-}}
{{!}} <code>r</code>
{{!}} Opens a file for input (reading) operations. The file must exist.
{{!-}}
{{!}} <code>w</code>
{{!}} Creates a new file for output (writing) operations. If the file already exists, its contents will be cleared first.
{{!-}}
{{!}} <code>a</code>
{{!}} Opens a file for appending data. The file is created if it does not exist.
{{!-}}
{{!}} <code>r+</code>
{{!}} Open for input and output operations. The file must exist.
{{!-}}
{{!}} <code>w+</code>
{{!}} Creates a new file for input and output operations. If the file already exists, its contents will be cleared first.
{{!-}}
{{!}} <code>a+</code>
{{!}} Opens a file for input and output operations. Output operations will append data to the end of the file. Input operations are affected by {{func link|seek}}, but output operations will move the position back to the end of the file. The file is created if it does not exist.
{{!-}}
{{!}} <code>rb</code>
{{!}} Opens a file for input operations, treating it as a binary file. The file must exist. '''Default mode'''.
{{!-}}
{{!}} <code>wb</code>
{{!}} Creates a new file for output operations, treating it as a binary file. If the file already exists, its contents will be cleared first.
{{!-}}
{{!}} <code>ab</code>
{{!}} Opens a file for appending data, treating it as a binary file. The file is created if it does not exist.
{{!-}}
{{!}} <code>r+b</code> ''or'' <code>rb+</code>
{{!}} Open for input and output operations, treating it as a binary file. The file must exist.
{{!-}}
{{!}} <code>w+b</code> ''or'' <code>wb+</code>
{{!}} Creates a new file for input and output operations, treating it as a binary file. If the file already exists, its contents will be cleared first.
{{!-}}
{{!}} <code>a+b</code> ''or'' <code>ab+</code>
{{!}} Opens a file for input and output operations, treating it as a binary file. Output operations will append data to the end of the file. Input operations are affected by {{func link|seek}}, but output operations will move the position back to the end of the file. The file is created if it does not exist.
{{!}}}
|param1 = path
|param1 = path
|param1text = Full path to the file as a string.
|param1text = Full path to the file as a string.
Line 113: Line 152:
|example1 =  
|example1 =  
}}
}}
{| class="wikitable"
! String !! Meaning
|-
| <code>r</code> || Opens a file for input (reading) operations. The file must exist.
|-
| <code>w</code> || Creates a new file for output (writing) operations. If the file already exists, its contents will be cleared first.
|-
| <code>a</code> || Opens a file for appending data. The file is created if it does not exist.
|-
| <code>r+</code> || Open for input and output operations as a text file. The file must exist.
|-
| <code>w+</code> || Creates a new file for input and output operations. If the file already exists, its contents will be cleared first.
|-
| <code>a+</code> || Opens a file for input and output operations. Output operations will append data to the end of the file. Input operations are affected by {{func link|seek}}, but output operations will move the position back to the end of the file. The file is created if it does not exist.
|}


=== read(filehandle, buf, len) ===
=== read(filehandle, buf, len) ===

Navigation menu