gplasma

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: BSD-2-Clause Imports: 3 Imported by: 0

README

plasma

Build codecov GitHub go.mod Go version Go Report Card

Plasma is an embeddable scripting ruby like language.

logo

Features

  • Simple extensibility: Easy to add new go bindings
  • Zero dependency: The language used as a library doesn't depend on any external project.
  • Thread safe: the virtual machine and all the objects created during runtime are thread safe
  • Rich syntax: Generators, defer, special boolean operators and more (check documentation for more details)
  • Bytecode VM backend: the language compiles to a custom bytecode that can then stored and preloaded in the machine without recompiling scripts.
  • Stop vm execution: Plasma let you stop at any the time the execution of the VM.

Documentation

You can find documentation in:

Install interpreter

go install github.com/shoriwe/gplasma/cmd/plasma@latest

Preview

REPL

You can start a REPL with:

plasma

logo

Embedding and creating Go bindings

go get -u github.com/shoriwe/gplasma@v1
package main

import (
	"github.com/shoriwe/gplasma/pkg/vm"
	"os"
)

const myScript = `
args = get_args()
if args.__len__() > 1
    println(args.__string__())
else
    println("No")
end
`

func main() {
	plasma := vm.NewVM(os.Stdin, os.Stdout, os.Stderr)
	plasma.Load("get_args", func(plasma *vm.Plasma) *vm.Value {
		return plasma.NewBuiltInFunction(plasma.Symbols(),
			func(argument ...*vm.Value) (*vm.Value, error) {
				tupleValues := make([]*vm.Value, 0, len(os.Args))
				for _, cmdArg := range os.Args {
					tupleValues = append(tupleValues, plasma.NewString([]byte(cmdArg)))
				}
				return plasma.NewTuple(tupleValues), nil
			})
	})
	_, errorChannel, _ := plasma.ExecuteString(myScript)
	err := <-errorChannel
	if err != nil {
		panic(err)
	}
}

Contributing

To contribute to this project please follow the contribution guidelines and the code of conduct

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(scriptCode string) ([]byte, error)

func NewVM

func NewVM(stdin io.Reader, stdout io.Writer, stderr io.Writer) *vm.Plasma

Types

This section is empty.

Jump to

Keyboard shortcuts

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