ottox

package module
v0.0.0-...-d47a0fb Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2014 License: MIT Imports: 7 Imported by: 0

README

ottox

Plugins for the Otto Go JavaScript parser and interpreter.

IO

Documentation

Overview

ottox is a series of plugins for the Otto Go JavaScript parser and interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exist

func Exist(runtime *otto.Otto, name string) bool

Exist gets whether a variable exists in the runtime or not.

func NewReader

func NewReader(runtime *otto.Otto, methodName string, reader io.Reader) error

NewReader adds a read method to the specified runtime that allows client code to read from the specified reader.

The client function created has the following syntax:

var response = readMethodName(bytesToRead);

Response object:

{
  data: "This was read from the reader.",
  eof: false|true,
  error: error|undefined
}

If eof is false, client code should keep calling the read method until all data has been read.

For example, to stream from the Stdin pipe:

// in go...
NewReader(js, "readStdIn", os.Stdin)

// in a script...
var data = "";
var response = {"eof":false};
while (!response.eof) {
  response = readStdIn(255);
  data += response.data;
}

Passing -1 as the bytesToRead will read the entire contents from the reader immediately.

func NewWriter

func NewWriter(runtime *otto.Otto, methodName string, writer io.Writer) error

NewWriter adds a write method to the specified runtime that allows client code to write to the specified io.Writer.

The client function created has the following syntax:

var response = writeMethodName(contentToWrite)

Response object:

{
  len: bytes_written,
   error: error|undefined
}

func RegisterMethodFileOpen

func RegisterMethodFileOpen(runtime *otto.Otto, methodName string) error

RegisterMethodFileOpen registers a method that is capable of opening files.

Response object:

{
  ok: true|false,
  reader: "readFile" // the method to use to read from the file
}

To read the entire file into a variable:

// in Go...
RegisterMethodFileOpen(js, "openFile")

// in the script...
var file = openFile("filename"); // open the file
var read = eval(file.reader); // get the reader method
var close = eval(file.closer); // get the closer method

var fileContents = read(-1); // read everything
close(); // close the file

func SetOnce

func SetOnce(runtime *otto.Otto, name string, value interface{}) (bool, error)

SetOnce sets a name or value only if it doesn't exist.

Returns whether the value was set or not, or an error if it failed to set it.

For acceptable values, see http://godoc.org/github.com/robertkrimen/otto#Otto.Set

Types

This section is empty.

Jump to

Keyboard shortcuts

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