Home Explore Blog CI



neovim

71th chunk of `runtime/doc/luaref.txt`
58ad614dc9c82c84bf24d250de7b01bd2992ad9ed49395f00000000100000fa7
 beginning of the file. If this function
        fails, it returns `nil`, plus a string describing the error.

        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.

file:setvbuf({mode} [, {size}])                          *file:setvbuf()*
        Sets the buffering mode for an output file. There are three available
        modes:

         `"no"`    no buffering; the result of any output operation appears
                 immediately.
         `"full"`  full buffering; output operation is performed only when
                 the buffer is full (or when you explicitly `flush` the file
                 (see |io.flush()|).
         `"line"`  line buffering; output is buffered until a newline is
                 output or there is any input from some special files (such as
                 a terminal device).

        For the last two cases, {size} specifies the size of the buffer, in
        bytes. The default is an appropriate size.

file:write({...})                                          *file:write()*
        Writes the value of each of its arguments to `file`. The arguments
        must be strings or numbers. To write other values, use `tostring`
        |tostring()| or `string.format` |string.format()| before
        `write`.

==============================================================================
5.8  Operating System Facilities                                  *lua-lib-os*

This library is implemented through table `os`.

os.clock()                                                          *os.clock()*
        Returns an approximation of the amount in seconds of CPU time used by
        the program.

os.date([{format} [, {time}]])                                       *os.date()*
        Returns a string or a table containing date and time, formatted
        according to the given string {format}.

        If the {time} argument is present, this is the time to be formatted
        (see the `os.time` function |os.time()| for a description of this
        value). Otherwise, `date` formats the current time.

        If {format} starts with `!`, then the date is formatted in
        Coordinated Universal Time. After this optional character, if {format}
        is the string `"*t"`, then `date` returns a table with the following
        fields: `year` (four digits), `month` (1-12), `day` (1-31), `hour`
        (0-23), `min` (0-59), `sec` (0-61), `wday` (weekday, Sunday is 1),
        `yday` (day of the year), and `isdst` (daylight saving flag, a
        boolean).

        If {format} is not `"*t"`, then `date` returns the date as a string,
        formatted according to the same rules as the C function `strftime`.

        When called without arguments, `date` returns a reasonable date and
        time representation that depends on the host system and on the current
        locale (that is, `os.date()` is equivalent to `os.date("%c")`).

os.difftime({t2}, {t1})                                          *os.difftime()*
        Returns the number of seconds from time {t1} to time {t2}. In POSIX,
        Windows, and some other systems, this value is exactly `t2 - t1` .

os.execute([{command}])                                           *os.execute()*
        This function is equivalent to the C function `system`. It passes
        {command} to be executed by an operating system shell. It returns a
        status code, which is system-dependent. If {command} is absent, then
        it returns nonzero if a shell is available and zero otherwise.

os.exit([{code}])                                                    *os.exit()*
        Calls the C function `exit`, with an optional {code}, to terminate

Title: Lua File Buffering, Writing, and OS Facilities: Time, Date, and Execution
Summary
This section covers several functions related to file handling and operating system interactions in Lua. It describes `file:setvbuf` for setting the buffering mode of an output file, `file:write` for writing strings and numbers to a file. It introduces the `os` library, including `os.clock` for CPU time, `os.date` for formatting date and time, `os.difftime` for calculating the time difference between two times, `os.execute` for executing system commands, and `os.exit` for terminating the program.