ioutil

package
v0.0.0-...-f7fb57a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 2 Imported by: 0

README

ioutil GoDoc

Usage

local ioutil = require("ioutil")

local file = io.open("./test/file.data", "w")
file:write("content of test file", "\n")
file:close()

-- ioutil.read_file()
local result, err = ioutil.read_file("./test/file.data")
if err then error(err) end
if not(result == "content of test file") then error("ioutil.read_file()") end

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 Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

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

func ReadFile(L *lua.LState) int

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

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL