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

Register and create closure functions #1439

Closed
HalidOdat opened this issue Jul 28, 2021 · 0 comments · Fixed by #1442
Closed

Register and create closure functions #1439

HalidOdat opened this issue Jul 28, 2021 · 0 comments · Fixed by #1442
Assignees
Labels
API enhancement New feature or request execution Issues or PRs related to code execution
Milestone

Comments

@HalidOdat
Copy link
Member

Currently we can only create function that can be coerced into a NativeFunction, this does not allow us to capture variables from a closure. And changing the function signature of NativeFunction to Box<dyn Fn> would be bad for performance reasons, since for every function now we have to allocate. Instead we would have another variant in Function enum Closure that would contain a Box<dyn Fn>

So I propose the following, we add separate functions for closures function creation.

let some_variable = ...
context.register_global_closure("name", move |_, _, _| {
	Ok(some_variable)
});

We would also add a way to create a closure with the FunctionBuilder

@HalidOdat HalidOdat added enhancement New feature or request execution Issues or PRs related to code execution API labels Jul 28, 2021
@HalidOdat HalidOdat added this to the v0.13.0 milestone Jul 28, 2021
@HalidOdat HalidOdat self-assigned this Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant