adding packages
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
abstract class WasmImpl {
|
||||
WasmImpl.fromAssets(String path);
|
||||
Future<bool> init();
|
||||
bool get isReady;
|
||||
Future function(String name);
|
||||
Future functionParam(String name, dynamic input);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'impl.dart';
|
||||
|
||||
class WasmLoader extends WasmImpl {
|
||||
@override
|
||||
Future function(String name) {
|
||||
// TODO: implement function
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future functionParam(String name, input) {
|
||||
// TODO: implement functionParam
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
// TODO: implement isReady
|
||||
bool get isReady => throw UnimplementedError();
|
||||
|
||||
WasmLoader.fromAssets(String path) : super.fromAssets(path);
|
||||
|
||||
@override
|
||||
Future<bool> init() {
|
||||
// TODO: implement init
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'impl.dart';
|
||||
|
||||
class WasmLoader extends WasmImpl {
|
||||
@override
|
||||
Future function(String name) {
|
||||
// TODO: implement function
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future functionParam(String name, input) {
|
||||
// TODO: implement functionParam
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
// TODO: implement isReady
|
||||
bool get isReady => throw UnimplementedError();
|
||||
|
||||
WasmLoader.fromAssets(String path) : super.fromAssets(path);
|
||||
|
||||
@override
|
||||
Future<bool> init() {
|
||||
// TODO: implement init
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Import dart:ffi.
|
||||
import 'dart:async';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wasm_interop/wasm_interop.dart';
|
||||
|
||||
import 'impl.dart';
|
||||
|
||||
class WasmLoader extends WasmImpl {
|
||||
Instance _wasm;
|
||||
String _path;
|
||||
|
||||
WasmLoader.fromAssets(String path)
|
||||
: _path = path,
|
||||
super.fromAssets(path);
|
||||
|
||||
@override
|
||||
Future function(String name) {
|
||||
final _func = _wasm.functions[name];
|
||||
final _result = _func.call();
|
||||
return _result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future functionParam(String name, input) {
|
||||
final _func = _wasm.functions[name];
|
||||
final _result = _func.call(input);
|
||||
return _result;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isReady => _wasm != null;
|
||||
|
||||
@override
|
||||
Future<bool> init() async {
|
||||
assert(_path != null);
|
||||
final _data = await rootBundle.load(_path);
|
||||
_wasm = await Instance.fromBufferAsync(_data.buffer);
|
||||
return isReady;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user