Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically generate functions?

Tags:

dart

I want to be able to take a string (with the proper Dart syntax) and convert it into a callable dart function. Is there a way to do that?

For example, I would receive the string,

void test() { print("testing!"); }

And then turn it into a callable function. The reason I want to do this is to be able to download dart files from other servers and call their functions.

like image 649
Austin Salgat Avatar asked Oct 21 '22 18:10

Austin Salgat


1 Answers

Per the dart FAQ, https://www.dartlang.org/support/faq.html#q-is-it-really-a-dynamic-language-if-it-doesnt-have-eval-or-adding-fields-to-a-value-at-run-time

Dart does not currently have an eval() function, nor support runtime compilation of arbitrary strings, though it may in the future.

So, you'll have to make your own VM within dart to do what you want to do.

like image 147
Bandrami Avatar answered Oct 24 '22 01:10

Bandrami