hetu_script 0.3.2 copy "hetu_script: ^0.3.2" to clipboard
hetu_script: ^0.3.2 copied to clipboard

outdated

Hetu is a lightweight script language for embedding in Flutter apps.

hetu script

Hetu Script

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

Warning #

Hetu is early WIP! We are focusing on making Hetu stable and feature complete right now.

Introduction #

Hetu is a lightweight script language purely written in Dart for embedding in Flutter apps. The main goal is to enable Flutter apps to have hotfix and scripting ability.

We did not choose to use another existing language to achieve the goal. Because we want to keep it away from interference of other language's complex implementation and their irrelative-to-Flutter eco-system. This will keep this language simple and focus on what we actually need.

Documentation #

English #

Quick start #

Below is an example to eval a string literal of Hetu code in Dart.

import 'package:hetu_script/hetu_script.dart';

void main() {
  var hetu = Hetu();
  hetu.init();
  hetu.eval(r'''
    fun main {
      var ht = {
        name: 'Hetu',
        greeting: () {
          print('Hi! I\'m', this.name)
        }
      }
      ht.greeting()
    }
  ''', invokeFunc: 'main');
}

Hetu's grammar is close to typescript/kotlin/swift and other modern languages.

  • Semicolon is optional.
  • Function starts with a keyword like 'fun, get, set, construct'.
  • Support both class based OOP and prototype based OOP, and also functional programming. You can choose whatever style you want.
  • Type annotation is optional. Variable declared will infer its type from its initializer expression. (The static analysis is still WIP.)

Binding #

Communicating with Dart is very easy. You can directly pass common value types from and to script.

Below is an example to pass a Map to script, modify it in script and get it back:

import 'package:hetu_script/hetu_script.dart';

void main() {
  var hetu = Hetu();
  hetu.init(externalFunctions: {
    'hello': () => {'greeting': 'hello'},
  });
  hetu.eval(r'''
      external fun hello
      fun main {
        var dartValue = hello()
        print('dart value:', dartValue)
        dartValue['foo'] = 'bar'
        return dartValue
      }''');

  var hetuValue = hetu.invoke('main');

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

VScode extension #

If you are using VSCode as your editor, you can download this extension to get basic highlight and snippets features.

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
// or you can use a git url or local path:
// dart pub global activate --source path G:\_dev\hetu-script\packages\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
>>>a
42
>>>fun hello {\
return a }
>>>hello
function hello() -> any // repl print
>>>hello()
42 // repl print
>>>

If there's any problems, you can check this official document about pub global activate.

Discussion group #

Discord: https://discord.gg/sTF73qcS

中文交流请加 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

43
likes
0
pub points
69%
popularity

Publisher

verified publisherhetu.dev

Hetu is a lightweight script language for embedding in Flutter apps.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, path, pub_semver, quiver, recase

More

Packages that depend on hetu_script