Documentation
¶
Overview ¶
ottox is a series of plugins for the Otto Go JavaScript parser and interpreter.
Index ¶
- func Exist(runtime *otto.Otto, name string) bool
- func NewReader(runtime *otto.Otto, methodName string, reader io.Reader) error
- func NewWriter(runtime *otto.Otto, methodName string, writer io.Writer) error
- func RegisterMethodFileOpen(runtime *otto.Otto, methodName string) error
- func SetOnce(runtime *otto.Otto, name string, value interface{}) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReader ¶
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 ¶
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 ¶
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 ¶
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.