Closed cyberpwnn closed 1 week ago
It's hard to say exactly without looking at your code. In general it's always going to be easiest to "just evaluate it" if that's possible, i.e. if you can just copy the utility class and paste it into the string you pass into dart_eval. If that doesn't work, which could be for any number of reasons (it uses features that dart_eval doesn't support, it has to modify or read static fields, it imports a bunch of other files that themselves import files and finding all that code to copy into a string for dart_eval would be too hard, etc.) then you can use a bridge or wrapper. I usually just say use a bridge if you need to extend the class, otherwise use a wrapper.
A plugin is just a reusable structure to define bridges/wrappers, if you make a bridge or wrapper you should probably use it, but it doesn't do anything special it just helps you organize the code.
You can specify void in a bridge or wrapper using CoreTypes.voidType
, obviously if you evaluate code directly you can just use void
.
Long story short im using blockly to generate dart code along with my own custom blocks. My custom blocks are simply just calling a callback in the generated code to avoid spending hours on type declaration configs. But im having trouble getting very basic things like variables to work, or async
Theres just a lot of issues im having, i've resulted to heavily modifying the source just to get the eval to stop complaining. But for example:
(i ended up just using a callback to simplify the util class)
var x;
void _r(Function _a) {
x = 3;
_a("k", x);
}
This fails because uninitialized vars are not supported
So i walked the source code to find something to define it with otherwise remove the declaration resulting in
var x = 3;
void _r(Function _a) {
x = 3;
_a("k", x);
}
Which still fails with CompileError: Cannot find value to set: x at unknown (file package:default/main.dart)
What isnt supported here? Its a variable being initialized and then updated later on, whats not supported there?
Also i'd love to support something like this
Future<void> _r(Function _a) async {
_a("a");
await _a("w", 1); // Wait command
_a("c");
}
But im not sure if async is supported, or at least it really diddnt like the async keyword part so maybe then chaining?
Faced the same issue today :(
Issue with setting top-level variables fixed in v0.7.3.
As far as the issue with await
, I need more information. Async/await does work in dart_eval and there are a bunch of tests for it running in CI. It's possible you're doing something else that dart_eval doesn't support.
Closing due to no response
I've read the entire readme and some wiki pages and still dont know how to call a void function from a class in my project. How am i supposed to use this?
I have a utility class which does certain things in it, and im evaluating a method which uses said class. I dont know if im supposed to just evaluate it, make a plugin and hand define each type function etc, or use a bridge? also how do you do void?