箭头

用 Dart 编写的脚本语言,旨在通过简洁、干净的 API 嵌入到 Dart 程序中。

语法

语法深受 JavaScript 等语言的影响。

// Line breaks are significant!
// They tell the parser its a new instruction!
// If you want multiple instructions on one line, seperate them with a ;

// Define a local
let name = 5

// This makes name have its value exported into the Exports table of the VM.
// This isn't like a global, the VM doesn't read its exports. Only the embedder is meant to read exports via helper functions.
export name as "name";

// Define a local function
function test() {
  return name
}

// Globalize a variable
global test;

// Set a variable (global or local)
set name = name + 2

// Define a global (set also defines if the global doesnt exist, but this one forcefully uses the global)
global name = "Test"

// This makes the VM itself return some value
return [5, 123, 789]

嵌入

Arrow 非常容易嵌入到 Dart 应用中。

import "package:arrow_lang/arrow_lang.dart";

void main() {
  // Create a VM instance
  final vm = ArrowVM();

  // Load built-in libraries
  vm.loadLibs();

  // Run a file
  final result = vm.runFile(File("code.arrow"));

  // Read a global from the VM
  print(vm.globals.get("Some global"));

  // Modify a global inside of the VM
  vm.globals.set("Some global", ArrowNumber(42));

  // Get an export
  final someExportedValue = vm.exports.get("Some export");
}

您可以查看examples文件夹以了解更多示例。

GitHub

查看 Github