goos

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

README

goos GoDoc

Usage

local goos = require("goos")

-- stat
local stat, err = goos.stat("./filename")
if err then error(err) end
print(stat.is_dir)
print(stat.size)
print(stat.mod_time)
print(stat.mode)

-- hostname
local hostname, err = goos.hostname()
if err then error(err) end
print(hostname)

-- get_pagesize
local page_size = goos.get_pagesize()
if not(page_size > 0) then error("bad pagesize") end

-- mkdir_all
goos.mkdir_all("./test/test_dir/test_dir/all")
local stat, err = goos.stat("./test/test_dir/test_dir/all")
if err then error(err) end

Documentation

Overview

Package goos implements golang package os functionality for lua.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Getpagesize

func Getpagesize(L *lua.LState) int

Getpagesize lua goos.pagesize() return number

Example

goos.get_pagesize()

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local goos = require("goos")
local page_size = goos.get_pagesize()
print(page_size > 0)
	`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

true

func Hostname

func Hostname(L *lua.LState) int

Hostname lua goos.hostname() returns (string, error)

Example

goos.hostname()

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local goos = require("goos")
local hostname, err = goos.hostname()
if err then error(err) end
print(hostname > "")
	`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

true

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func MkdirAll

func MkdirAll(L *lua.LState) int

MkdirAll lua goos.mkdir_all() return err

Example

goos.mkdir_all()

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local goos = require("goos")
local err = goos.mkdir_all("./test/test_dir_example/test_dir")
if err then error(err) end
local _, err = goos.stat("./test/test_dir_example/test_dir")
print(err == nil)
	`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

true

func Preload

func Preload(L *lua.LState)

Preload adds goos to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local goos = require("goos")

func Stat

func Stat(L *lua.LState) int

Stat lua goos.stat(filename) returns (table, err)

Example

goos.stat(filename)

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local goos = require("goos")
local inspect = require("inspect")

local info, err = goos.stat("./test/test.file")
if err then error(err) end
info.mode=""
info.mod_time=0
print(inspect(info, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

{is_dir = false,mod_time = 0,mode = "",size = 0}

Types

This section is empty.

Jump to

Keyboard shortcuts

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