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

Ability to call CompiledFunction from Callable #94

Closed
kcsampson opened this issue Feb 10, 2019 · 5 comments
Closed

Ability to call CompiledFunction from Callable #94

kcsampson opened this issue Feb 10, 2019 · 5 comments

Comments

@kcsampson
Copy link

I want to supply a Callable to my script via Indexable. But I want the arg to my Callable to be a func() declared in the script. The func() comes to the script as "*CompiledFunction". But I have no way to call the compiled function. My use case is to implement things like map/reduce, where the script is declaring lambda's.

`

`

@d5
Copy link
Owner

d5 commented Feb 11, 2019

This is one of the things that I wanted to implement earlier, but, invoking compiled functions from native Go code is a bit challenging. Maybe not in the near term, but, I will definitely revisit this feature in the future version. I know that's not what you wanted, but, you can always write map/reduce functions in Tengo and use them via modules, if that works.

@kcsampson
Copy link
Author

Thanks, I'll give it a try. Perhaps I'll fork it and give it a go. I'll need to do that since "machine" is private to a Compiled.
Can I create a second machine, and run the function on that? how would I copy symbol table?

@d5
Copy link
Owner

d5 commented Feb 11, 2019

I'd say writing map/reduce functions in a module is better, but, if you want to experiment with running compiler/VM directly, my recommendation is to look at script.Script and script.Compiled code to see how they manage symbol table and global variables. More specifically this and this could be good starting points.

@mccolljr
Copy link
Contributor

@kcsampson this functionality is now available in the tengo2 branch. The Callable interface and CallableFunc signatures have changed, so you might need to update your code to support that, but you will be able to call back to tengo code from go code provided you make the call from the same goroutine the VM is running on.

@antmanler
Copy link

I'd like to know when this feature will be merged @mccolljr

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

4 participants