Create a new file in Lua/LuaFileSystem


I've looked over the Lua & LuaFileSystem Docs and have yet to find a way to create a new file, I also scouted around on here but to the same end.

As a note, the solution I'm looking for has to be OS neutral to ensure portability, but I'm happy to get different answers for different systems.

Best Solution

Example (writing "Hello World" into test.txt):

$ lua
Lua 5.1.4  Copyright (C) 1994-2008, PUC-Rio
> file ="test.txt", "w")
> file:write("Hello World")
> file:close()
> ^D
$ cat test.txt 
Hello World

See also: Lua IO tutorial

Related Question