Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart, how to parse user string into functional dart code?

is it possible to parse in a user entered string, say from a text area, and then incorporate it into a dart function which you can then run, without having to post it back to the server? I guess I'm looking for a dart eval equivalent.

like image 505
Daniel Robinson Avatar asked Sep 16 '13 14:09

Daniel Robinson


People also ask

How do you parse a Dart string?

A string can be cast to an integer using the int. parse() method in Dart. The method takes a string as an argument and converts it into an integer.

How do you parse a string in flutter?

Parse a String into an int in Dart/Fluttertry { var n = int. parse('n42'); print(n); } on FormatException { print('Format error! '); } // Format error! int class parse() method also gives us a way to handle FormatException case with onError parameter.

How do you convert a string to a double Dart?

For converting a String to a double, the parse() static method of double class can be used. String source, [@deprecated double onError(String source)?] );


1 Answers

There is no notion of eval in Dart, and it is not possible to dynamically build code. You can run code in a different isolate using spawnUri (see http://api.dartlang.org/docs/releases/latest/dart_isolate.html). When not running in the Dartium browser, note that the Dart code needs to be compiled to JavaScript using dart2js. The site http://try.dartlang.org/ does all that.

Some time in the future Dart might get mirror builders which can be used for "programs to extend and modify themselves" (citation from last paragraph in https://www.dartlang.org/articles/reflection-with-mirrors/).

like image 89
sgjesse Avatar answered Sep 20 '22 17:09

sgjesse