hetu script

Hetu Script

A lightweight scripting language written in Dart for embedding in Flutter apps.

简体中文页面

Introduction

Hetu is a lightweight scripting language purely written in Dart for embedding in Flutter apps. Our goal is to enable Flutter app & game to have hotfix and scripting ability.

Documentation 中文文档

Features

  • Modern programming language syntax likes typescript/kotlin/swift, need very little time to get familiar with.
  • Full scripting language abilities: class OOP, prototype OOP, FP, module, errors, etc.
  • Runs on all platforms that flutter supports, including web browsers and desktop.
  • Extremely easy on binding, call Dart functions in script or call script functions in Dart with just one line.

Test Hetu script in the online playground.

Quick start

To eval a string literal of Hetu code in Dart.

import 'package:hetu_script/hetu_script.dart';

void main() {
  final hetu = Hetu();
  hetu.init();
  hetu.eval(r'''
    var ht = {
      name: 'Hetu',
      greeting: () {
        print('Greetings from ${this.name}!')
      }
    }
    ht.greeting()
  ''');
}

To pass a Map to script, modify it in script and get it back:

import 'package:hetu_script/hetu_script.dart';

void main() {
  final hetu = Hetu();
  hetu.init(externalFunctions: {
    'hello': () => {'greetings': 'greetings from Dart!'},
  });
  var hetuValue = hetu.eval(r'''
      external fun hello
      var dartValue = hello()
      dartValue['reply'] = 'Hi, this is Hetu.'
      dartValue // the script will return the value of it's last expression
      ''');

  print('hetu value: $hetuValue');
}

You can check the documentation for more information on the grammar and binding.

IDE extension

If you are using VS Code, you can download this extension to get basic highlight and dart snippets on bindings.

Command line tool

We have a command line REPL tool for quick testing. You can activate by the following command:

dart pub global activate hetu_script_dev_tools

Then you can use command line tool 'hetu' in any directory on your computer.

More information about the command line tool can be found by enter 'hetu -h'.

If no arguments is provided, enter REPL mode.

In REPL mode, every exrepssion you entered will be evaluated and print out immediately.

If you want to write multiple line in REPL mode, use '\' to end a line.

>>>var a = 42
null // repl print
>>>a
42 // repl print
>>>fun meaning {\
return a }
null // repl print
>>>meaning
meaning() -> any // repl print
>>>hello()
42 // repl print

You can check this official document for more information on 'pub global activate'.

Discussion group

Discord: https://discord.gg/aJedwcRPr8

中文交流可以加 QQ 群:812529118

Support

You can support my project by simply giving it a star on GitHub.

Or you can buy me a coffee:

Buy me a coffee

Libraries

declaration/function/abstract_parameter
declaration/type/abstract_type_declaration
analyzer/analysis_error
analyzer/analysis_manager
analyzer/analysis_result
analyzer/analyzer
analyzer
analyzer/analyzer_impl
ast/ast
binding
bundler/bundler
bytecode/bytecode_module
bytecode/bytecode_reader
value/instance/cast
value/class/class
binding/class_binding
declaration/class/class_declaration
value/class/class_namespace
bytecode/compiler
source/computer
grammar/constant
value/constant
constant/constant_interpreter
shared/constants
shared/crc32b
declaration/declaration
declaration/namespace/declaration_namespace
declarations
analyzer/diagnostic
bytecode/disassembler
grammar/element
value/entity
error/error
error/error_handler
error/error_severity
errors
type/external
external/external_class
value/external_enum/external_enum
external/external_function
external/external_instance
formatter/formatter
type/function
value/function/function
declaration/function/function_declaration
shared/gaussian_noise
declaration/generic/generic_type_parameter
constant/global_constant_table
bytecode/goto_info
grammar/grammar
hetu/hetu
binding/hetu_binding
hetu_script
Hetu Script A lightweight scripting language for embedding in Flutter apps.
value/instance/instance
binding/instance_binding
value/instance/instance_namespace
interpreter/interpreter
shared/jsonify
lexer/lexer
lexer/lexicon
lexer/lexicon_default_impl
source/line_info
type/literal
locale/locale
shared/math
value/struct/named_struct
value/namespace/namespace
type/nominal
resource/overlay/overlay_context
resource/overlay/overlay_manager
value/function/parameter
declaration/function/parameter_declaration
parser
parser/parser
parser/parser_default_impl
preincludes/preinclude_functions
preincludes/preinclude_module
ast/visitor/recursive_ast_visitor
resource/resource
resource/resource_context
resource/resource_manager
source/source
source/source_range
value/struct/struct
type/structural
parser/token
parser/token_reader
type/type
declaration/type/type_alias_declaration
analyzer/type_checker
types
shared/uid
type/union
type/unresolved
value/unresolved_import_statement
util
shared/util
values
value/variable/variable
declaration/variable/variable_declaration
version