d4rt
0.2.6, released 4 weeks ago by an unverified publisher
An interpreter and runtime for executing Dart code dynamically.
What it does
d4rt is a Dart-written interpreter and runtime that allows you to execute Dart code dynamically in your applications. It includes AST caching, execution limits, code introspection, and a security sandboxing system.
AI-written summary of version 0.2.6, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to execute user-provided or dynamically loaded Dart code at runtime.
- You want to build scripting or plugin systems within your Dart/Flutter application.
- You require execution limits and sandboxing to restrict dangerous operations like filesystem or network access.
Skip it when
- You are looking for standard ahead-of-time (AOT) or just-in-time (JIT) compilation for performance-critical production code.
- You do not need dynamic script interpretation or runtime code evaluation.
Strengths
- Full generics support and runtime type validation
- Security sandboxing with permission-based module restrictions
- Precompiled scripts and AST caching for better performance
Weaknesses
- Interpreted code execution is inherently slower than native compiled code
- Certain advanced native interactions require specific permission grants
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 4
Add d4rt to pubspec.yaml and configure security permissions via code if executing restricted operations.
import 'package:d4rt/d4rt.dart';
void main() {
final code = '''
int fib(int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
main() {
return fib(6);
}
''';
final interpreter = D4rt();
final result = interpreter.execute(source: code);
print('Result: $result'); // Result: 8
}Alternatives
Packages that do the same job and could replace d4rt.
- io
Utilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
88Compare - async_extension
Dart async extensions for Future, FutureOr, and performance improvements.
74Compare - dart_eval
A flexible Dart bytecode compiler and interpreter for dynamic execution and code push.
72Compare - antlr4
Dart runtime libraries for ANTLR 4 parser generator.
50Compare
Works with
Packages commonly used together with d4rt: ones it builds on, ones built on it, and its own family.
- analyzerd4rt depends on itPerforms static analysis of Dart code for tool integration and embedding.
- buildd4rt depends on itPackage for authoring build_runner compatible code generators.
- source_gend4rt depends on itSource code generation builders and utilities for the Dart build system.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.