Class FileTable

Table that is synchronized with a specific file.

Usage:

     local config = FileTable:New("config.lua")
     config.__comment = "Configuration of the program"
    
     -- prints the last time the program was executed
     print(os.date("*t", config.lastRunTime))
    
     -- stores the current time for next time
     config.lastTime = os.time()
     -- no further actions are necessary, the file is saved immediately

Functions

FileTable:New (path) Creates a new instance of a FileTable mapped to the specified file.

Tables

FileTable Whenever any assignment is made to this table, it is immediatelly written to the associated file.

Methods

FileTable:Flush () Forces the writing of the file.
FileTable:Pairs () Replacement to using the regular pairs method.


Functions

FileTable:New (path)
Creates a new instance of a FileTable mapped to the specified file.

Remarks:

    The file cannot access any of the standard functions, as its envorinmont is overriden to be an empty table. That makes it safe, as it cannot access parts of a code it shouldn't touch, but it also isn't capable of using any standard functions -- meaning it has to be pure data.

Parameters:

  • path path within the VFS corresponding to a Lua data file

Returns:

    FileTable

Tables

FileTable
Whenever any assignment is made to this table, it is immediatelly written to the associated file.

Fields:

  • __comment String that should be used as a comment on the beggining of the file.
  • ... anything not containing cycles

Methods

FileTable:Flush ()
Forces the writing of the file.

Remarks:

    It should usually not be necessary to call this method as the file gets saved whenever any change occurs. It might only be needed if the file holds nested tables and a change occurs there.
FileTable:Pairs ()
Replacement to using the regular pairs method. This is necessary as one could otherwise not iterate over the keys due to the way FileTable is internally implemented.
generated by LDoc 1.4.3 Last updated 2017-06-01 23:07:48