flight_script 0.0.2 flight_script: ^0.0.2 copied to clipboard
A small flutter compatible embeded scripting language scripting language. Because sometimes you just have to load your function from a database and have it change without a full app rebuild.
A small scripting language to embed in your flutter projects.
Features #
- Lightweight scripting. Define functions. create loops. Assign variables. All the usuals, none of the extras.
- Call dart functions from flight, or call flight from dart.
- Reverse polish syntax
- VM is language agnostic - implement a parser and to implement a new language on the Flight VM
Getting started #
Initializing the interpreter and running a script:
import 'package:flight_script/flight_script.dart';
/// Flight uses a reverse-polish notation. Arguments go before the function call
/// This program is equivalent to print("Hello, Dart!");
const program = """
"Hello, Flight Script!" print()
""";
void main() {
final interpreter = Interpreter();
interpreter.eval(program);
}
Result
[Hello, World!]
Notice that returned values are returned in an array.
Usage #
Take the first n numbers passed by dart:
import 'package:flight_script/flight_script.dart';
/// as well as using dart to call flight, we can use flight to call dart functions
/// and push dart_values to the vm using `bind`
/// dart functions must use the Dart-API - it's similar to Lua's stack (more example to follow)
const program = """
hello_text print()
"Hello from flight!" dart_print()
""";
void main() {
final interpreter = Interpreter();
interpreter.bind("hello_text", "Hello from dart!");
interpreter.bind("dart_print", (VirtualMachine vm) {
print(vm.popString());
});
interpreter.eval(program);
}
Result
Hello from dart!
Hello from flight!
More examples in the examples/
folder.