Skip to content

Commit

Permalink
optimize api naming
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamcmi committed Oct 14, 2024
1 parent 0f65e53 commit e9c4b4a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
58 changes: 45 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,53 @@ cjpm build
./target/release/bin/main
```

### ruapu with Dart

<table>

<tr><td>

Compile ruapu library

```bash
cd dart
bash build.sh
```


</td>
<td>
Use ruapu in cangjie

```swift
import ruapu.*
main(): Int64 {
ruapu_init()
let neon_supported = ruapu_supports("neon")
println("supports neon: ${neon_supported}")
let d = ruapu_rua()
for (i in d) {
println(i)
}
return 0
Use ruapu in dart

```dart
void main() {
var libraryPath =
path.join(Directory.current.path, 'build', 'libruapu.so');
if (Platform.isMacOS) {
libraryPath =
path.join(Directory.current.path, 'build', 'libruapu.dylib');
}
if (Platform.isWindows) {
libraryPath = path.join(
Directory.current.path, 'build', 'Debug', 'ruapu.dll');
}
Ruapu ruapu = Ruapu(libraryPath);
ruapu.init();
List<String> isas = ruapu.rua();
print("This CPU Support:");
for (String isa in isas) {
print(isa);
}
print("=================");
String isaToCheck = 'aes';
bool isSupported = ruapu.supports(isaToCheck);
print('Does the system support $isaToCheck? $isSupported');
}
```
</td></tr>
Expand Down
8 changes: 4 additions & 4 deletions dart/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ void main() {
Directory.current.path, 'build', 'Debug', 'ruapu.dll');
}

Ruapu api = Ruapu(libraryPath);
Ruapu ruapu = Ruapu(libraryPath);

api.init();
ruapu.init();

List<String> isas = api.getRuapuISA();
List<String> isas = ruapu.rua();
print("This CPU Support:");
for (String isa in isas) {
print(isa);
}
print("=================");

String isaToCheck = 'aes';
bool isSupported = api.supportsISA(isaToCheck);
bool isSupported = ruapu.supports(isaToCheck);
print('Does the system support $isaToCheck? $isSupported');
}
4 changes: 2 additions & 2 deletions dart/ruapu_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Ruapu {
}

/// Get the ISA support list of the CPU
List<String> getRuapuISA() {
List<String> rua() {
final RuapuRUA_Dart ruapu_rua = _nativeLib
.lookup<NativeFunction<RuapuRUA_C>>('ruapu_rua')
.asFunction();
Expand All @@ -46,7 +46,7 @@ class Ruapu {
}

/// Check the support status of a given isa
bool supportsISA(String isa) {
bool supports(String isa) {
final Pointer<Utf8> cIsa = isa.toNativeUtf8();

final RuapuSupports_Dart ruapu_supports = _nativeLib
Expand Down

0 comments on commit e9c4b4a

Please sign in to comment.