Syntax
local file = assert(io.open("notes.txt", "w"))
file:write("Hello\n")
file:close()Examples
Lua io library example
A focused example you can adapt while practising.
local file = assert(io.open("notes.txt", "w"))
file:write("Hello\n")
file:close()Best practices
- Start with the smallest working example, then adapt it to your project.
- Use the language’s standard library and idioms before introducing extra dependencies.
At a glance
- Purpose
- Lightweight scripting and embedding
- File extension
- .lua
- Runs in
- Lua interpreter or a host application
- Usually used with
- Host APIs and Lua modules
Specifications & further reading
Related Lua documentation
Lua Modules
Lua modules typically return a table of public functions and values. require loads a module and returns the value it exported, caching it for later requests.Lua require
Lua reference for lua require.Lua dofile and loadfile
Lua reference for lua dofile and loadfile.Lua os library
Lua reference for lua os library.
Lua modules typically return a table of public functions and values. require loads a module and returns the value it exported, caching it for later requests.Lua require
Lua reference for lua require.Lua dofile and loadfile
Lua reference for lua dofile and loadfile.Lua os library
Lua reference for lua os library.