jsre

package
v0.9.23 Latest Latest
Warning

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

Go to latest
Published: May 21, 2015 License: LGPL-2.1-or-later Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSRE

type JSRE struct {
	// contains filtered or unexported fields
}

JSRE is a generic JS runtime environment embedding the otto JS interpreter. It provides some helper functions to - load code from files - run code snippets - require libraries - bind native go objects

func New

func New(assetPath string) *JSRE

runtime must be stopped with Stop() after use and cannot be used after stopping

func (*JSRE) Bind

func (self *JSRE) Bind(name string, v interface{}) (err error)

assigns value v to a variable in the JS environment

func (*JSRE) Compile

func (self *JSRE) Compile(fn string, src interface{}) error

compiles and then runs a piece of JS code

func (*JSRE) Eval

func (self *JSRE) Eval(code string) (s string, err error)

evaluates JS function and returns result in a pretty printed string format

func (*JSRE) Exec

func (self *JSRE) Exec(file string) error

Exec(file) loads and runs the contents of a file if a relative path is given, the jsre's assetPath is used

func (*JSRE) Get

func (self *JSRE) Get(ns string) (otto.Value, error)

returns the value of a variable in the JS environment

func (*JSRE) PrettyPrint

func (self *JSRE) PrettyPrint(v interface{}) (val otto.Value, err error)

uses the "prettyPrint" JS function to format a value

func (*JSRE) Run

func (self *JSRE) Run(code string) (otto.Value, error)

runs a piece of JS code

func (*JSRE) Set

func (self *JSRE) Set(ns string, v interface{}) error

assigns value v to a variable in the JS environment

func (*JSRE) Stop

func (self *JSRE) Stop(waitForCallbacks bool)

stops the event loop before exit, optionally waits for all timers to expire

func (*JSRE) ToVal

func (self *JSRE) ToVal(v interface{}) otto.Value

creates an otto value from a go type (non-serialized version)

func (*JSRE) ToValue

func (self *JSRE) ToValue(v interface{}) (otto.Value, error)

creates an otto value from a go type (serialized version)

Jump to

Keyboard shortcuts

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