-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Passing objects from Rust to the script should be easier #489
Comments
While on this topic of the difficulty locating and invoking arbitrary functions, is it at all possible in Dyon to do this sort of thing to a non-main function? I'm looking for some functionality like Dyon-based event handlers where I can invoke particular functions by name, passing in current state data. Will move this question to another issue if I'm too off-topic. |
Yeah I'm interested in that too, for other projects… :) I think you should be able to add current objects to any function using this code. But I haven't looked into invoking an arbitrary function. Also, would be nice to be able to register arbitrary event handlers from main, including closures, not just named functions. I'm surprised there wasn't much work in this direction, this is a very common use case for any embeddable scripting interpreter… |
So, this is a naive solution: let mut module = Module::new();
error(load_str(&*asset.name, Arc::new(asset.source.clone()), &mut module));
error(self.host.call_str("init", &[], &Arc::new(module.clone()))); |
Notice that it is possible to use the current library. |
@bvssvni: perhaps I'm misunderstanding its application but how would that library interact with a Dyon script I am executing from my Rust code? It would seem that what that library does is essentially create global values which, while acceptable in a scripting language, seems like terribly bad form for Rust. It also claims to be "safe" but I'm unsure in what sense this is meant, since every example of its use references unsafe code. |
I see there's a |
You can you do this: fn main(a: any) {
~ a := a // Set current object.
...
} |
|
OK. Perhaps we could add some features to |
Exactly, that's precisely what I want |
Do you want to try designing this thing? |
Hi. I'm currently working on a little tool that uses Dyon as a scripting engine. I have an existing Rust object that needs to be passed to the script. This is what I came up with to add a current object to main:
Would be nice to have an easier method to do this. Without importing
range
, pushing to three runtime stacks, explicitly findingmain
…UPDATE: published the initial commit of the project! This thing has been extracted into a macro there. Would be nice to see macros like these in dyon itself…
The text was updated successfully, but these errors were encountered: