core

package
v0.0.0-...-1982c3d Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 17 Imported by: 0

README

core

The directory contains code for Elsa's runtime agnostic. It comes with a simple Go API for developers to embed Elsa applications into their Go code.

Usage

package main

import (
    "github.com/elsaland/elsa/core"
    "github.com/elsaland/elsa/core/options"
)

var source string: = "console.log(1)"

func main() {
    env: = options.Environment {
        NoColor: false, // Set true to disable coloured output
        Args: os.Args[1: ],
    }
    opt: = options.Options {
        SourceFile: "file.js",
        Source: source,
        Perms: & options.Perms {
            Fs: false, // Set true to allow file system access
        },
        Env: env,
    }
    core.Run(opt)
}

Documentation

Overview

Package core lists all the OPS in elsa Will be updated as an when new OPS are added

Index

Constants

View Source
const (
	FSWrite     = 1
	FSRead      = 2
	FSExists    = 3
	FSDirExists = 4
	FSCwd       = 5
	Serve       = 25
	FSStat      = 6
	FSRemove    = 7
	FSMkdir     = 9
	FSWalk      = 14
)

FileSystem ops

View Source
const (
	Env = 11
)

env ops

View Source
const (
	Fetch = 20
)

fetch ops

View Source
const (
	Log = 10
)

console binding ops

View Source
const (
	Plugin = 15
)

plugin ops

Variables

This section is empty.

Functions

func CheckEnv

func CheckEnv(perms *options.Perms)

func CheckFs

func CheckFs(perms *options.Perms)

CheckFs utility to check whether file system access is avaliable or not

func CheckNet

func CheckNet(perms *options.Perms)

CheckNet utility to check whether net access is avaliable or not

func ConsoleLog

func ConsoleLog(ctx *quickjs.Context, value []quickjs.Value) quickjs.Value

ConsoleLog console.log bindings to quickjs engine

func ElsaRecvNS

func ElsaRecvNS(elsa *options.Elsa) func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value

ElsaRecvNS Native function corresponding to the JavaScript global `__recv` It is binded with `__recv` and accepts arguments including recv ID of the async function

func ElsaSendNS

func ElsaSendNS(elsa *options.Elsa) func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value

ElsaSendNS Native function corresponding to the JavaScript global `__send` It is binded with `__send` and accepts arguments including op ID

func Eval

func Eval(text string, buffer *string) string

Eval js from string

func Marshal

func Marshal(jsonObj interface{}) ([]byte, error)

Marshal JSON data with default options

func OpenPlugin

func OpenPlugin(path string, arg interface{}) interface{}

OpenPlugin open a dynamic lib and call the exported ElsaPlugin function with the args provided by the plugin op Currently, not compatible with windows

func PrepareRuntimeContext

func PrepareRuntimeContext(cxt *quickjs.Context, jsruntime quickjs.Runtime, args []string, flags *options.Perms, mode string)

PrepareRuntimeContext prepare the runtime and context with Elsa's internal ops injects `__send` and `__recv` global dispatch functions into runtime

func Repl

func Repl()

Repl implementation

func Run

func Run(opt options.Options)

Run create and dispatch a QuickJS runtime binded with Elsa's OPs configurable using options

Types

type Formatter

type Formatter struct {
	KeyColor        *color.Color
	StringColor     *color.Color
	BoolColor       *color.Color
	NumberColor     *color.Color
	NullColor       *color.Color
	StringMaxLength int
	Indent          int
	DisabledColor   bool
	RawStrings      bool
}

func NewFormatter

func NewFormatter() *Formatter

func (*Formatter) Marshal

func (f *Formatter) Marshal(jsonObj interface{}) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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