Difference between revisions of "X file:seek"

From GiderosMobile
(Created page with "__NOTOC__ <languages /> '''<translate>Available since</translate>:''' Gideros 2011.6<br/> '''<translate>Class</translate>:''' file<br/> === <transl...")
 
m (Text replacement - "<source" to "<syntaxhighlight")
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[file|file]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/file|file]]<br/>
 
=== <translate>Description</translate> ===
 
<translate>Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence, as follows:
 
  
"set": base is position 0 (beginning of the file);
+
=== Description ===
"cur": base is current position;
+
Sets and gets the file position, measured from the beginning of the file to the position given by offset plus a base specified by the string '''whence'''.
"end": base is end of file;
+
<syntaxhighlight lang="lua">
 +
(number) = file:seek(whence, offset)
 +
</source>
 +
 
 +
 
 +
Possible values for '''whence''':
 +
*"set": base is position 0 (beginning of the file)
 +
*"cur": base is current position
 +
*"end": base is end of file
 +
 
 +
In case of success, function '''seek''' returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error.
  
In case of success, function seek returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error.
 
  
 +
Therefore:
 +
*'''file:seek()''' returns the current file position, without changing it
 +
*'''file:seek("set")''' sets the position to the beginning of the file (and returns 0)
 +
*'''file:seek("end")''' sets the position to the end of the file, and returns its size
  
The default value for whence is "cur", and for offset is 0. Therefore, the call file:seek() returns the current file position, without changing it; the call file:seek("set") sets the position to the beginning of the file (and returns 0); and the call file:seek("end") sets the position to the end of the file, and returns its size.</translate>
+
=== Parameters ===
<source lang="lua">
+
'''whence''': (string) setting the base point for offset '''optional''' (default = "cur")<br/>
(number) = file:seek(whence,offset)
+
'''offset''': (number) offset to set position to '''optional''' (default = 0)<br/>
</source>
+
 
=== <translate>Parameters</translate> ===
+
=== Return values ===
'''whence''': (string) <translate>setting the base point for offset</translate> '''optional'''<br/>
+
'''Returns''' (number) the position in file measured in bytes from the beginning of the file<br/>
'''offset''': (number) <translate>offset to set position to</translate> '''optional'''<br/>
 
=== <translate>Return values</translate> ===
 
'''<translate>Returns</translate>''' (number) <translate>the position in file measured in bytes from the beginning of the file</translate><br/>
 
  
 
{{File}}
 
{{File}}

Latest revision as of 15:32, 13 July 2023

Available since: Gideros 2011.6
Class: file

Description

Sets and gets the file position, measured from the beginning of the file to the position given by offset plus a base specified by the string whence. <syntaxhighlight lang="lua"> (number) = file:seek(whence, offset) </source>


Possible values for whence:

  • "set": base is position 0 (beginning of the file)
  • "cur": base is current position
  • "end": base is end of file

In case of success, function seek returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error.


Therefore:

  • file:seek() returns the current file position, without changing it
  • file:seek("set") sets the position to the beginning of the file (and returns 0)
  • file:seek("end") sets the position to the end of the file, and returns its size

Parameters

whence: (string) setting the base point for offset optional (default = "cur")
offset: (number) offset to set position to optional (default = 0)

Return values

Returns (number) the position in file measured in bytes from the beginning of the file