Skip to content

Commit

Permalink
changed package folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
hythl0day committed Apr 1, 2021
1 parent ff3b23f commit 5820987
Show file tree
Hide file tree
Showing 962 changed files with 698 additions and 584 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml
# include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
Expand Down
42 changes: 19 additions & 23 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hetu_script/hetu_script.dart';
import 'package:script_widget/script_widget.dart';

Expand Down Expand Up @@ -34,7 +33,7 @@ class MyHomePage extends StatefulWidget {
late final Hetu interpreter;

MyHomePage({Key? key, required this.title}) : super(key: key) {
interpreter = Hetu(moduleHandler: ScriptImportHandler());
interpreter = Hetu(moduleHandler: ScriptModuleHandler());
}

// This widget is the home page of your application. It is stateful, meaning
Expand All @@ -57,10 +56,11 @@ class _MyHomePageState extends State<MyHomePage> {
bool loading = true;

void load() async {
var binding = ManualBinding();
var binding = ManualBinding(widget.interpreter);
await widget.interpreter.init();
binding.loadExternalClasses(widget.interpreter);
await binding.importScripts(widget.interpreter, 'ht-lib');
binding.loadExternalFunctionTypes();
binding.loadExternalClasses();
await binding.importScripts();
setState(() {
loading = false;
});
Expand Down Expand Up @@ -90,24 +90,12 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

class ScriptImportHandler extends HTModuleHandler {
final Set<String> _cachedKeys = {};
class ManualBinding extends DefaultBindingHander {
ManualBinding(Hetu interpreter) : super(interpreter);

@override
Future<HTModuleInfo> import(String key, [String? curFile]) async {
if (!_cachedKeys.contains(key)) {
var content = await rootBundle.loadString(key);
_cachedKeys.add(key);
return HTModuleInfo(key, content);
}
return HTModuleInfo(key, '', duplicate: true);
}
}

class ManualBinding extends Binding {
@override
void loadExternalFunctionTypes(Hetu interpreter) {
super.loadExternalFunctionTypes(interpreter);
void loadExternalFunctionTypes() {
super.loadExternalFunctionTypes();

final functionWrappers = <String, HTExternalFunctionTypedef>{
'ValueChangedInt': (HTFunction function) => (int data) => function.call(positionalArgs: [data]),
Expand All @@ -125,8 +113,16 @@ class ManualBinding extends Binding {
}

@override
void loadExternalClasses(Hetu interpreter) {
super.loadExternalClasses(interpreter);
void loadExternalClasses() {
super.loadExternalClasses();
interpreter.bindExternalFunction('_rebuild', ScriptWidget.rebuild);
}

@override
Future importScripts() {
var future = super.importScripts();
var futures = <Future>[];
futures.add(future);
return Future.wait(futures);
}
}
24 changes: 0 additions & 24 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,6 @@ flutter:
# the material Icons class.
uses-material-design: true

assets:
- assets/
- ht-lib/dart/
- ht-lib/dart/async/
- ht-lib/dart/convert/
- ht-lib/dart/core/
- ht-lib/dart/io/
- ht-lib/dart/ui/
- ht-lib/dart/math/
- ht-lib/flutter/
- ht-lib/flutter/animation/
- ht-lib/flutter/cupertino/
- ht-lib/flutter/foundation/
- ht-lib/flutter/gestures/
- ht-lib/flutter/material/
- ht-lib/flutter/painting/
- ht-lib/flutter/physics/
- ht-lib/flutter/rendering/
- ht-lib/flutter/scheduler/
- ht-lib/flutter/semantics/
- ht-lib/flutter/services/
- ht-lib/flutter/widgets/
- ht-lib/user/

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5820987

Please sign in to comment.