Skip to content

Pass globals to loaded scripts #36

@pgundlach

Description

@pgundlach

Is it possible to pass globals to loaded scripts?

My code (main.go):

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/1set/starlight"
)

func dothings() error {
	globals := map[string]interface{}{
		"A": func(in string) { fmt.Println(in) },
	}
	wd, err := os.Getwd()
	if err != nil {
		return err
	}

	c := starlight.New(wd)
	_, err = c.Run("main.star", globals)
	return err
}

func main() {
	if err := dothings(); err != nil {
		log.Fatal(err)
	}
}

the file main.star:

load("script.star","foo")
foo()

and script.star:

def foo():
    A("hello")

The goal is to define the globals once and then access in the loaded scripts . Is this possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions