Native Integration
Quick Start
Native method declaration:
typescript
// ETS side
export class Math {
public native static sqrt(x: double): double;
}
C++ implementation:
cpp
// C++ side
double Math_sqrt(double x) {
return std::sqrt(x);
}
Type conversions:
cpp
// ETS string to C++ std::string str = etsToCppString(etsStr); // C++ to ETS string EtsString* etsStr = cppToEtsString(str);
Key Concepts
ANI (Ark Native Interface):
- •StringHelper for string conversions
- •ArrayHelper for array conversions
- •ExceptionHelper for error handling
ICU Integration:
- •Locale handling
- •Number/date formatting
- •Collation
Script Utilities
- •check_native_integration.sh - Validate native methods