Skip to content

How to keep Risor state between different Eval() #290

Answered by gmelchett
gmelchett asked this question in Q&A
Discussion options

You must be logged in to vote

Had a look in: cmd/risor/repl/repl.go and got a short example working (error checks removed):

func main() {
        cfg := risor.NewConfig()
        ctx := context.Background()

        c, _ := compiler.New(cfg.CompilerOpts()...)

        ast, _ := parser.Parse(ctx, "a := 5; b := 6; c := 4; func value() { 77 }")
        code, _ := c.Compile(ast)

        vm := vm.New(code, cfg.VMOpts()...)

        vm.Run(ctx)

        ast, _ = parser.Parse(ctx, "print(b); print(value())")
        c.Compile(ast)

        vm.Run(ctx)
}

It seems to be working, but I have no idea how print(b); print(value()) gets loaded into the vm. Perhalps via ctx?

Well, I'm satisified, but IMHO Risor would benefit for a …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gmelchett
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant