motto

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

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Copyright 2014 dong<ddliuhb@gmail.com>. Licensed under the MIT license.

Motto - Modular Javascript environment.

Copyright 2014 dong<ddliuhb@gmail.com>. Licensed under the MIT license.

Motto - Modular Javascript environment.

Copyright 2014 dong<ddliuhb@gmail.com>. Licensed under the MIT license.

Motto - Modular Javascript environment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddModule

func AddModule(id string, m ModuleLoader)

AddModule registers global module

func AddPath

func AddPath(paths ...string)

AddPath registers global path.

func FindFileModule

func FindFileModule(name, pwd string, paths []string) (string, error)

Find a file module by name.

If name starts with "." or "/", we search the module in the according locations (name and name.js and name.json).

Otherwise we search the module in the "node_modules" sub-directory of "pwd" and "paths"

It basicly follows the rules of Node.js module api: http://nodejs.org/api/modules.html

Types

type ModuleLoader

type ModuleLoader func(*Motto) (otto.Value, error)

ModuleLoader is declared to load a module.

func CreateLoaderFromFile

func CreateLoaderFromFile(filename string) ModuleLoader

Create module loader from javascript file.

Filename can be a javascript file or a json file.

func CreateLoaderFromSource

func CreateLoaderFromSource(source, pwd string) ModuleLoader

Create module loader from javascript source code.

When the loader is called, the javascript source is executed in Motto.

"pwd" indicates current working directory, which might be used to search for modules.

func Module

func Module(id string) ModuleLoader

Module returns ModuleLoader for a given ID.

type Motto

type Motto struct {
	// Motto is based on otto
	*otto.Otto
	// contains filtered or unexported fields
}

Motto is modular vm environment

func New

func New() *Motto

New creates a new motto vm instance.

func Run

func Run(name string) (*Motto, otto.Value, error)

Run module by name in the motto module environment.

func (*Motto) AddModule

func (m *Motto) AddModule(id string, l ModuleLoader)

AddModule registers a new module to current vm.

func (*Motto) AddPath

func (m *Motto) AddPath(paths ...string)

AddPath adds paths to search for modules.

func (*Motto) Require

func (m *Motto) Require(id, pwd string) (otto.Value, error)

Require a module with cache

func (*Motto) Run

func (m *Motto) Run(name string) (otto.Value, error)

Run a module or file

Jump to

Keyboard shortcuts

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