Documentation
¶
Overview ¶
Package ioutil implements golang package ioutil functionality for lua.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Preload ¶
Preload adds ioutil to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:
local ioutil = require("ioutil")
func ReadFile ¶
ReadFile lua ioutil.read_file(filepath) reads the file named by filename and returns the contents, returns (string,error)
Example ¶
ioutil.read_file(filepath)
state := lua.NewState()
Preload(state)
source := `
local file = io.open("./test/file.data", "w")
file:write("content of test file", "\n")
file:close()
local ioutil = require("ioutil")
local result, err = ioutil.read_file("./test/file.data")
if err then error(err) end
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: content of test file
func WriteFile ¶
WriteFile lua ioutil.write_file(filepath, data) reads the file named by filename and returns the contents, returns (string,error)
Example ¶
ioutil.write_file(filepath)
state := lua.NewState()
Preload(state)
source := `
local ioutil = require("ioutil")
local err = ioutil.write_file("./test/file.data", "content of test file")
if err then error(err) end
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.