Search code examples
iolua

Open file mode string w+


I know what io.open(file, "w") does, it indicates writting. However I have encountered io.open(file, "w+") and can't find what "w+" does?


Solution

  • From the reference manual io.open

    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.

    update mode here means, both input and output may be performed on the associated file.