{"id":21503388,"url":"https://github.com/hetu-script/hetu-script-autobinding","last_synced_at":"2025-07-15T23:31:27.553Z","repository":{"id":45256709,"uuid":"348575284","full_name":"hetu-script/hetu-script-autobinding","owner":"hetu-script","description":"Auto binding codes generator for Hetu script language. Generate from Flutter/Dart library, your codes, or any packages and use them in the scripts. ","archived":false,"fork":false,"pushed_at":"2022-09-14T10:39:39.000Z","size":4112,"stargazers_count":5,"open_issues_count":4,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2023-03-20T21:31:21.408Z","etag":null,"topics":["autobinding","dart","hetu","script","tool"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hetu-script.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-17T04:06:31.000Z","updated_at":"2022-06-21T09:03:18.000Z","dependencies_parsed_at":"2023-01-18T07:15:23.687Z","dependency_job_id":null,"html_url":"https://github.com/hetu-script/hetu-script-autobinding","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetu-script%2Fhetu-script-autobinding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetu-script%2Fhetu-script-autobinding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetu-script%2Fhetu-script-autobinding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetu-script%2Fhetu-script-autobinding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hetu-script","download_url":"https://codeload.github.com/hetu-script/hetu-script-autobinding/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226079668,"owners_count":17570501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autobinding","dart","hetu","script","tool"],"created_at":"2024-11-23T18:22:02.074Z","updated_at":"2024-11-23T18:22:02.997Z","avatar_url":"https://github.com/hetu-script.png","language":"Dart","readme":"# Autobinding Codes Generator for Hetu Script Language\n\n## Introduction\n\nA Dart binding code generator for [Hetu script language](https://github.com/hythl0day/hetu_script). \nYou can generate glue codes from Flutter/Dart library, your codes, or any packages. \nThen you can use them in the Hetu script:\n\n\nThe classes and enums that need to be used in the scripts:\n```dart\n@HTBinding()\nenum Ingredients {\n   Apple,\n   Banana,\n   Cinnamon,\n}\n\n@HTBinding()\nclass RootAssetBundle extends services.AssetBundle{\n   @override\n   Future\u003cservices.ByteData\u003e load(String key) {\n      return services.rootBundle.load(key);\n   }\n\n   @override\n   Future\u003cString\u003e loadString(String key, {bool cache = true}) {\n      return services.rootBundle.loadString(key, cache: cache);\n   }\n\n   @override\n   Future\u003cT\u003e loadStructuredData\u003cT\u003e(String key, Future\u003cT\u003e Function(String value) parser) {\n      return services.rootBundle.loadStructuredData(key, parser);\n   }\n}\n\n@HTBinding()\nclass ScriptHelper {\n   ScriptHelper._();\n\n   static void futureHandler(HT_Function callback, Future future) {\n      future.then((value) {\n         try {\n            callback.call(positionalArgs: [value]);\n         }\n         catch(err, stack) {\n            print('$err\\n$stack');\n         }\n      });\n   }\n}\n```\n\nThe binding codes are generated by this tool:\n```dart\nclass IngredientsClassBinding extends HT_ExternNamespace {\n   @override\n   dynamic fetch(String id) {\n      switch (id) {\n         case 'Apple':\n            return Ingredients.Apple;\n         case 'Banana':\n            return Ingredients.Banana;\n         case 'Cinnamon':\n            return Ingredients.Cinnamon;\n         default:\n            throw HTErr_Undefined(id);\n      }\n   }\n}\n\nclass RootAssetBundleClassBinding extends HT_ExternNamespace {\n   @override\n   dynamic fetch(String id) {\n      switch (id) {\n         case 'RootAssetBundle':\n            return () =\u003e RootAssetBundleObjectBinding(RootAssetBundle());\n         default:\n            throw HTErr_Undefined(id);\n      }\n   }\n}\n\nclass RootAssetBundleObjectBinding extends HT_ExternObject\u003cRootAssetBundle\u003e {\n   RootAssetBundleObjectBinding(RootAssetBundle value) : super(value);\n\n   @override\n   final typeid = HT_TypeId('RootAssetBundle');\n\n   @override\n   dynamic fetch(String id) {\n      switch (id) {\n         case 'load':\n            return externObject.load;\n         case 'loadString':\n            return externObject.loadString;\n         case 'loadStructuredData':\n            return externObject.loadStructuredData;\n         default:\n            throw HTErr_Undefined(id);\n      }\n   }\n\n}\n\nclass ScriptHelperClassBinding extends HT_ExternNamespace {\n   @override\n   dynamic fetch(String id) {\n      switch (id) {\n         case 'futureHandler':\n            return (callback, future) =\u003e ScriptHelper.futureHandler(callback, future);\n         default:\n            throw HTErr_Undefined(id);\n      }\n   }\n}\n```\nAnd scripts are generated too:\n```\nexternal class Ingredients {\n    static var Apple\n    static var Banana\n    static var Cinnamon\n}\nexternal class RootAssetBundle {\n    construct\n    fun load\n    fun loadString\n    fun loadStructuredData\n}\nexternal class ScriptHelper {\n    static fun futureHandler (callback, future)\n}\n```\nThen you can use the dart class from the script:\n```\nfun handleString(string) {\n  print(string)\n}\n\nfun main() {\n   print(Ingredients.Banana)\n   var r = RootAssetBundle()   \n   var strFuture = r.loadString('assets/data/test.txt')   \n   ScriptHelper.futureHandler(handleString, strFuture)\n}\n```\n\n## Build\n\nYou can build the executable file by the script: ```build.sh```\n\n## Generate the binding codes\n1. Flutter/Dart Framework (-f)\n   \n   *Should only point to the root of the Flutter repository folder (containing 'packages' folder)*\n   \n2. Third-party packages  (-p)\n   \n   *Could point to any packages' lib folder or the root of the repository folder.*\n   \n   *You can find the packages from ~/.pub-cache/hosted/pub.dartlang.org/ or from a repository folder.*\n   \n3. Your own codes  (-u)\n\n   *Point to the folder that containing your codes. You should also add a ```@HTBinding()``` annotation to your custom class/enum for binding:*\n```dart\n@HTBinding()\nclass CustomClass {\n  var m;\n}\n\n@HTBinding()\nenum CustomEnum { \n  a,\n  b,\n}\n\n```\nMore options could be found by flagging ```-h```:\n```shell\n./bin/ht-binding-generator -h\n\n-u, --user-lib-paths=\u003cpath1, path2, ...\u003e                                        \n  Will iterate over all the folders recursively.\n\n-p, --package-lib-paths=\u003cpackage1/lib, package2/lib, ...\u003e                       \n  Will iterate over all the package cache folders.\n\n-f, --flutter-lib-path=\u003cflutter-framework-path\u003e                                 \n  Will iterate the Flutter/Dart framework recursively. The path should point to the Flutter root folder.\n\n-o, --output                                                                    \n  The output path for .dart code generation and .json intermediate files.\n  \n-s, --script-output                                                             \n  The output path for .ht code generation.\n                                                                           \n-j, --[no-]json-export                                                          \n  Whether to export the intermediate JSON files for diagnostics.\n\n-h, --[no-]help       \n                                                        \n-i, --ignores=\u003cignored-file-name, ignored-file-name:ignored-class-name, ...\u003e    \n  The files/classes from this list will be ignored during the code generation.\n  \n-w, --whitelist=\u003cwhitelist-file-name, whitelist-file-name2, ...\u003e                \n  Only the files from the list will be parsed, working with 'ignores' too.\n```\n\n## Initialize the binding\n\ncall ```loadAutoBinding``` and ```loadAutoBindingScripts``` on a ```HetuScriptBinding()``` will initialize all definitions for Hetu script usage.\n \n\n```dart\n  void initBinding() async {\n    var hetu = HTAstInterpreter(readFileMethod: (path) {\n      return rootBundle.loadString(path);\n    });\n    var binding = HetuScriptBinding();\n    binding.loadAutoBinding(hetu);\n    binding.loadAutoBindingScripts(hetu, 'assets/path').then((value) {\n      print('initialization done.');\n    });\n  }\n```\n\n## Manual binding\n\nYou can also add manual-binding codes by subclassing ```HetuScriptBinding```class, and use ```ManualBinding``` instead of ```HetuScriptBinding```.\n\nThe auto-binding codes will be loaded by calling the ```super```. \n\n```dart\n\nclass ManualBinding extends HetuScriptBinding {\n  @override\n  void loadAutoBinding(HTAstInterpreter interpreter) {\n    super.loadAutoBinding(interpreter);\n    var bindings = {\n      'RootAssetBundle' : RootAssetBundleClassBinding(),\n      'ScriptHelper' : ScriptHelperClassBinding(),\n      'ExternalAssetBundle' : ExternalAssetBundleClassBinding(),\n    };\n    bindings.forEach((key, value) {\n      interpreter.bindExternalNamespace(key, value);\n    });\n  }\n\n  @override\n  Future loadAutoBindingScripts(HTAstInterpreter interpreter, String path) {\n    var future = super.loadAutoBindingScripts(interpreter, path);\n    var futures = \u003cFuture\u003e[];\n    futures.add(future);\n    futures.add(interpreter.evalf('$path/user/root_asset_bundle.ht'));\n    futures.add(interpreter.evalf('$path/user/external_asset_bundle.ht'));\n    return Future.wait(futures);\n  }\n}\n```\n \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhetu-script%2Fhetu-script-autobinding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhetu-script%2Fhetu-script-autobinding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhetu-script%2Fhetu-script-autobinding/lists"}