Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WhiredPlanck opened this issue Nov 2, 2024 · 0 comments
Open

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

WhiredPlanck opened this issue Nov 2, 2024 · 0 comments

Comments

@WhiredPlanck
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant