code

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Contains all the types/functions to do with running scripts/callbacks as well as a map of all the SupportedLang(s).

These are mostly internally used functions and types and due to its imports.

How it works

When calling json_map.JsonMapInt.FindScriptFields, each script/callback will be replaced by a value of Code type in the jom.Traversal field within jom.JsonMap. The code.Run function can be used to execute a code.Code object of any supported type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIfSupported

func CheckIfSupported(scriptLang string) bool

Checks if the given script language suffix is a supported language.

This just checks the supportedLangs variable.

func RegisterLang

func RegisterLang(shebangName string, runCode func(code Code, jsonMap json_map.JsonMapInt) (data json_map.JsonMapInt, err error)) bool

Registers a new SupportedLang to the supportedLangs map. Every supported language package should call this within their init().

func Run

func Run(code Code, jsonMap json_map.JsonMapInt) (data json_map.JsonMapInt, err error)

Run the given Code in the given Code environment. Returns a json_map.JsonMapInt containing the updated scope, and a non-nil error if an error has occurred, otherwise err will be nil.

Types

type Code

type Code struct {
	// The script/callback which can be run in either a VM of the language's type/in Go if it is a callback.
	Script interface{}
	// The script's language which determines what it will be run inside.
	ScriptLang ScriptLangType
}

Wrapper for any "runnable" script/callback.

func NewFrom

func NewFrom(from interface{}) (code Code, ok bool)

Creates a new Code object from the given string source code (must include shebang) or a func(json json_map.JsonMapInt). If the given value is not one of these an empty Code object will be returned and ok will be false. If the given value is a string the following will happen:

• Checking the first line of the string and seeing if it starts with the ShebangPrefix and ends with one of the supported languages.

• Panics if the shebang fits the required length for a shebang but is not a supported script language.

• ok is true if the script does contain a json-dom script, false otherwise.

If the given value is a func(json json_map.JsonMapInt) then there will be no checks as a function callback will be run rather than a script in a virtual environment.

func (*Code) ScriptLangShebang

func (code *Code) ScriptLangShebang() string

Gets all the shebang suffixes for the given ScriptLangType.

func (*Code) String

func (code *Code) String() string

Uses globals.ScriptErrorFormatString to return a string with both the script and the script language.

type ScriptLangType

type ScriptLangType int
const (
	JS ScriptLangType = iota
	GO ScriptLangType = iota
)

Script language types which are used for printing errors/determining script language type.

Note: This does not mean that all constants are supported by json-dom.

func ShebangScriptLang

func ShebangScriptLang(shebang string) ScriptLangType

Gets the ScriptLangType of the given shebang suffix.

type SupportedLang

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

Describes a language which is supported (can be run) from within a JOM.

Directories

Path Synopsis
Contains runner for native Go callbacks within JOM.
Contains runner for native Go callbacks within JOM.
Contains runner and getter/setter functions for the execution of JS scripts within an otto.Otto VM.
Contains runner and getter/setter functions for the execution of JS scripts within an otto.Otto VM.

Jump to

Keyboard shortcuts

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