cmd

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: 6 Imported by: 0

README

cmd GoDoc

Usage

local cmd = require("cmd")
local runtime = require("runtime")

local command = "sleep 1"
if runtime.goos() == "windows" then command = "timeout 1" end

local result, err = cmd.exec(command)
if err then error(err) end
if not(result.status == 0) then error("status") end

Documentation

Overview

Package cmd implements golang cmd functionality for lua.

Index

Examples

Constants

View Source
const (
	// default execution timeout
	Timeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func Exec

func Exec(L *lua.LState) int

Exec(): lua cmd.exec(command) return ({status=0, stdout="", stderr=""}, err)

Example

cmd.exec()

state := lua.NewState()
Preload(state)
runtime.Preload(state)
source := `
local cmd = require("cmd")
local runtime = require("runtime")

local command = "sleep 1"
if runtime.goos() == "windows" then command = "timeout 1" end

local result, err = cmd.exec(command)
if err then error(err) end
print(result.status)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

0

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

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

local cmd = require("cmd")

Types

This section is empty.

Directories

Path Synopsis
glua with preload libs original: https://raw.githubusercontent.com/yuin/gopher-lua/master/cmd/glua/glua.go
glua with preload libs original: https://raw.githubusercontent.com/yuin/gopher-lua/master/cmd/glua/glua.go

Jump to

Keyboard shortcuts

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