hetu_script 0.3.1 copy "hetu_script: ^0.3.1" to clipboard
hetu_script: ^0.3.1 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 the language simple, and keep it away from interference of other language's complex implementation and their irrelative-to-Flutter eco-system, and make the debug process pain-free and remain in Dart realms.

It takes very little time to bind almost anything in Dart/Flutter into Hetu, makes communicating with your existing Dart code very easy.

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, need very little time to get familar with.

  • Optional semicolon.
  • Function is declared with 'fun, get, set, construct'.
  • Optional type annotation. Variable declared will infer its type from its initializer expression.
  • Support for traditional class style OOP and javascript-like prototyped based OOP, and also functional programming as function is a first class value. You can choose whatever style you want.

Syntax referrence

Binding #

Hetu script is purely written in Dart, so passing object to and from script is extremely easy.

Check this page for more information about how to bind external classes, functions, enums and how to passing object and functions between Dart and script.

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');
}

Discussion group #

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