ostdlib

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

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

Go to latest
Published: Oct 20, 2016 License: BSD-3-Clause Imports: 17 Imported by: 5

README

This project has been depreciated as the JavaScript implementations common in web browsers and NodeJS (ES6) have are diveraging from the implementation provided for in Otto (ES5). Otto remains under active developement (as Oct 2016) and the need for this library has deminished as a result even where ES5 support remains desirable.

Go Report Card

ostdlib

Standard JavaScript objects and functions for use when embedding Otto. Also provides a standard REPL experience if desired.

Documentation

Overview

Package ostdlib is a collection of JavaScript objects, functions and polyfill for standardizing embedding Robert Krimen's Otto JavaScript Interpreter.

@author R. S. Doiel, <rsdoiel@caltech.edu>

Copyright (c) 2016, Caltech All rights not granted herein are expressly reserved by Caltech.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const Version = "0.0.7"

Version of the Otto Standard Library

Variables

View Source
var (
	// Workbookfill wraps the xlsx object to provide a more wholistic worbook experience
	Workbookfill = `` /* 1308-byte string literal not displayed */

	// Polyfill addes missing functionality implemented in JavaScript rather than Go
	Polyfill = `` /* 8415-byte string literal not displayed */

)

Functions

func ToStruct

func ToStruct(value otto.Value, aStruct interface{}) error

ToStruct will attempt populate a struct passed in as a parameter.

ToStruct returns an error if it runs into a problem.

Example: a := struct{One int, Two string}{} val, _ := vm.Run(`(function (){ return {One: 1, Two: "two"}}())`) _ := ToSruct(val, &a) fmt.Printf("One: %d, Two: %s\n", a.One, a.Two)

Types

type HelpMsg

type HelpMsg struct {
	XMLName  xml.Name `xml:"HelpMsg" json:"-"`
	Object   string   `xml:"object" json:"object"`
	Function string   `xml:"function" json:"function"`
	Params   []string `xml:"parameters" json:"parameters"`
	Msg      string   `xml:"docstring" json:"docstring"`
}

HelpMsg supports storing interactive help content

type JavaScriptVM

type JavaScriptVM struct {
	VM                *otto.Otto
	AutoCompleter     *readline.PrefixCompleter
	AutoCompleteTerms []string              `xml:"autocomplete_terms" json:"autocomplete_terms"`
	Help              map[string][]*HelpMsg `xml:"help" json:"help"`
}

JavaScriptVM is a wrapper for *otto.Otto to make it easy to add features without forking Otto.

func New

func New(vm *otto.Otto) *JavaScriptVM

New create a new JavaScriptVM structure extending the functionality of *otto.Otto

func (*JavaScriptVM) AddAutoComplete

func (js *JavaScriptVM) AddAutoComplete()

AddAutoComplete populates the auto completion based on the help data structure

func (*JavaScriptVM) AddExtensions

func (js *JavaScriptVM) AddExtensions() *otto.Otto

AddExtensions takes an exisitng *otto.Otto (JavaScript VM) and adds os and http objects wrapping some Go native packages

func (*JavaScriptVM) AddHelp

func (js *JavaScriptVM) AddHelp()

AddHelp adds the interactive help based on the extensions defined in ostdlib

func (*JavaScriptVM) Eval

func (js *JavaScriptVM) Eval(script string) (otto.Value, error)

Eval evaluate some JavaScript source code

func (*JavaScriptVM) GetHelp

func (js *JavaScriptVM) GetHelp(objectName, functionName string)

GetHelp retrieves help text by object and function names

func (*JavaScriptVM) PrintDefaultWelcome

func (js *JavaScriptVM) PrintDefaultWelcome()

PrintDefaultWelcome display default weclome message based on JavaScriptVM.HelpMsg

func (*JavaScriptVM) Repl

func (js *JavaScriptVM) Repl()

Repl provides interactive JavaScript shell supporting autocomplete and command history

func (*JavaScriptVM) Run

func (js *JavaScriptVM) Run(fname string) error

Run executes a specific JavaScirpt file

func (*JavaScriptVM) Runner

func (js *JavaScriptVM) Runner(filenames []string)

Runner given a list of JavaScript filenames run the files

func (*JavaScriptVM) SetHelp

func (js *JavaScriptVM) SetHelp(objectName string, functionName string, params []string, text string)

SetHelp adds help documentation by object and function

Directories

Path Synopsis
cmds

Jump to

Keyboard shortcuts

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