AgentSkillsCN

native-integration

本技能重点涵盖 C++ 编程、FFI(外部函数接口)、ANI(Ark 原生接口)、ICU4C 国际化集成,以及 ETS stdlib 的原生方法实现。适用于以下场景:(1) 实现原生方法;(2) 与 C++ 代码进行集成;(3) 使用 ICU 实现国际化;(4) 处理原生与 ETS 之间的边界;(5) 调试原生崩溃问题;或 (6) 优化原生代码。

SKILL.md
--- frontmatter
name: native-integration
description: Essential skill covering C++ programming, FFI (Foreign Function Interface), ANI (Ark Native Interface), ICU4C integration for internationalization, and native method implementation for ETS stdlib. Use this skill when: (1) Implementing native methods, (2) Integrating with C++ code, (3) Using ICU for i18n, (4) Handling native/ETS boundary, (5) Debugging native crashes, or (6) Optimizing native code.

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