

The filename is where the file is, and the mode is listed in the table below (or following the same mode as in C for fopen). When you exit the program, the file should close as well, but that’s considered poor practice. Your workflow will typically involve opening a file, doing whatever with it, then explicitly closing it. Open and Closeīefore we get into either reading or writing, we need to discuss opening and closing files. Because of this, you rarely need to use a Unicode library except for more specific use cases. This means that all strings are treated effectively as binary data rather than any kind of encoding. The I/O library works with both text and binary files.

Lua has plenty of builtin features to handle this via the I/O Library. So far, we’ve learned a lot about working with data within a program, and how to include more Lua into a program, but not how to import and export data from a file.
