Skip to content

Using Context : How to pass script level variables? #942

@nmondal

Description

@nmondal

In the ScriptEngine paradigm - things were simple.
Create a CompiledScript and ask it to evaluate with Bindings.
Like this:

https://docs.oracle.com/en/java/javase/11/docs/api/java.scripting/javax/script/CompiledScript.html#eval(javax.script.Bindings)

I am wondering in graal - with Context, how to do it?
Admittedly I tried putMember in the Context Binding - it did not work.

context.getBindings("js").putMember("N", 2000);
context.getBindings("js").putMember("EXPECTED", 17393);
context.eval(Source.newBuilder("js", SOURCE, "src.js").build());
Value primesMain = context.getBindings("js").getMember("primesMain");

I am finding myself a bit foolish and clueless here, how to achieve this?

Actually, right now I am using graaljs via ScriptEngine, so this problem is not an issue. But I am planning to migrate all graal powered languages into a much more "Context" based design - and this is blocking nmondal/cowj#148

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions