Skip to content

Export Functions

s edited this page Aug 1, 2026 · 3 revisions

Export Functions

The generator finds marked Kotlin/Java methods or C++ functions and creates the bridge and TypeScript declaration for each export.

By default, JavaScript uses the source function name. Override it when needed:

@SupernoteExport(name = "greet")
fun makeGreeting(name: String): String = "Hello, $name"
// @SupernoteExport(name = "greet")
std::string makeGreeting(std::string name) {
  return "Hello, " + name;
}

Export names must be unique and JavaScript-safe.

Kotlin and Java

Use the annotation generated for the module:

import com.example.math.nativemodule.annotation.SupernoteExport

class Example {
  @SupernoteExport
  fun add(left: Double, right: Double): Double = left + right
}

Supported

  • public instance methods on concrete public classes;
  • public constructors taking ReactApplicationContext, Android Context, or no arguments;
  • unique export names;
  • the supported types in the table below.

Not supported

  • suspend, inline, operator, or static methods;
  • generics, extension methods, or varargs;
  • nullable values, collections, arrays, callbacks, and arbitrary objects;
  • unsupported constructors or value types.
Kotlin/Java type TypeScript Call behavior
Boolean / boolean boolean Promise when returned
Double / double number Promise when returned
String string Promise when returned
Unit / void return void Call without await

C and C++

Place the marker immediately before a top-level definition:

// @SupernoteExport
double add(double left, double right) {
  return left + right;
}

Supported

  • top-level definitions in .cc, .cpp, or .cxx;
  • bool, double, and UTF-8 std::string by value;
  • void returns and noexcept;
  • explicitly named parameters;
  • an optional export-name override.

Not supported

  • overloads, namespaces, or templates;
  • pointers or references;
  • variadic or default arguments;
  • static, inline, constexpr, or extern "C" exports;
  • decorated signatures or export markers in .c files.

C files compile as C23 and may provide helpers. C++ and generated bindings compile as C++23. Generated JNI code transports strings as UTF-8 byte arrays, not JNI modified UTF-8.

JavaScript call model

Backend Returned value Example
Native Promise const total = await Math.add(20, 22);
JNI Promise const total = await MathJni.add(20, 22);
JSI Synchronous const total = MathJsi.add(20, 22);

For editable and replaceable files, see Files the Generator Creates.

Clone this wiki locally