ethanblake4 / dart_eval

Extensible Dart interpreter for Dart with full interop
https://pub.dev/packages/dart_eval
BSD 3-Clause "New" or "Revised" License
334 stars 40 forks source link

Book bridge example (not yet working) #161

Open BenVercammen opened 10 months ago

BenVercammen commented 10 months ago

@ethanblake4 Could you please have a look at this example? I've tried to reconstruct the Book bridge example from the README.md file, but get the following error:

dart_eval runtime exception: type 'List<$Value>' is not a subtype of type 'List<String>'

ethanblake4 commented 10 months ago

Was an error with the example, will be updated in next release.

You can change the $new function in the $Book$bridge class to the following to fix:

static $Value? $new(
  Runtime runtime, $Value? target, List<$Value?> args) {
  return $Book$bridge((args[0]!.$reified as List).cast());
}
BenVercammen commented 10 months ago

@ethanblake4 A new question.. I'd like to modify the list in the program, but the new pages don't show up in the bridged class. I suppose that the problem lies in my $getProperty method, but I'm not sure where to get the actual value from... Could you shed some light on this please?

ethanblake4 commented 10 months ago

That specific use case isn't really supported with the built-in $List class currently. I created an issue to track it. You could make a custom $List wrapper that supports writeback via a type-mapper function, but if you want to do this now I'd suggest just making an addPage function or similar.

ethanblake4 commented 9 months ago

This is now supported in v0.7.5 using the new $List.view() constructor