Skip to content
Lucent
SEARCH LUCENT

Search guides, APIs, and examples.

GitHub

Very early and experimental. The language, the generated native code and every package API change without notice. Do not use Lucent in production.

Types across the boundary

How each type crosses between JavaScript and Lucent: its C++ form, copy or reference, and what JavaScript must pass.

TypeScriptC++Crosses asJavaScript must pass
numberdoublea copya number
bigintlucent::BigInta copy, exacta bigint
booleanboola copya boolean
string, string literal typeslucent::String, UTF-16a copya string; any string, for literal types
T | null, T | undefined, x?: Tlucent::Opt<T>the value, or its absencenull or undefined for absent: both, whatever the type declares
T[]lucent::Array<T>a copyan array; each element is checked
[A, B]std::tuple<A, B>a copyan array
object types, interfaces without methodsa struct, by shapea copyan object with each declared field; extra fields are ignored
Record<string, V>lucent::Dict<V>a copyan object; each value is checked
Map<K, V>, Set<T>lucent::Map, lucent::Seta copya Map or a Set
Uint8Arraylucent::Bytesa copya Uint8Array or an ArrayBuffer
Datelucent::Datea copy of its timean object with getTime()
RegExplucent::RegExpits source and flagsa RegExp; lastIndex isn't kept
enumsdouble or lucent::Stringa copya number or a string; membership isn't checked
unionsstd::variantthe member JavaScript's value matchesa value of one member; object members need a string-literal discriminant (LUCENT2005)
classesa reference-counted objecta reference, with its identityan instance of that Lucent class
interfaces a class implementsthe class's objecta referencean instance of a Lucent class that implements it
functionslucent::Fna callbacka function
Promise<T>lucent::Promise<T>a promisea promise or any value, as await takes
AbortSignallucent::AbortSignalinto Lucent onlyan AbortSignal
Error, TypeError, RangeErrorlucent::Errorits name, message and codeany value
Iterable<T> (parameters only)lucent::Iter<T>a snapshot, as Array.from takesan iterable
voidvoidundefined

The call throws a TypeError before your code runs, even for an async export. The message names the function, the argument and the path to the bad value:

terminal
TypeError: hash: argument 'input' must be a string, got a number
TypeError: midpoint: argument 'a'.y must be a number, got undefined
ValueCode
SDK objects, such as a CLLocationManagerLUCENT2006
iterators and generators, returnedLUCENT2006
an AbortSignal going out, and AbortController either wayLUCENT2006
generic functions, classes and valuesLUCENT2007
unions whose members JavaScript can't tell apartLUCENT2005
  • The same native object is the same JS object each time, so === works. It lives while either side holds it.
  • JavaScript can call new on an exported class. The constructor's arguments are checked like a function's.
  • Public fields, getters, setters and methods are on the prototype. Each read of an array or object field returns a fresh copy.
  • Static methods are on the constructor. Static fields aren't visible from JavaScript.
  • private, protected and #private members are hidden.
  • Called during a synchronous call from JavaScript, a callback runs at once and may return any value that can cross.
  • Called from async code, it is posted to the JS thread. It must return void, or a Promise that Lucent can await.
  • A JavaScript error thrown in a callback becomes a Lucent error that catch can handle.
  • The function is released when the last Lucent reference to it goes.