Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new file in Lua/LuaFileSystem

Tags:

lua

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.

like image 600
Shane Gadsby Avatar asked Jul 31 '11 12:07

Shane Gadsby


1 Answers

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

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

See also: Lua IO tutorial

like image 138
miku Avatar answered Sep 25 '22 03:09

miku