39 lines
823 B
Dart
39 lines
823 B
Dart
import 'dart:ffi';
|
|
import 'dart:io';
|
|
|
|
abstract class Lib {
|
|
static DynamicLibrary? _daliLib;
|
|
static String? _base;
|
|
|
|
static DynamicLibrary _loadDaliLib(String base) {
|
|
if (Platform.isIOS || Platform.isMacOS) {
|
|
return DynamicLibrary.executable();
|
|
} else if (Platform.isWindows) {
|
|
return DynamicLibrary.open('$base.dll');
|
|
} else {
|
|
return DynamicLibrary.open('$base.so');
|
|
}
|
|
}
|
|
|
|
static DynamicLibrary init(String base) {
|
|
_base = base;
|
|
_daliLib = _loadDaliLib(base);
|
|
|
|
return _daliLib!;
|
|
}
|
|
|
|
static DynamicLibrary get shared {
|
|
if (_daliLib == null) {
|
|
throw Exception('Library not initialized !');
|
|
}
|
|
return _daliLib!;
|
|
}
|
|
|
|
static String get base {
|
|
if (_base == null) {
|
|
throw Exception('Library not initialized !');
|
|
}
|
|
return _base!;
|
|
}
|
|
}
|