Skip to content

How to call a method of an object (especially a generator)? #69

@WhiredPlanck

Description

@WhiredPlanck

For example, a generator function like:

function* generator(i) {
    yield i
    yield i + 1
    yield i + 2
}

then eval on context to get Value instance in C++ ... :

Value generatorFunc = context.eval("generator");
Value generator = ((std::function<Value(int)>) generatorFunc)(10);

I've tried:

Value nextFunc = generator["next"];
Value result = ((std::function<Value(void)>) nextFunc)();

but got a TypeError: not a generator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions