Extern Declarations
The extern keyword declares functions that are defined outside Rux — typically in C / C++ libraries.
extern func malloc(size: uint) -> *opaque;
extern func free(ptr: *opaque);
Multiple declarations from the same library can be grouped in one extern block.
extern {
func malloc(size: uint) -> *opaque;
func realloc(ptr: *opaque, size: uint) -> *opaque;
func free(ptr: *opaque);
}
Foreign functions exchange data through pointers: *opaque for handles, *T for read-only buffers, and *var T for buffers the callee may write to.
See Also
- Linking Libraries — binding an
externdeclaration to a library with#Link - Pointers and
extern— the pointer types crossing the boundary - Pointer Types —
*opaque,*T, and*var T
Overview
The foreign function interface (FFI) lets Rux call functions defined outside the language — typically in C / C++ libraries — and exchange data with them. Each part of the FFI has a dedicated chapter:
Linking Libraries
The #Link attribute binds an extern declaration to a native library (.dll, .so, .dylib). The operating-system loader resolves the library by name at run time.